1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Form\Form; |
4
|
|
|
|
5
|
|
|
use Fiv\Form\Element\Input; |
6
|
|
|
use Fiv\Form\Filter\Trim; |
7
|
|
|
use Fiv\Form\Form; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @package Tests\Form\Form |
11
|
|
|
*/ |
12
|
|
|
class HiddenTest extends \Tests\Form\MainTestCase { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @return \Fiv\Form\Element\Input |
16
|
|
|
*/ |
17
|
|
|
protected function getElement() { |
18
|
|
|
$form = new Form(); |
19
|
|
|
return $form->hidden("test"); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
public function testRender() { |
24
|
|
|
$element = $this->getElement(); |
25
|
|
|
|
26
|
|
|
$this->assertContains("hidden", (string) $element); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
public function testAttributes() { |
31
|
|
|
|
32
|
|
|
$element = $this->getElement(); |
33
|
|
|
|
34
|
|
|
$this->assertEquals('test', $element->getName()); |
35
|
|
|
$this->assertEmpty($element->getClass()); |
36
|
|
|
|
37
|
|
|
$element->setClass("hidden_class"); |
38
|
|
|
$this->assertEquals("hidden_class", $element->getClass()); |
39
|
|
|
|
40
|
|
|
$element->setAttribute('data-id', 'custom-id'); |
41
|
|
|
$this->assertEquals('custom-id', $element->getAttribute('data-id')); |
42
|
|
|
|
43
|
|
|
$element->removeAttribute('data-id'); |
44
|
|
|
$this->assertEquals(null, $element->getAttribute('data-id')); |
45
|
|
|
|
46
|
|
|
$error = null; |
47
|
|
|
try { |
48
|
|
|
$element->sendItem(); |
|
|
|
|
49
|
|
|
} catch (\Exception $error) { |
|
|
|
|
50
|
|
|
} |
51
|
|
|
$this->assertInstanceOf('Exception', $error); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testValueWithSlashes() { |
56
|
|
|
|
57
|
|
|
$input = new Input(); |
58
|
|
|
$input->setName('test'); |
59
|
|
|
$input->setType('hidden'); |
60
|
|
|
$value = ' 123"234 \' 44 '; |
61
|
|
|
|
62
|
|
|
$input->addFilter(new Trim()); |
63
|
|
|
|
64
|
|
|
$input->setValue($value); |
65
|
|
|
|
66
|
|
|
$this->assertContains('<input type="hidden" name="test" value="123"234 ' 44"', $input->render()); |
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: