55 */
66declare (strict_types=1 );
77
8- namespace Magento \Reports \Block \Adminhtml \Sales \Invoiced ;
8+ namespace Magento \Reports \Test \ Unit \ Block \Adminhtml \Sales \Invoiced ;
99
1010use Magento \Backend \Block \Template \Context ;
1111use Magento \Directory \Model \Currency ;
1515use Magento \Framework \Event \ManagerInterface ;
1616use Magento \Framework \Filesystem ;
1717use Magento \Framework \Math \Random ;
18- use Magento \Framework \Phrase ;
1918use Magento \Framework \Test \Unit \Helper \RequestInterfaceTestHelper ;
2019use Magento \Framework \UrlInterface ;
2120use Magento \Framework \View \Element \AbstractBlock ;
2423use Magento \Reports \Helper \Data ;
2524use Magento \Reports \Model \Grouped \CollectionFactory ;
2625use Magento \Reports \Model \ResourceModel \Report \Collection \Factory ;
26+ use Magento \Reports \Block \Adminhtml \Sales \Invoiced \Grid ;
2727use Magento \Store \Model \StoreManagerInterface ;
2828use PHPUnit \Framework \MockObject \Exception ;
2929use PHPUnit \Framework \TestCase ;
3030use PHPUnit \Framework \MockObject \MockObject ;
3131
32+ /**
33+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
34+ */
3235class GridTest extends TestCase
3336{
3437
@@ -153,7 +156,64 @@ public function testColumnsRenderer(): void
153156 ->onlyMethods (['setData ' ])
154157 ->getMock ();
155158
156- $ expectedData = [
159+ $ expectedData = $ this ->getColumnData ($ currencyCode , $ rate );
160+ $ callIndex = 0 ;
161+ $ extendedBlock
162+ ->method ('setData ' )
163+ ->willReturnCallback (function (array $ data ) use (&$ callIndex , $ expectedData , $ extendedBlock ) {
164+ if (!isset ($ expectedData [$ callIndex ])) {
165+ return $ extendedBlock ;
166+ }
167+ $ expected = $ this ->normalizeDataArray ($ expectedData [$ callIndex ]);
168+ $ actual = $ this ->normalizeDataArray ($ data );
169+
170+ self ::assertSame (
171+ $ expected ,
172+ $ actual ,
173+ sprintf ('Unexpected data passed to setData() at call #%d ' , $ callIndex + 1 )
174+ );
175+
176+ $ callIndex ++;
177+
178+ return $ extendedBlock ;
179+ });
180+
181+ $ extendedBlock ->method ('setId ' )->willReturnSelf ();
182+ $ extendedBlock ->method ('setGrid ' )->willReturnSelf ();
183+ $ this ->layout ->method ('createBlock ' )->willReturn ($ extendedBlock );
184+ $ block ->method ('getChildBlock ' )->willReturn ($ extendedBlock );
185+ $ block ->method ('getChildNames ' )->willReturn ([]);
186+
187+ $ this ->storeManager ->method ('getStores ' )->willReturn ([]);
188+ $ store = $ this ->createMock (\Magento \Store \Model \Store::class);
189+ $ store ->method ('getBaseCurrencyCode ' )->willReturn ($ currencyCode );
190+ $ currency = $ this ->createMock (Currency::class);
191+ $ currency ->method ('getRate ' )->willReturn ($ rate );
192+ $ store ->method ('getBaseCurrency ' )->willReturn ($ currency );
193+ $ this ->storeManager ->method ('getStore ' )->willReturn ($ store );
194+
195+ $ collection = $ this ->createMock (AbstractDb::class);
196+ $ select = $ this ->createMock (Select::class);
197+ $ collection ->method ('getSelect ' )->willReturn ($ select );
198+ $ collection
199+ ->method ('getIterator ' )
200+ ->willReturn (new \ArrayIterator ([new DataObject ([])]));
201+
202+ $ this ->invoicedGrid ->setTotals (new DataObject ());
203+ $ this ->invoicedGrid ->setCollection ($ collection );
204+ $ this ->invoicedGrid ->getXml ();
205+ }
206+
207+ /**
208+ * Invoice grid column data
209+ *
210+ * @param string $currencyCode
211+ * @param float $rate
212+ * @return array[]
213+ */
214+ private function getColumnData (string $ currencyCode , float $ rate ): array
215+ {
216+ return [
157217 [
158218 'header ' => __ ('Interval ' ),
159219 'index ' => 'period ' ,
@@ -218,58 +278,8 @@ public function testColumnsRenderer(): void
218278 'header_css_class ' => 'col-total-invoiced-not-paid ' ,
219279 'column_css_class ' => 'col-total-invoiced-not-paid ' ,
220280 'renderer ' => \Magento \Reports \Block \Adminhtml \Grid \Column \Renderer \Currency::class
221- ],
222- [
223- 'label ' => __ ('Reset Filter ' ),
224- 'onclick ' => 'testJsObject.resetFilter() ' ,
225- 'class ' => 'action-reset action-tertiary '
226281 ]
227282 ];
228- $ callIndex = 0 ;
229- $ extendedBlock
230- ->method ('setData ' )
231- ->willReturnCallback (function (array $ data ) use (&$ callIndex , $ expectedData , $ extendedBlock ) {
232- if (!isset ($ expectedData [$ callIndex ])) {
233- return $ extendedBlock ;
234- }
235- $ expected = $ this ->normalizeDataArray ($ expectedData [$ callIndex ]);
236- $ actual = $ this ->normalizeDataArray ($ data );
237-
238- self ::assertSame (
239- $ expected ,
240- $ actual ,
241- sprintf ('Unexpected data passed to setData() at call #%d ' , $ callIndex + 1 )
242- );
243-
244- $ callIndex ++;
245-
246- return $ extendedBlock ;
247- });
248-
249- $ extendedBlock ->method ('setId ' )->willReturnSelf ();
250- $ extendedBlock ->method ('setGrid ' )->willReturnSelf ();
251- $ this ->layout ->method ('createBlock ' )->willReturn ($ extendedBlock );
252- $ block ->method ('getChildBlock ' )->willReturn ($ extendedBlock );
253- $ block ->method ('getChildNames ' )->willReturn ([]);
254-
255- $ this ->storeManager ->method ('getStores ' )->willReturn ([]);
256- $ store = $ this ->createMock (\Magento \Store \Model \Store::class);
257- $ store ->method ('getBaseCurrencyCode ' )->willReturn ($ currencyCode );
258- $ currency = $ this ->createMock (Currency::class);
259- $ currency ->method ('getRate ' )->willReturn ($ rate );
260- $ store ->method ('getBaseCurrency ' )->willReturn ($ currency );
261- $ this ->storeManager ->method ('getStore ' )->willReturn ($ store );
262-
263- $ collection = $ this ->createMock (AbstractDb::class);
264- $ select = $ this ->createMock (Select::class);
265- $ collection ->method ('getSelect ' )->willReturn ($ select );
266- $ collection
267- ->method ('getIterator ' )
268- ->willReturn (new \ArrayIterator ([new DataObject ([])]));
269-
270- $ this ->invoicedGrid ->setTotals (new DataObject ());
271- $ this ->invoicedGrid ->setCollection ($ collection );
272- $ this ->invoicedGrid ->getXml ();
273283 }
274284
275285 /**
@@ -281,7 +291,7 @@ public function testColumnsRenderer(): void
281291 private function normalizeDataArray (array $ data ): array
282292 {
283293 array_walk_recursive ($ data , function (&$ value ) {
284- if ($ value instanceof Phrase ) {
294+ if (is_object ( $ value) ) {
285295 $ value = (string )$ value ;
286296 }
287297 });
0 commit comments