|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace ipl\Tests\Html; |
| 4 | + |
| 5 | +use ipl\Html\Attribute; |
| 6 | +use ipl\Html\Attributes; |
| 7 | +use ipl\Html\Form; |
| 8 | +use ipl\Html\FormElement\SelectElement; |
| 9 | +use ipl\Html\FormElement\SubmitElement; |
| 10 | + |
| 11 | +class CloneTest extends TestCase |
| 12 | +{ |
| 13 | + public function testCloningSubmitElement(): void |
| 14 | + { |
| 15 | + $originalButton = new SubmitElement('exampleButton', ['class' => 'class01']); |
| 16 | + |
| 17 | + $clonesButton = clone $originalButton; |
| 18 | + $clonesButton->getAttributes()->setAttribute(Attribute::create('class', 'class02')); |
| 19 | + |
| 20 | + $this->assertNotSame( |
| 21 | + $originalButton->getAttributes()->get('class')->getValue(), |
| 22 | + $clonesButton->getAttributes()->get('class')->getValue() |
| 23 | + ); |
| 24 | + $this->assertNotSame($originalButton->render(), $clonesButton->render()); |
| 25 | + } |
| 26 | + |
| 27 | + public function testCloningSelectElement() |
| 28 | + { |
| 29 | + $original = new SelectElement('test_select', [ |
| 30 | + 'label' => 'Test Select', |
| 31 | + 'options' => [ |
| 32 | + 1 => 'One', |
| 33 | + 2 => 'Two' |
| 34 | + ] |
| 35 | + ]); |
| 36 | + $clone = clone $original; |
| 37 | + |
| 38 | + $clone->getAttributes()->setAttribute(Attribute::create('class', 'class02')); |
| 39 | + |
| 40 | + $this->assertNotSame($original->render(), $clone->render()); |
| 41 | + } |
| 42 | + |
| 43 | + public function testCloningForm(): void |
| 44 | + { |
| 45 | + $original = new Form(); |
| 46 | + $original->addElement('input', 'test_input', [ |
| 47 | + 'label' => 'Test Input' |
| 48 | + ]); |
| 49 | + |
| 50 | + $clone = clone $original; |
| 51 | + $clone->addElement('submit', 'test_submit', [ |
| 52 | + 'label' => 'Test Submit' |
| 53 | + ]); |
| 54 | + $clone->getAttributes()->setAttribute(Attribute::create('class', 'class02')); |
| 55 | + |
| 56 | + $this->assertNotSame($original->render(), $clone->render()); |
| 57 | + } |
| 58 | + |
| 59 | + public function testCloningAttributes(): void |
| 60 | + { |
| 61 | + $original = Attributes::create([Attribute::create('class', 'class01')]); |
| 62 | + |
| 63 | + $clone = clone $original; |
| 64 | + $clone->setAttribute(Attribute::create('class', 'class02')); |
| 65 | + |
| 66 | + $this->assertNotSame($original, $clone); |
| 67 | + } |
| 68 | +} |
0 commit comments