Skip to content

Commit 3af121c

Browse files
committed
MC-32996: Product Attribute Option Label update Magento 2.3.4 REST API
1 parent 669f64f commit 3af121c

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/OptionManagementTest.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1111
use Magento\Catalog\Model\Product\Attribute\OptionManagement;
1212
use Magento\Eav\Api\AttributeOptionManagementInterface;
13+
use Magento\Eav\Api\AttributeOptionUpdateInterface;
1314
use Magento\Eav\Api\Data\AttributeOptionInterface;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617

18+
/**
19+
* Class to test management of attribute options
20+
*/
1721
class OptionManagementTest extends TestCase
1822
{
1923
/**
@@ -22,18 +26,28 @@ class OptionManagementTest extends TestCase
2226
protected $model;
2327

2428
/**
25-
* @var MockObject
29+
* @var AttributeOptionManagementInterface|MockObject
2630
*/
2731
protected $eavOptionManagementMock;
2832

33+
/**
34+
* @var AttributeOptionUpdateInterface|MockObject
35+
*/
36+
private $eavOptionUpdateMock;
37+
2938
protected function setUp(): void
3039
{
3140
$this->eavOptionManagementMock = $this->getMockForAbstractClass(AttributeOptionManagementInterface::class);
41+
$this->eavOptionUpdateMock = $this->getMockForAbstractClass(AttributeOptionUpdateInterface::class);
3242
$this->model = new OptionManagement(
33-
$this->eavOptionManagementMock
43+
$this->eavOptionManagementMock,
44+
$this->eavOptionUpdateMock
3445
);
3546
}
3647

48+
/**
49+
* Test to Retrieve list of attribute options
50+
*/
3751
public function testGetItems()
3852
{
3953
$attributeCode = 10;
@@ -44,6 +58,9 @@ public function testGetItems()
4458
$this->assertEquals([], $this->model->getItems($attributeCode));
4559
}
4660

61+
/**
62+
* Test to Add option to attribute
63+
*/
4764
public function testAdd()
4865
{
4966
$attributeCode = 42;
@@ -56,6 +73,9 @@ public function testAdd()
5673
$this->assertTrue($this->model->add($attributeCode, $optionMock));
5774
}
5875

76+
/**
77+
* Test to delete attribute option
78+
*/
5979
public function testDelete()
6080
{
6181
$attributeCode = 'atrCde';
@@ -68,6 +88,9 @@ public function testDelete()
6888
$this->assertTrue($this->model->delete($attributeCode, $optionId));
6989
}
7090

91+
/**
92+
* Test to delete attribute option with invalid option id
93+
*/
7194
public function testDeleteWithInvalidOption()
7295
{
7396
$this->expectException('Magento\Framework\Exception\InputException');
@@ -77,4 +100,24 @@ public function testDeleteWithInvalidOption()
77100
$this->eavOptionManagementMock->expects($this->never())->method('delete');
78101
$this->model->delete($attributeCode, $optionId);
79102
}
103+
104+
/**
105+
* Test to update attribute option
106+
*/
107+
public function testUpdate()
108+
{
109+
$attributeCode = 'atrCde';
110+
$optionId = 10;
111+
$optionMock = $this->getMockForAbstractClass(AttributeOptionInterface::class);
112+
113+
$this->eavOptionUpdateMock->expects($this->once())
114+
->method('update')
115+
->with(
116+
ProductAttributeInterface::ENTITY_TYPE_CODE,
117+
$attributeCode,
118+
$optionId,
119+
$optionMock
120+
)->willReturn(true);
121+
$this->assertTrue($this->model->update($attributeCode, $optionId, $optionMock));
122+
}
80123
}

0 commit comments

Comments
 (0)