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\Element\ElementFactory; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
class ElementFactoryTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Tests if will we get an Element instance from factory |
20
|
|
|
* |
21
|
|
|
* @return null |
22
|
|
|
*/ |
23
|
|
|
public function testFormCreationFromFactory() |
24
|
|
|
{ |
25
|
|
|
$form = ElementFactory::create('FORM', [ |
26
|
|
|
"action" => 'someurl', |
27
|
|
|
"method" => 'post', |
28
|
|
|
], [ |
29
|
|
|
"input" => [ |
30
|
|
|
"username" => [ |
31
|
|
|
"type" => 'text', |
32
|
|
|
"maxlength" => 15, |
33
|
|
|
"minlength" => 5, |
34
|
|
|
], |
35
|
|
|
"password" => [ |
36
|
|
|
"type" => 'password', |
37
|
|
|
"maxlength" => 15, |
38
|
|
|
"minlength" => 5, |
39
|
|
|
], |
40
|
|
|
], |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
|
$this->assertEquals('<form>', $form->getStartTag()); |
44
|
|
|
$this->assertEquals('</form>', $form->getEndTag()); |
45
|
|
|
$this->assertTrue($form->hasAttribute('action')); |
46
|
|
|
$this->assertTrue($form->hasAttribute('method')); |
47
|
|
|
$this->assertTrue($form->hasChild('username')); |
48
|
|
|
$this->assertTrue($form->hasChild('password')); |
49
|
|
|
|
50
|
|
|
$actionAttr = $form->getAttribute('action'); |
51
|
|
|
|
52
|
|
|
$this->assertEquals('action', $actionAttr->getName()); |
53
|
|
|
$this->assertEquals('someurl', $actionAttr->getValue()); |
54
|
|
|
|
55
|
|
|
$inputElem = $form->getChild('username'); |
56
|
|
|
|
57
|
|
|
$this->assertEquals('<input', $inputElem->getStartTag()); |
58
|
|
|
$this->assertEquals('/>', $inputElem->getEndTag()); |
59
|
|
|
|
60
|
|
|
$typeAttrFromInput = $inputElem->getAttribute('type'); |
61
|
|
|
$this->assertEquals('type', $typeAttrFromInput->getName()); |
62
|
|
|
$this->assertEquals('text', $typeAttrFromInput->getValue()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|