16
16
use Magento \Framework \EntityManager \EntityMetadataInterface ;
17
17
use Magento \Framework \EntityManager \MetadataPool ;
18
18
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
19
+ use Magento \Store \Api \StoreResolverInterface ;
20
+ use Magento \Store \Model \Store ;
19
21
20
22
class StatusBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase
21
23
{
@@ -29,6 +31,11 @@ class StatusBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase
29
31
*/
30
32
private $ metadataPool ;
31
33
34
+ /**
35
+ * @var StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject
36
+ */
37
+ private $ storeResolver ;
38
+
32
39
/**
33
40
* @var Select|\PHPUnit_Framework_MockObject_MockObject
34
41
*/
@@ -43,19 +50,22 @@ protected function setUp()
43
50
{
44
51
$ this ->eavConfig = $ this ->getMockBuilder (Config::class)->disableOriginalConstructor ()->getMock ();
45
52
$ this ->metadataPool = $ this ->getMockBuilder (MetadataPool::class)->disableOriginalConstructor ()->getMock ();
53
+ $ this ->storeResolver = $ this ->getMockBuilder (StoreResolverInterface::class)->getMock ();
46
54
$ this ->select = $ this ->getMockBuilder (Select::class)->disableOriginalConstructor ()->getMock ();
47
55
48
56
$ this ->statusBaseSelectProcessor = (new ObjectManager ($ this ))->getObject (StatusBaseSelectProcessor::class, [
49
57
'eavConfig ' => $ this ->eavConfig ,
50
58
'metadataPool ' => $ this ->metadataPool ,
59
+ 'storeResolver ' => $ this ->storeResolver ,
51
60
]);
52
61
}
53
62
54
63
public function testProcess ()
55
64
{
56
65
$ linkField = 'link_field ' ;
57
66
$ backendTable = 'backend_table ' ;
58
- $ attributeId = 'attribute_id ' ;
67
+ $ attributeId = 2 ;
68
+ $ currentStoreId = 1 ;
59
69
60
70
$ metadata = $ this ->getMock (EntityMetadataInterface::class);
61
71
$ metadata ->expects ($ this ->once ())
@@ -66,35 +76,49 @@ public function testProcess()
66
76
->with (ProductInterface::class)
67
77
->willReturn ($ metadata );
68
78
79
+ /** @var AttributeInterface|\PHPUnit_Framework_MockObject_MockObject $statusAttribute */
69
80
$ statusAttribute = $ this ->getMockBuilder (AttributeInterface::class)
70
81
->setMethods (['getBackendTable ' , 'getAttributeId ' ])
71
82
->getMock ();
72
- $ statusAttribute ->expects ($ this ->once ())
83
+ $ statusAttribute ->expects ($ this ->atLeastOnce ())
73
84
->method ('getBackendTable ' )
74
85
->willReturn ($ backendTable );
75
- $ statusAttribute ->expects ($ this ->once ())
86
+ $ statusAttribute ->expects ($ this ->atLeastOnce ())
76
87
->method ('getAttributeId ' )
77
88
->willReturn ($ attributeId );
78
89
$ this ->eavConfig ->expects ($ this ->once ())
79
90
->method ('getAttribute ' )
80
91
->with (Product::ENTITY , ProductInterface::STATUS )
81
92
->willReturn ($ statusAttribute );
82
93
83
- $ this ->select ->expects ($ this ->once ())
84
- ->method ('join ' )
94
+ $ this ->storeResolver ->expects ($ this ->once ())
95
+ ->method ('getCurrentStoreId ' )
96
+ ->willReturn ($ currentStoreId );
97
+
98
+ $ this ->select ->expects ($ this ->at (0 ))
99
+ ->method ('joinLeft ' )
85
100
->with (
86
- ['status_attr ' => $ backendTable ],
87
- sprintf ('status_attr.%s = %s.%1$s ' , $ linkField , BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS ),
101
+ ['status_global_attr ' => $ backendTable ],
102
+ "status_global_attr. {$ linkField } = "
103
+ . BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . ". {$ linkField }"
104
+ . " AND status_global_attr.attribute_id = {$ attributeId }"
105
+ . ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID ,
88
106
[]
89
107
)
90
108
->willReturnSelf ();
91
109
$ this ->select ->expects ($ this ->at (1 ))
92
- ->method ('where ' )
93
- ->with ('status_attr.attribute_id = ? ' , $ attributeId )
110
+ ->method ('joinLeft ' )
111
+ ->with (
112
+ ['status_attr ' => $ backendTable ],
113
+ "status_attr. {$ linkField } = " . BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . ". {$ linkField }"
114
+ . " AND status_attr.attribute_id = {$ attributeId }"
115
+ . " AND status_attr.store_id = {$ currentStoreId }" ,
116
+ []
117
+ )
94
118
->willReturnSelf ();
95
119
$ this ->select ->expects ($ this ->at (2 ))
96
120
->method ('where ' )
97
- ->with ('status_attr.value = ? ' , Status::STATUS_ENABLED )
121
+ ->with ('IFNULL( status_attr.value, status_global_attr.value) = ? ' , Status::STATUS_ENABLED )
98
122
->willReturnSelf ();
99
123
100
124
$ this ->assertEquals ($ this ->select , $ this ->statusBaseSelectProcessor ->process ($ this ->select ));
0 commit comments