|
25 | 25 | use Gt\DomTemplate\Test\TestHelper\HTMLPageContent;
|
26 | 26 | use Gt\DomTemplate\Test\TestHelper\ExampleClass;
|
27 | 27 | use Gt\DomTemplate\Test\TestHelper\Model\Address;
|
| 28 | +use Gt\DomTemplate\Test\TestHelper\Model\ArrayIterator\Product\ProductList; |
28 | 29 | use Gt\DomTemplate\Test\TestHelper\Model\Country;
|
29 | 30 | use Gt\DomTemplate\Test\TestHelper\Model\Customer;
|
30 | 31 | use PHPUnit\Framework\TestCase;
|
@@ -1366,6 +1367,39 @@ public function getIterator():Traversable {
|
1366 | 1367 | self::assertCount(1, $ol->children);
|
1367 | 1368 | }
|
1368 | 1369 |
|
| 1370 | + public function testBindList_arrayIterator():void { |
| 1371 | + $document = new HTMLDocument(HTMLPageContent::HTML_SHOP_PRODUCTS); |
| 1372 | + $sut = new DocumentBinder($document); |
| 1373 | + $sut->setDependencies(...$this->documentBinderDependencies($document)); |
| 1374 | + |
| 1375 | + $categoryNameList = ["Category 1", "Category 2"]; |
| 1376 | + $productNameList = [ |
| 1377 | + ["Product 1 in cat 1", "Product 2 in cat 1"], |
| 1378 | + ["Product 3 in cat 2", "Product 4 in cat 2", "Product 5 in cat 2"], |
| 1379 | + ]; |
| 1380 | + |
| 1381 | + $obj = new ProductList( |
| 1382 | + $categoryNameList, |
| 1383 | + $productNameList, |
| 1384 | + ); |
| 1385 | + $sut->bindList($obj); |
| 1386 | + |
| 1387 | + $categoryList = $document->querySelector("ul.categoryList"); |
| 1388 | + self::assertCount(count($categoryNameList), $categoryList->children); |
| 1389 | + |
| 1390 | + $productCount = 0; |
| 1391 | + foreach($categoryList->children as $categoryIndex => $categoryLi) { |
| 1392 | + self::assertSame("Category " . ($categoryIndex + 1), $categoryLi->querySelector("h2")->innerText); |
| 1393 | + |
| 1394 | + self::assertCount(count($productNameList[$categoryIndex]), $categoryLi->querySelector("ul")->children); |
| 1395 | + |
| 1396 | + foreach($categoryLi->querySelectorAll("ul li") as $productIndex => $productLi) { |
| 1397 | + self::assertSame("Product " . ($productCount + 1) . " in cat " . ($categoryIndex + 1), $productLi->textContent); |
| 1398 | + $productCount++; |
| 1399 | + } |
| 1400 | + } |
| 1401 | + } |
| 1402 | + |
1369 | 1403 | private function documentBinderDependencies(HTMLDocument $document, mixed...$otherObjectList):array {
|
1370 | 1404 | $htmlAttributeBinder = new HTMLAttributeBinder();
|
1371 | 1405 | $htmlAttributeCollection = new HTMLAttributeCollection();
|
|
0 commit comments