This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
ValidationTextBoxTest.php
157 lines (138 loc) · 5.66 KB
/
ValidationTextBoxTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Dojo
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\Dojo\Form\Element;
use Zend\Dojo\Form\Element\ValidationTextBox as ValidationTextBoxElement,
Zend\Dojo\View\Helper\Dojo as DojoHelper,
Zend\Registry,
Zend\View;
/**
* Test class for Zend_Dojo_Form_Element_ValidationTextBox.
*
* @category Zend
* @package Zend_Dojo
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @group Zend_Dojo
* @group Zend_Dojo_Form
*/
class ValidationTextBoxTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
Registry::_unsetInstance();
DojoHelper::setUseDeclarative();
$this->view = $this->getView();
$this->element = $this->getElement();
$this->element->setView($this->view);
}
public function getView()
{
$view = new View\PhpRenderer();
\Zend\Dojo\Dojo::enableView($view);
return $view;
}
public function getElement()
{
$element = new ValidationTextBoxElement(
'foo',
array(
'value' => 'some text',
'label' => 'ValidationTextBox',
'class' => 'someclass',
'style' => 'width: 100px;',
)
);
return $element;
}
public function testInvalidMessageAccessorsShouldProxyToDijitParams()
{
$this->assertNull($this->element->getInvalidMessage());
$this->assertFalse(array_key_exists('invalidMessage', $this->element->dijitParams));
$this->element->setInvalidMessage('message');
$this->assertEquals('message', $this->element->getInvalidMessage());
$this->assertEquals('message', $this->element->dijitParams['invalidMessage']);
}
public function testPromptMessageAccessorsShouldProxyToDijitParams()
{
$this->assertNull($this->element->getPromptMessage());
$this->assertFalse(array_key_exists('promptMessage', $this->element->dijitParams));
$this->element->setPromptMessage('message');
$this->assertEquals('message', $this->element->getPromptMessage());
$this->assertEquals('message', $this->element->dijitParams['promptMessage']);
}
public function testRegExpAccessorsShouldProxyToDijitParams()
{
$this->assertNull($this->element->getRegExp());
$this->assertFalse(array_key_exists('regExp', $this->element->dijitParams));
$this->element->setRegExp('[\w]+');
$this->assertEquals('[\w]+', $this->element->getRegExp());
$this->assertEquals('[\w]+', $this->element->dijitParams['regExp']);
}
public function testConstraintsAccessorsShouldProxyToDijitParams()
{
$constraints = $this->element->getConstraints();
$this->assertTrue(empty($constraints));
$this->assertFalse(array_key_exists('constraints', $this->element->dijitParams));
$constraints = array('foo' => 'bar', 'bar' => 'baz');
$this->element->setConstraints($constraints);
$this->assertSame($constraints, $this->element->getConstraints());
$this->assertSame($constraints, $this->element->dijitParams['constraints']);
}
public function testShouldAllowSettingRetrievingAndRemovingInvididualConstraints()
{
$constraints = $this->element->getConstraints();
$this->assertTrue(empty($constraints));
$this->assertFalse($this->element->hasDijitParam('constraints'));
$this->element->setConstraint('foo', 'bar');
$this->assertTrue($this->element->hasConstraint('foo'));
$this->assertEquals('bar', $this->element->getConstraint('foo'));
$this->assertTrue($this->element->hasDijitParam('constraints'));
$this->assertEquals('bar', $this->element->dijitParams['constraints']['foo']);
$this->element->removeConstraint('foo');
$this->assertFalse($this->element->hasConstraint('foo'));
$this->assertTrue($this->element->hasDijitParam('constraints'));
$this->assertTrue(empty($this->element->dijitParams['constraints']));
}
public function testShouldAllowClearingConstraints()
{
$this->testConstraintsAccessorsShouldProxyToDijitParams();
$this->element->clearConstraints();
$this->assertFalse($this->element->hasDijitParam('constraints'));
}
public function testShouldRenderValidationTextBoxDijit()
{
$html = $this->element->render();
$this->assertContains('dojoType="dijit.form.ValidationTextBox"', $html);
}
public function testSettingMultipleConstraintsShouldNotOverridePreviousConstraints()
{
$this->element->setConstraint('foo', 'bar');
$this->element->setConstraints(array('spam' => 'ham'));
$this->assertEquals('bar', $this->element->getConstraint('foo'));
}
}