@@ -352,6 +352,107 @@ public function testContentForEachForEach()
352352 $ this ->assertEquals ($ sheet ->getTables ()[0 ], $ sheet ->getTables ()[2 ]);
353353 }
354354
355+ public function testCellsForEachForEach ()
356+ {
357+ $ mapping = [
358+ 'sheets ' => [
359+ [
360+ 'content ' => [
361+ [
362+ 'type ' => 'VerticalTable ' ,
363+ 'columns ' => [
364+ [
365+ 'foreach ' => 'headerList as header ' ,
366+ 'do ' => [
367+ [
368+ 'foreach ' => 'header as letter ' ,
369+ 'do ' => [
370+ '{{ letter }} '
371+ ]
372+ ]
373+ ]
374+ ],
375+ 'Col1 ' ,
376+ 'Col2 ' ,
377+ ],
378+ 'lines ' => [
379+ [
380+ 'foreach ' => 'foo as i => bar ' ,
381+ 'do ' => [
382+ [
383+ 'cells ' => [
384+ [
385+ 'foreach ' => 'indexList as index ' ,
386+ 'do ' => [
387+ [
388+ 'foreach ' => 'index as letter ' ,
389+ 'do ' => [
390+ '{{ letter }} '
391+ ]
392+ ]
393+ ],
394+ ],
395+ '{{ i }} ' ,
396+ '{{ bar }} ' ,
397+ ],
398+ ],
399+ ],
400+ ],
401+ ],
402+ ],
403+ ],
404+ ],
405+ ],
406+ ];
407+
408+ $ mappingReader = $ this ->getMockForAbstractClass ('Xport\MappingReader\MappingReader ' );
409+ $ mappingReader ->expects ($ this ->once ())->method ('getMapping ' )->will ($ this ->returnValue ($ mapping ));
410+
411+ $ modelBuilder = new SpreadsheetModelBuilder ();
412+ $ modelBuilder ->bind ('headerList ' , [['A ' , 'B ' ], ['C ' , 'D ' , 'E ' ]]);
413+ $ modelBuilder ->bind ('indexList ' , [['1 ' , '2 ' ], ['3 ' , '4 ' , '5 ' ]]);
414+ $ modelBuilder ->bind ('foo ' , ['test1 ' , 'test2 ' ]);
415+ $ result = $ modelBuilder ->build ($ mappingReader );
416+
417+ $ this ->assertTrue ($ result instanceof Document);
418+ $ this ->assertCount (1 , $ result ->getSheets ());
419+
420+ $ sheet = $ result ->getSheets ()[0 ];
421+ $ this ->assertCount (1 , $ sheet ->getTables ());
422+
423+ // Table
424+ $ table = $ sheet ->getTables ()[0 ];
425+ $ this ->assertCount (2 , $ table ->getLines ());
426+ $ this ->assertNull ($ table ->getLabel ());
427+
428+ // Columns
429+ $ this ->assertCount (7 , $ table ->getColumns ());
430+ $ this ->assertEquals ('A ' , $ table ->getColumns ()[0 ]->getLabel ());
431+ $ this ->assertEquals ('B ' , $ table ->getColumns ()[1 ]->getLabel ());
432+ $ this ->assertEquals ('C ' , $ table ->getColumns ()[2 ]->getLabel ());
433+ $ this ->assertEquals ('D ' , $ table ->getColumns ()[3 ]->getLabel ());
434+ $ this ->assertEquals ('E ' , $ table ->getColumns ()[4 ]->getLabel ());
435+ $ this ->assertEquals ('Col1 ' , $ table ->getColumns ()[5 ]->getLabel ());
436+ $ this ->assertEquals ('Col2 ' , $ table ->getColumns ()[6 ]->getLabel ());
437+
438+ // Cells
439+ $ this ->assertCount (14 , $ table ->getCells ());
440+ $ this ->assertEquals ('1 ' , $ table ->getCell ($ table ->getLines ()[0 ], $ table ->getColumns ()[0 ])->getContent ());
441+ $ this ->assertEquals ('2 ' , $ table ->getCell ($ table ->getLines ()[0 ], $ table ->getColumns ()[1 ])->getContent ());
442+ $ this ->assertEquals ('3 ' , $ table ->getCell ($ table ->getLines ()[0 ], $ table ->getColumns ()[2 ])->getContent ());
443+ $ this ->assertEquals ('4 ' , $ table ->getCell ($ table ->getLines ()[0 ], $ table ->getColumns ()[3 ])->getContent ());
444+ $ this ->assertEquals ('5 ' , $ table ->getCell ($ table ->getLines ()[0 ], $ table ->getColumns ()[4 ])->getContent ());
445+ $ this ->assertEquals ('0 ' , $ table ->getCell ($ table ->getLines ()[0 ], $ table ->getColumns ()[5 ])->getContent ());
446+ $ this ->assertEquals ('test1 ' , $ table ->getCell ($ table ->getLines ()[0 ], $ table ->getColumns ()[6 ])->getContent ());
447+ $ this ->assertEquals ('1 ' , $ table ->getCell ($ table ->getLines ()[1 ], $ table ->getColumns ()[0 ])->getContent ());
448+ $ this ->assertEquals ('2 ' , $ table ->getCell ($ table ->getLines ()[1 ], $ table ->getColumns ()[1 ])->getContent ());
449+ $ this ->assertEquals ('3 ' , $ table ->getCell ($ table ->getLines ()[1 ], $ table ->getColumns ()[2 ])->getContent ());
450+ $ this ->assertEquals ('4 ' , $ table ->getCell ($ table ->getLines ()[1 ], $ table ->getColumns ()[3 ])->getContent ());
451+ $ this ->assertEquals ('5 ' , $ table ->getCell ($ table ->getLines ()[1 ], $ table ->getColumns ()[4 ])->getContent ());
452+ $ this ->assertEquals ('1 ' , $ table ->getCell ($ table ->getLines ()[1 ], $ table ->getColumns ()[5 ])->getContent ());
453+ $ this ->assertEquals ('test2 ' , $ table ->getCell ($ table ->getLines ()[1 ], $ table ->getColumns ()[6 ])->getContent ());
454+ }
455+
355456 public function testComplexForeachStructure ()
356457 {
357458 /** @var Document $result */
0 commit comments