Skip to content

Commit

Permalink
ENGCOM-2089: Customer group extension attributes not carried over on …
Browse files Browse the repository at this point in the history
…save #16254
  • Loading branch information
Stanislav Idolov authored Jul 8, 2018
2 parents ee7e32f + 518b71f commit 781c0d8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ public function save(\Magento\Customer\Api\Data\GroupInterface $group)
->setCode($groupModel->getCode())
->setTaxClassId($groupModel->getTaxClassId())
->setTaxClassName($groupModel->getTaxClassName());

if ($group->getExtensionAttributes()) {
$groupDataObject->setExtensionAttributes($group->getExtensionAttributes());
}

return $groupDataObject;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class GroupRepositoryTest extends \PHPUnit\Framework\TestCase
*/
protected $group;

/**
* @var \Magento\Customer\Api\Data\GroupInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $factoryCreatedGroup;

/**
* @var \Magento\Customer\Model\ResourceModel\Group|\PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -153,6 +158,12 @@ private function setupGroupObjects()
'group',
false
);
$this->factoryCreatedGroup = $this->getMockForAbstractClass(
\Magento\Customer\Api\Data\GroupInterface::class,
[],
'group',
false
);

$this->groupResourceModel = $this->createMock(\Magento\Customer\Model\ResourceModel\Group::class);
}
Expand All @@ -162,16 +173,22 @@ public function testSave()
$groupId = 0;

$taxClass = $this->getMockForAbstractClass(\Magento\Tax\Api\Data\TaxClassInterface::class, [], '', false);
$extensionAttributes = $this->getMockForAbstractClass(
\Magento\Customer\Api\Data\GroupExtensionInterface::class
);

$this->group->expects($this->once())
$this->group->expects($this->atLeastOnce())
->method('getCode')
->willReturn('Code');
$this->group->expects($this->atLeastOnce())
->method('getId')
->willReturn($groupId);
$this->group->expects($this->once())
$this->group->expects($this->atLeastOnce())
->method('getTaxClassId')
->willReturn(17);
$this->group->expects($this->atLeastOnce())
->method('getExtensionAttributes')
->willReturn($extensionAttributes);

$this->groupModel->expects($this->atLeastOnce())
->method('getId')
Expand All @@ -185,22 +202,33 @@ public function testSave()
$this->groupModel->expects($this->atLeastOnce())
->method('getTaxClassName')
->willReturn('Tax class name');
$this->group->expects($this->once())

$this->factoryCreatedGroup->expects($this->once())
->method('setId')
->with($groupId)
->willReturnSelf();
$this->group->expects($this->once())
$this->factoryCreatedGroup->expects($this->once())
->method('setCode')
->with('Code')
->willReturnSelf();
$this->group->expects($this->once())
$this->factoryCreatedGroup->expects($this->once())
->method('setTaxClassId')
->with(234)
->willReturnSelf();
$this->group->expects($this->once())
$this->factoryCreatedGroup->expects($this->once())
->method('setTaxClassName')
->with('Tax class name')
->willReturnSelf();
$this->factoryCreatedGroup->expects($this->once())
->method('setExtensionAttributes')
->with($extensionAttributes)
->willReturnSelf();
$this->factoryCreatedGroup->expects($this->atLeastOnce())
->method('getCode')
->willReturn('Code');
$this->factoryCreatedGroup->expects($this->atLeastOnce())
->method('getTaxClassId')
->willReturn(17);

$this->taxClassRepository->expects($this->once())
->method('get')
Expand Down Expand Up @@ -229,9 +257,12 @@ public function testSave()
->with($groupId);
$this->groupDataFactory->expects($this->once())
->method('create')
->willReturn($this->group);
->willReturn($this->factoryCreatedGroup);

$updatedGroup = $this->model->save($this->group);

$this->assertSame($this->group, $this->model->save($this->group));
$this->assertSame($this->group->getCode(), $updatedGroup->getCode());
$this->assertSame($this->group->getTaxClassId(), $updatedGroup->getTaxClassId());
}

/**
Expand Down

0 comments on commit 781c0d8

Please sign in to comment.