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
158
159
160
161
162
163
164
165
166
167
168
|
<?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-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: CurrencyTextBoxTest.php 11973 2008-10-15 16:00:56Z matthew $
*/
// Call Zend_Dojo_Form_Element_CurrencyTextBoxTest::main() if this source file is executed directly.
if (!defined("PHPUnit_MAIN_METHOD")) {
define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_CurrencyTextBoxTest::main");
}
require_once dirname(__FILE__) . '/../../../../TestHelper.php';
/** Zend_Dojo_Form_Element_CurrencyTextBox */
require_once 'Zend/Dojo/Form/Element/CurrencyTextBox.php';
/** Zend_View */
require_once 'Zend/View.php';
/** Zend_Registry */
require_once 'Zend/Registry.php';
/** Zend_Dojo_View_Helper_Dojo */
require_once 'Zend/Dojo/View/Helper/Dojo.php';
/**
* Test class for Zend_Dojo_Form_Element_Dijit.
*
* @package Zend_Dojo
* @subpackage UnitTests
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Dojo_Form_Element_CurrencyTextBoxTest extends PHPUnit_Framework_TestCase
{
/**
* Runs the test methods of this class.
*
* @return void
*/
public static function main()
{
$suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_Form_Element_CurrencyTextBoxTest");
$result = PHPUnit_TextUI_TestRunner::run($suite);
}
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
Zend_Registry::_unsetInstance();
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
$this->view = $this->getView();
$this->element = $this->getElement();
$this->element->setView($this->view);
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @return void
*/
public function tearDown()
{
}
public function getView()
{
require_once 'Zend/View.php';
$view = new Zend_View();
$view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
return $view;
}
public function getElement()
{
$element = new Zend_Dojo_Form_Element_CurrencyTextBox(
'foo',
array(
'value' => 'some text',
'label' => 'CurrencyTextBox',
'class' => 'someclass',
'style' => 'width: 100px;',
)
);
return $element;
}
public function testShouldExtendNumberTextBox()
{
$this->assertTrue($this->element instanceof Zend_Dojo_Form_Element_NumberTextBox);
}
public function testCurrencyAccessorsShouldProxyToDijitParams()
{
$this->assertNull($this->element->getCurrency());
$this->assertNull($this->element->getDijitParam('currency'));
$this->element->setCurrency('USD');
$this->assertEquals('USD', $this->element->getCurrency());
$this->assertEquals('USD', $this->element->getDijitParam('currency'));
}
public function testFractionalAccessorsShouldProxyToConstraints()
{
$this->assertFalse($this->element->getFractional());
$this->assertFalse(array_key_exists('constraints', $this->element->dijitParams));
$this->element->setFractional(true);
$this->assertTrue($this->element->getFractional());
$this->assertEquals('true', $this->element->dijitParams['constraints']['fractional']);
}
public function testSymbolAccessorsShouldProxyToConstraints()
{
$this->assertNull($this->element->getSymbol());
$this->assertFalse($this->element->hasConstraint('symbol'));
$this->element->setSymbol('USD');
$this->assertEquals('USD', $this->element->getSymbol());
$this->assertEquals('USD', $this->element->getConstraint('symbol'));
}
public function testSymbolMutatorShouldCastToStringAndUppercaseAndLimitTo3Chars()
{
$this->element->setSymbol('usdollar');
$this->assertEquals('USD', $this->element->getSymbol());
$this->assertEquals('USD', $this->element->getConstraint('symbol'));
}
/**
* @expectedException Zend_Form_Element_Exception
*/
public function testSymbolMutatorShouldRaiseExceptionWhenFewerThan3CharsProvided()
{
$this->element->setSymbol('$');
}
public function testShouldRenderCurrencyTextBoxDijit()
{
$html = $this->element->render();
$this->assertContains('dojoType="dijit.form.CurrencyTextBox"', $html);
}
}
// Call Zend_Dojo_Form_Element_CurrencyTextBoxTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_CurrencyTextBoxTest::main") {
Zend_Dojo_Form_Element_CurrencyTextBoxTest::main();
}
|