7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
17
* @subpackage UnitTests
18
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
19
* @license http://framework.zend.com/license/new-bsd New BSD License
20
* @version $Id: CurrencyTextBoxTest.php 11973 2008-10-15 16:00:56Z matthew $
23
// Call Zend_Dojo_Form_Element_CurrencyTextBoxTest::main() if this source file is executed directly.
24
if (!defined("PHPUnit_MAIN_METHOD")) {
25
define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_CurrencyTextBoxTest::main");
28
require_once dirname(__FILE__) . '/../../../../TestHelper.php';
30
/** Zend_Dojo_Form_Element_CurrencyTextBox */
31
require_once 'Zend/Dojo/Form/Element/CurrencyTextBox.php';
34
require_once 'Zend/View.php';
37
require_once 'Zend/Registry.php';
39
/** Zend_Dojo_View_Helper_Dojo */
40
require_once 'Zend/Dojo/View/Helper/Dojo.php';
43
* Test class for Zend_Dojo_Form_Element_Dijit.
46
* @subpackage UnitTests
47
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
48
* @license http://framework.zend.com/license/new-bsd New BSD License
50
class Zend_Dojo_Form_Element_CurrencyTextBoxTest extends PHPUnit_Framework_TestCase
53
* Runs the test methods of this class.
57
public static function main()
59
$suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_Form_Element_CurrencyTextBoxTest");
60
$result = PHPUnit_TextUI_TestRunner::run($suite);
64
* Sets up the fixture, for example, open a network connection.
65
* This method is called before a test is executed.
69
public function setUp()
71
Zend_Registry::_unsetInstance();
72
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
74
$this->view = $this->getView();
75
$this->element = $this->getElement();
76
$this->element->setView($this->view);
80
* Tears down the fixture, for example, close a network connection.
81
* This method is called after a test is executed.
85
public function tearDown()
89
public function getView()
91
require_once 'Zend/View.php';
92
$view = new Zend_View();
93
$view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
97
public function getElement()
99
$element = new Zend_Dojo_Form_Element_CurrencyTextBox(
102
'value' => 'some text',
103
'label' => 'CurrencyTextBox',
104
'class' => 'someclass',
105
'style' => 'width: 100px;',
111
public function testShouldExtendNumberTextBox()
113
$this->assertTrue($this->element instanceof Zend_Dojo_Form_Element_NumberTextBox);
116
public function testCurrencyAccessorsShouldProxyToDijitParams()
118
$this->assertNull($this->element->getCurrency());
119
$this->assertNull($this->element->getDijitParam('currency'));
120
$this->element->setCurrency('USD');
121
$this->assertEquals('USD', $this->element->getCurrency());
122
$this->assertEquals('USD', $this->element->getDijitParam('currency'));
125
public function testFractionalAccessorsShouldProxyToConstraints()
127
$this->assertFalse($this->element->getFractional());
128
$this->assertFalse(array_key_exists('constraints', $this->element->dijitParams));
129
$this->element->setFractional(true);
130
$this->assertTrue($this->element->getFractional());
131
$this->assertEquals('true', $this->element->dijitParams['constraints']['fractional']);
134
public function testSymbolAccessorsShouldProxyToConstraints()
136
$this->assertNull($this->element->getSymbol());
137
$this->assertFalse($this->element->hasConstraint('symbol'));
138
$this->element->setSymbol('USD');
139
$this->assertEquals('USD', $this->element->getSymbol());
140
$this->assertEquals('USD', $this->element->getConstraint('symbol'));
143
public function testSymbolMutatorShouldCastToStringAndUppercaseAndLimitTo3Chars()
145
$this->element->setSymbol('usdollar');
146
$this->assertEquals('USD', $this->element->getSymbol());
147
$this->assertEquals('USD', $this->element->getConstraint('symbol'));
151
* @expectedException Zend_Form_Element_Exception
153
public function testSymbolMutatorShouldRaiseExceptionWhenFewerThan3CharsProvided()
155
$this->element->setSymbol('$');
158
public function testShouldRenderCurrencyTextBoxDijit()
160
$html = $this->element->render();
161
$this->assertContains('dojoType="dijit.form.CurrencyTextBox"', $html);
165
// Call Zend_Dojo_Form_Element_CurrencyTextBoxTest::main() if this source file is executed directly.
166
if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_CurrencyTextBoxTest::main") {
167
Zend_Dojo_Form_Element_CurrencyTextBoxTest::main();