7
7
8
8
namespace Magento \Catalog \Test \Unit \Ui \Component ;
9
9
10
- use PHPUnit \Framework \TestCase ;
11
- use Magento \Catalog \Ui \Component \FilterFactory ;
12
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
13
- use Magento \Framework \View \Element \UiComponentFactory ;
14
10
use Magento \Catalog \Api \Data \ProductAttributeInterface ;
11
+ use Magento \Catalog \Ui \Component \FilterFactory ;
15
12
use Magento \Eav \Model \Entity \Attribute \Source \SourceInterface ;
13
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
16
14
use Magento \Framework \View \Element \UiComponent \ContextInterface ;
15
+ use Magento \Framework \View \Element \UiComponentFactory ;
16
+ use PHPUnit \Framework \MockObject \MockObject ;
17
+ use PHPUnit \Framework \TestCase ;
17
18
18
19
class FilterFactoryTest extends TestCase
19
20
{
21
+ /**
22
+ * Stub attribute
23
+ */
24
+ private const STUB_ATTRIBUTE = [
25
+ 'attribute_code ' => 'color ' ,
26
+ 'default_frontend_label ' => 'Color ' ,
27
+ 'uses_source ' => 'Color ' ,
28
+ 'source_model ' => 'getSourceModel value ' ,
29
+ 'frontend_input ' => 'select ' ,
30
+ 'all_options ' => [
31
+ [
32
+ 'value ' => 1 ,
33
+ 'label ' => 'Black ' ,
34
+ ],
35
+ [
36
+ 'value ' => 2 ,
37
+ 'label ' => 'White ' ,
38
+ ]
39
+ ]
40
+ ];
41
+
20
42
/**
21
43
* @var FilterFactory
22
44
*/
23
45
private $ filterFactory ;
24
46
25
47
/**
26
- * @var UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject
48
+ * @var UiComponentFactory|MockObject
27
49
*/
28
50
private $ componentFactoryMock ;
29
51
@@ -32,7 +54,7 @@ class FilterFactoryTest extends TestCase
32
54
*/
33
55
protected function setUp ()
34
56
{
35
- $ objectManager = new ObjectManagerHelper ($ this );
57
+ $ objectManager = new ObjectManager ($ this );
36
58
37
59
$ this ->componentFactoryMock = $ this ->createMock (UiComponentFactory::class);
38
60
@@ -53,43 +75,24 @@ public function testCreateWithUseSourceAttribute()
53
75
$ attributeMock = $ this ->getMockBuilder (ProductAttributeInterface::class)
54
76
->setMethods (['usesSource ' , 'getSource ' ])
55
77
->getMockForAbstractClass ();
56
- $ attributeMock ->method ('getAttributeCode ' )->willReturn ('color ' );
57
- $ attributeMock ->method ('getDefaultFrontendLabel ' )->willReturn ('Color ' );
58
- $ attributeMock ->method ('usesSource ' )->willReturn (true );
59
- $ attributeMock ->method ('getSourceModel ' )->willReturn ('getSourceModel value ' );
60
- $ attributeMock ->method ('getFrontendInput ' )->willReturn ('select ' );
78
+ $ attributeMock ->method ('getAttributeCode ' )->willReturn (self ::STUB_ATTRIBUTE ['attribute_code ' ]);
79
+ $ attributeMock ->method ('getDefaultFrontendLabel ' )
80
+ ->willReturn (self ::STUB_ATTRIBUTE ['default_frontend_label ' ]);
81
+ $ attributeMock ->method ('usesSource ' )->willReturn (self ::STUB_ATTRIBUTE ['uses_source ' ]);
82
+ $ attributeMock ->method ('getSourceModel ' )->willReturn (self ::STUB_ATTRIBUTE ['source_model ' ]);
83
+ $ attributeMock ->method ('getFrontendInput ' )->willReturn (self ::STUB_ATTRIBUTE ['frontend_input ' ]);
61
84
$ sourceMock = $ this ->createMock (SourceInterface::class);
62
85
$ attributeMock ->method ('getSource ' )->willReturn ($ sourceMock );
63
- $ sourceMock ->method ('getAllOptions ' )->willReturn (
64
- [
65
- [
66
- 'value ' => 1 ,
67
- 'label ' => 'Black ' ,
68
- ],
69
- [
70
- 'value ' => 2 ,
71
- 'label ' => 'White ' ,
72
- ]
73
- ]
74
- );
86
+ $ sourceMock ->method ('getAllOptions ' )->willReturn (self ::STUB_ATTRIBUTE ['all_options ' ]);
75
87
$ this ->componentFactoryMock ->expects ($ this ->once ())
76
88
->method ('create ' )
77
89
->with ('color ' , 'filterSelect ' , [
78
90
'data ' => [
79
91
'config ' => [
80
- 'options ' => [
81
- [
82
- 'value ' => 1 ,
83
- 'label ' => 'Black ' ,
84
- ],
85
- [
86
- 'value ' => 2 ,
87
- 'label ' => 'White ' ,
88
- ]
89
- ],
92
+ 'options ' => self ::STUB_ATTRIBUTE ['all_options ' ],
90
93
'caption ' => (string )__ ('Select... ' ),
91
- 'dataScope ' => ' color ' ,
92
- 'label ' => (string )__ (' Color ' ),
94
+ 'dataScope ' => self :: STUB_ATTRIBUTE [ ' attribute_code ' ] ,
95
+ 'label ' => (string )__ (self :: STUB_ATTRIBUTE [ ' default_frontend_label ' ] ),
93
96
]
94
97
],
95
98
'context ' => $ contextMock
0 commit comments