@@ -60,8 +60,17 @@ protected function setUp(): void
60
60
->willReturn ($ this ->metadataMock );
61
61
$ this ->configMock = $ args ['config ' ];
62
62
$ this ->scopeResolverMock = $ args ['scopeResolver ' ];
63
+
64
+ $ scopeMock = $ this ->getMockBuilder (\Magento \Framework \Model \Entity \ScopeInterface::class)
65
+ ->disableOriginalConstructor ()
66
+ ->getMock ();
67
+ $ fallback = clone $ scopeMock ;
68
+ $ scopeMock ->method ('getIdentifier ' )->willReturn ('store_id ' );
69
+ $ scopeMock ->method ('getValue ' )->willReturn (1 );
70
+ $ scopeMock ->method ('getFallback ' )->willReturn ($ fallback );
71
+
63
72
$ this ->scopeResolverMock ->method ('getEntityContext ' )
64
- ->willReturn ([]);
73
+ ->willReturn ([$ scopeMock ]);
65
74
66
75
$ this ->readHandler = $ objectManager ->getObject (ReadHandler::class, $ args );
67
76
}
@@ -73,8 +82,12 @@ protected function setUp(): void
73
82
* @param bool $isStatic
74
83
* @dataProvider executeDataProvider
75
84
*/
76
- public function testExecute ($ eavEntityType , $ callNum , array $ expected , $ isStatic = true )
77
- {
85
+ public function testExecute (
86
+ $ eavEntityType ,
87
+ $ callNum ,
88
+ array $ expected ,
89
+ $ isStatic = true
90
+ ) {
78
91
$ entityData = ['linkField ' => 'theLinkField ' ];
79
92
$ this ->metadataMock ->method ('getEavEntityType ' )
80
93
->willReturn ($ eavEntityType );
@@ -105,10 +118,83 @@ public function testExecute($eavEntityType, $callNum, array $expected, $isStatic
105
118
->willReturn ('linkField ' );
106
119
107
120
$ attributeMock = $ this ->getMockBuilder (AbstractAttribute::class)
121
+ ->setMethods (['getAttributeCode ' , 'isScopeWebsite ' , 'isStatic ' , 'getBackend ' , 'getAttributeId ' ])
122
+ ->disableOriginalConstructor ()
123
+ ->getMockForAbstractClass ();
124
+ $ attributeMock ->method ('isStatic ' )
125
+ ->willReturn ($ isStatic );
126
+ $ backendMock = $ this ->getMockBuilder (AbstractBackend::class)
127
+ ->disableOriginalConstructor ()
128
+ ->getMock ();
129
+ $ backendMock ->method ('getTable ' )
130
+ ->willReturn ('backendTable ' );
131
+ $ attributeMock ->method ('getBackend ' )
132
+ ->willReturn ($ backendMock );
133
+ $ attributeMock ->method ('getAttributeId ' )
134
+ ->willReturn ('attributeId ' );
135
+ $ attributeMock ->method ('getAttributeCode ' )
136
+ ->willReturn ('attributeCode ' );
137
+ $ this ->configMock ->expects ($ this ->exactly ($ callNum ))
138
+ ->method ('getEntityAttributes ' )
139
+ ->willReturn ([$ attributeMock ]);
140
+ $ this ->assertEquals ($ expected , $ this ->readHandler ->execute ('entity_type ' , $ entityData ));
141
+ }
142
+
143
+ /**
144
+ * @param string $eavEntityType
145
+ * @param int $callNum
146
+ * @param array $expected
147
+ * @param bool $isStatic
148
+ * @param null|int $isGlobalScope
149
+ * @throws \Magento\Framework\Exception\ConfigurationMismatchException
150
+ * @throws \Magento\Framework\Exception\LocalizedException
151
+ * @dataProvider executeGlobalScopeDataProvider
152
+ */
153
+ public function testExecuteGlobalScope (
154
+ $ eavEntityType ,
155
+ $ callNum ,
156
+ array $ expected ,
157
+ $ isStatic = true ,
158
+ $ isGlobalScope = null
159
+ ) {
160
+ $ entityData = ['linkField ' => 'theLinkField ' ];
161
+ $ this ->metadataMock ->method ('getEavEntityType ' )
162
+ ->willReturn ($ eavEntityType );
163
+ $ connectionMock = $ this ->getMockBuilder (AdapterInterface::class)
164
+ ->disableOriginalConstructor ()
165
+ ->getMockForAbstractClass ();
166
+ $ selectMock = $ this ->getMockBuilder (Select::class)
108
167
->disableOriginalConstructor ()
109
168
->getMock ();
169
+ $ selectMock ->method ('from ' )
170
+ ->willReturnSelf ();
171
+ $ selectMock ->method ('where ' )
172
+ ->willReturnSelf ();
173
+ $ connectionMock ->method ('select ' )
174
+ ->willReturn ($ selectMock );
175
+ $ connectionMock ->method ('fetchAll ' )
176
+ ->willReturn (
177
+ [
178
+ [
179
+ 'attribute_id ' => 'attributeId ' ,
180
+ 'value ' => 'attributeValue ' ,
181
+ 'store_id ' => 0
182
+ ]
183
+ ]
184
+ );
185
+ $ this ->metadataMock ->method ('getEntityConnection ' )
186
+ ->willReturn ($ connectionMock );
187
+ $ this ->metadataMock ->method ('getLinkField ' )
188
+ ->willReturn ('linkField ' );
189
+
190
+ $ attributeMock = $ this ->getMockBuilder (AbstractAttribute::class)
191
+ ->setMethods (['getAttributeCode ' , 'isScopeWebsite ' , 'getIsGlobal ' , 'isStatic ' , 'getBackend ' , 'getAttributeId ' ])
192
+ ->disableOriginalConstructor ()
193
+ ->getMockForAbstractClass ();
110
194
$ attributeMock ->method ('isStatic ' )
111
195
->willReturn ($ isStatic );
196
+ $ attributeMock ->method ('getIsGlobal ' )
197
+ ->willReturn ($ isGlobalScope );
112
198
$ backendMock = $ this ->getMockBuilder (AbstractBackend::class)
113
199
->disableOriginalConstructor ()
114
200
->getMock ();
@@ -142,6 +228,39 @@ public function executeDataProvider()
142
228
'attributeCode ' => 'attributeValue '
143
229
],
144
230
false
231
+ ]
232
+ ];
233
+ }
234
+
235
+ /**
236
+ * @return array
237
+ */
238
+ public function executeGlobalScopeDataProvider ()
239
+ {
240
+ return [
241
+ 'null entity type ' => [null , 0 , ['linkField ' => 'theLinkField ' ]],
242
+ 'static attribute ' => ['env-entity-type ' , 1 , ['linkField ' => 'theLinkField ' ]],
243
+ 'non-static attribute ' => [
244
+ 'env-entity-type ' ,
245
+ 1 ,
246
+ [
247
+ 'linkField ' => 'theLinkField ' ,
248
+ 'attributeCode ' => 'attributeValue '
249
+ ],
250
+ false ,
251
+ null ,
252
+ 1
253
+ ],
254
+ 'non-static attribute2 ' => [
255
+ 'env-entity-type ' ,
256
+ 1 ,
257
+ [
258
+ 'linkField ' => 'theLinkField ' ,
259
+ 'attributeCode ' => 'attributeValue '
260
+ ],
261
+ false ,
262
+ 1 ,
263
+ 0
145
264
],
146
265
];
147
266
}
0 commit comments