| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * DronePHP (http://www.dronephp.com) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @link      http://github.com/Pleets/DronePHP | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license   http://www.dronephp.com/license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @author    Darío Rivera <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | namespace DroneTest\Dom\Element; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Drone\Dom\Attribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Drone\Dom\Element\Form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Drone\Dom\Element\Input; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | class FormTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * Tests form tag constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @return null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public function testFormTags() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $form = new Form(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->assertEquals('<form>', $form->getStartTag()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertEquals('</form>', $form->getEndTag()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * Tests adding attributes and children | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @return null | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     public function testFormAttributesAndChildren() | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $form = new Form(); | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $this->assertEquals(0, count($form->getAttributes())); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertEquals(0, count($form->getChildren())); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         # adding an attribute | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         $form->setAttribute(new Attribute("action", "someurl")); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         $this->assertTrue($form->hasAttribute('action')); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         $attr = $form->getAttribute('action'); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $this->assertEquals("action", $attr->getName()); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         $this->assertEquals("someurl", $attr->getValue()); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         # adding an element | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $input = new Input(); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $input->setAttribute(new Attribute("type", "hidden")); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $form->setChild("someinput", $input); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $_input = $form->getChild('someinput'); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         $this->assertInstanceOf('\Drone\Dom\Element\Input', $_input); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 63 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |  |