10
10
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
11
11
use Magento \Catalog \Model \Product \Attribute \OptionManagement ;
12
12
use Magento \Eav \Api \AttributeOptionManagementInterface ;
13
+ use Magento \Eav \Api \AttributeOptionUpdateInterface ;
13
14
use Magento \Eav \Api \Data \AttributeOptionInterface ;
14
15
use PHPUnit \Framework \MockObject \MockObject ;
15
16
use PHPUnit \Framework \TestCase ;
16
17
18
+ /**
19
+ * Class to test management of attribute options
20
+ */
17
21
class OptionManagementTest extends TestCase
18
22
{
19
23
/**
@@ -22,18 +26,28 @@ class OptionManagementTest extends TestCase
22
26
protected $ model ;
23
27
24
28
/**
25
- * @var MockObject
29
+ * @var AttributeOptionManagementInterface| MockObject
26
30
*/
27
31
protected $ eavOptionManagementMock ;
28
32
33
+ /**
34
+ * @var AttributeOptionUpdateInterface|MockObject
35
+ */
36
+ private $ eavOptionUpdateMock ;
37
+
29
38
protected function setUp (): void
30
39
{
31
40
$ this ->eavOptionManagementMock = $ this ->getMockForAbstractClass (AttributeOptionManagementInterface::class);
41
+ $ this ->eavOptionUpdateMock = $ this ->getMockForAbstractClass (AttributeOptionUpdateInterface::class);
32
42
$ this ->model = new OptionManagement (
33
- $ this ->eavOptionManagementMock
43
+ $ this ->eavOptionManagementMock ,
44
+ $ this ->eavOptionUpdateMock
34
45
);
35
46
}
36
47
48
+ /**
49
+ * Test to Retrieve list of attribute options
50
+ */
37
51
public function testGetItems ()
38
52
{
39
53
$ attributeCode = 10 ;
@@ -44,6 +58,9 @@ public function testGetItems()
44
58
$ this ->assertEquals ([], $ this ->model ->getItems ($ attributeCode ));
45
59
}
46
60
61
+ /**
62
+ * Test to Add option to attribute
63
+ */
47
64
public function testAdd ()
48
65
{
49
66
$ attributeCode = 42 ;
@@ -56,6 +73,9 @@ public function testAdd()
56
73
$ this ->assertTrue ($ this ->model ->add ($ attributeCode , $ optionMock ));
57
74
}
58
75
76
+ /**
77
+ * Test to delete attribute option
78
+ */
59
79
public function testDelete ()
60
80
{
61
81
$ attributeCode = 'atrCde ' ;
@@ -68,6 +88,9 @@ public function testDelete()
68
88
$ this ->assertTrue ($ this ->model ->delete ($ attributeCode , $ optionId ));
69
89
}
70
90
91
+ /**
92
+ * Test to delete attribute option with invalid option id
93
+ */
71
94
public function testDeleteWithInvalidOption ()
72
95
{
73
96
$ this ->expectException ('Magento\Framework\Exception\InputException ' );
@@ -77,4 +100,24 @@ public function testDeleteWithInvalidOption()
77
100
$ this ->eavOptionManagementMock ->expects ($ this ->never ())->method ('delete ' );
78
101
$ this ->model ->delete ($ attributeCode , $ optionId );
79
102
}
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
+ }
80
123
}
0 commit comments