|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * OpenMage |
| 5 | + * |
| 6 | + * This source file is subject to the Open Software License (OSL 3.0) |
| 7 | + * that is bundled with this package in the file LICENSE.txt. |
| 8 | + * It is also available at https://opensource.org/license/osl-3-0-php |
| 9 | + * |
| 10 | + * @category OpenMage |
| 11 | + * @package OpenMage_Tests |
| 12 | + * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) |
| 13 | + * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
| 14 | + */ |
| 15 | + |
| 16 | +declare(strict_types=1); |
| 17 | + |
| 18 | +namespace OpenMage\Tests\Unit\Mage\Core\Block\Text; |
| 19 | + |
| 20 | +use Mage; |
| 21 | +use PHPUnit\Framework\TestCase; |
| 22 | + |
| 23 | +class ListTest extends TestCase |
| 24 | +{ |
| 25 | + public function setUp(): void |
| 26 | + { |
| 27 | + Mage::app(); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @group Mage_Core |
| 32 | + * @group Mage_Core_Block |
| 33 | + */ |
| 34 | + public function testDuplicateBlockName(): void |
| 35 | + { |
| 36 | + $layout = Mage::getModel('core/layout'); |
| 37 | + |
| 38 | + $parentBlock = $layout->createBlock('core/text_list', 'parent'); |
| 39 | + |
| 40 | + $childBlockA = $layout->createBlock('core/text', 'child_a')->setText('A1'); |
| 41 | + $parentBlock->append($childBlockA); |
| 42 | + |
| 43 | + $childBlockA = $layout->createBlock('core/text', 'child_a')->setText('A2'); |
| 44 | + $parentBlock->append($childBlockA); |
| 45 | + |
| 46 | + $this->assertSame('A2', $parentBlock->toHtml()); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @group Mage_Core |
| 51 | + * @group Mage_Core_Block |
| 52 | + */ |
| 53 | + public function testDuplicateBlockNameOrdering(): void |
| 54 | + { |
| 55 | + $layout = Mage::getModel('core/layout'); |
| 56 | + |
| 57 | + $parentBlock = $layout->createBlock('core/text_list', 'parent'); |
| 58 | + |
| 59 | + $childBlockA = $layout->createBlock('core/text', 'child_a')->setText('A'); |
| 60 | + $parentBlock->append($childBlockA); |
| 61 | + |
| 62 | + $childBlockB = $layout->createBlock('core/text', 'child_b')->setText('B'); |
| 63 | + $parentBlock->append($childBlockB); |
| 64 | + |
| 65 | + $childBlockC = $layout->createBlock('core/text', 'child_c')->setText('C'); |
| 66 | + $parentBlock->append($childBlockC); |
| 67 | + |
| 68 | + $parentBlock->unsetChild('child_b'); |
| 69 | + |
| 70 | + $childBlockB = $layout->createBlock('core/text', 'child_b')->setText('B'); |
| 71 | + $parentBlock->insert($childBlockB, 'child_c', false); |
| 72 | + |
| 73 | + $this->assertSame('ABC', $parentBlock->toHtml()); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @group Mage_Core |
| 78 | + * @group Mage_Core_Block |
| 79 | + */ |
| 80 | + public function testUniqueBlockNameOrdering(): void |
| 81 | + { |
| 82 | + $layout = Mage::getModel('core/layout'); |
| 83 | + |
| 84 | + $parentBlock = $layout->createBlock('core/text_list', 'parent'); |
| 85 | + |
| 86 | + $childBlockD = $layout->createBlock('core/text', 'child_d')->setText('D'); |
| 87 | + $parentBlock->insert($childBlockD, 'child_c', true); |
| 88 | + |
| 89 | + $childBlockC = $layout->createBlock('core/text', 'child_c')->setText('C'); |
| 90 | + $parentBlock->insert($childBlockC, 'child_b', true); |
| 91 | + |
| 92 | + $childBlockA = $layout->createBlock('core/text', 'child_a')->setText('A'); |
| 93 | + $parentBlock->insert($childBlockC, 'child_b', false); |
| 94 | + |
| 95 | + $childBlockB = $layout->createBlock('core/text', 'child_b')->setText('B'); |
| 96 | + $parentBlock->insert($childBlockC, 'child_a', true); |
| 97 | + |
| 98 | + $parentBlock->unsetChild('child_a'); |
| 99 | + $parentBlock->unsetChild('child_b'); |
| 100 | + |
| 101 | + $this->assertSame('CD', $parentBlock->toHtml()); |
| 102 | + } |
| 103 | +} |
0 commit comments