| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use HexMakina\Marker\Element; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | final class ElementTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     public function testCanBeCreatedFromValidTagName(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |         $this->assertInstanceOf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |             Element::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |             new Element('div') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     public function testCanBeUsedAsString(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             '<div>test</div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |             Element::div('test')->__toString() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function testVoidElement(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             '<hr/>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             Element::hr()->__toString() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     public function testVoidElementWithAttribute(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             '<img src="test.jpg"/>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             Element::img(null, ['src' => 'test.jpg'])->__toString() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             '<img src="test.jpg"/>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             (new Element('img', null, ['src' => 'test.jpg']))->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function testCanHaveBooleanAttribute(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $element = new Element('input', null, ['checked']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             '<input checked/>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     public function testCanHaveMixedAttributes(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $element = new Element('input', null, ['type' => 'radio', 'name' => 'gaga', 'checked']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             '<input type="radio" name="gaga" checked/>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $element->class = 'test'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             '<input type="radio" name="gaga" checked class="test"/>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $element->class = ['foo', 'bar']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             '<input type="radio" name="gaga" checked class="foo bar"/>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     public function testCanHaveStringClassAttribute(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         $element = new Element('div', 'with class', ['class' => 'test']); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         $this->assertEquals( | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |             '<div class="test">with class</div>', | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     public function testCanHaveArrayClassAttribute(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $element = new Element('div', 'Hello, World!', ['class' => ['foo', 'bar']]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             '<div class="foo bar">Hello, World!</div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     public function testCanHaveMultipleAttributes(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $element = new Element('div', 'Hello, World!', ['class' => ['foo', 'bar'], 'id' => 'test']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             '<div class="foo bar" id="test">Hello, World!</div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     public function testContentHasSpecialCaracters(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $element = new Element('div', 'Hello, World! & < > " \' ', ['class' => ['foo', 'bar'], 'id' => 'test']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             '<div class="foo bar" id="test">Hello, World! & < > " ' </div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         $element = new Element('div', 'Hello, World! & < > " \' ', ['class' => ['foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             'bar'], 'id' => 'test', 'data-attr' => 'Hello, World! & < > " \' ']);    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             '<div class="foo bar" id="test" data-attr="Hello, World! & < > " ' ">Hello, World! & < > " ' </div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $element = new Element('div', 'Hello, World! & < > " \' ', ['class' => ['foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             'bar'], 'id' => 'test', 'data-attr' => 'Hello, World! & < > " \' ', 'data-attr2' => 'Hello, World! & < > " \' ']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             '<div class="foo bar" id="test" data-attr="Hello, World! & < > " ' " data-attr2="Hello, World! & < > " ' ">Hello, World! & < > " ' </div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     public function testFormatterFalse(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $element = new Element('div', 'Hello, World! & < > " \' ', ['class' => ['foo', 'bar'], 'id' => 'test'], false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |             '<div class="foo bar" id="test">Hello, World! & < > " ' </div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $element = new Element('div', 'Hello, World! & < > " \' ', ['class' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |             'bar' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |         ], 'id' => 'test', 'data-attr' => 'Hello, World! & < > " \' '], false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |             '<div class="foo bar" id="test" data-attr="Hello, World! & < > " ' ">Hello, World! & < > " ' </div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         $element = new Element('div', 'Hello, World! & < > " \' ', ['class' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |             'foo', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             'bar' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         ], 'id' => 'test', 'data-attr' => 'Hello, World! & < > " \' ', 'data-attr2' => 'Hello, World! & < > " \' '], false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         $this->assertEquals( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             '<div class="foo bar" id="test" data-attr="Hello, World! & < > " ' " data-attr2="Hello, World! & < > " ' ">Hello, World! & < > " ' </div>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |             $element->__toString() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |         );  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 162 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 163 |  |  |  |