~clinton-collins/familyproject/trunk

« back to all changes in this revision

Viewing changes to ZendFramework/tests/Zend/Dojo/Form/Element/CurrencyTextBoxTest.php

  • Committer: Clinton Collins
  • Date: 2009-06-26 19:54:58 UTC
  • Revision ID: clinton.collins@gmail.com-20090626195458-5ebba0qcvo15xlpy
Initial Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
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.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Dojo
 
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 $
 
21
 */
 
22
 
 
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");
 
26
}
 
27
 
 
28
require_once dirname(__FILE__) . '/../../../../TestHelper.php';
 
29
 
 
30
/** Zend_Dojo_Form_Element_CurrencyTextBox */
 
31
require_once 'Zend/Dojo/Form/Element/CurrencyTextBox.php';
 
32
 
 
33
/** Zend_View */
 
34
require_once 'Zend/View.php';
 
35
 
 
36
/** Zend_Registry */
 
37
require_once 'Zend/Registry.php';
 
38
 
 
39
/** Zend_Dojo_View_Helper_Dojo */
 
40
require_once 'Zend/Dojo/View/Helper/Dojo.php';
 
41
 
 
42
/**
 
43
 * Test class for Zend_Dojo_Form_Element_Dijit.
 
44
 *
 
45
 * @package    Zend_Dojo
 
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
 
49
 */
 
50
class Zend_Dojo_Form_Element_CurrencyTextBoxTest extends PHPUnit_Framework_TestCase 
 
51
{
 
52
    /**
 
53
     * Runs the test methods of this class.
 
54
     *
 
55
     * @return void
 
56
     */
 
57
    public static function main()
 
58
    {
 
59
        $suite  = new PHPUnit_Framework_TestSuite("Zend_Dojo_Form_Element_CurrencyTextBoxTest");
 
60
        $result = PHPUnit_TextUI_TestRunner::run($suite);
 
61
    }
 
62
 
 
63
    /**
 
64
     * Sets up the fixture, for example, open a network connection.
 
65
     * This method is called before a test is executed.
 
66
     *
 
67
     * @return void
 
68
     */
 
69
    public function setUp()
 
70
    {
 
71
        Zend_Registry::_unsetInstance();
 
72
        Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
 
73
 
 
74
        $this->view    = $this->getView();
 
75
        $this->element = $this->getElement();
 
76
        $this->element->setView($this->view);
 
77
    }
 
78
 
 
79
    /**
 
80
     * Tears down the fixture, for example, close a network connection.
 
81
     * This method is called after a test is executed.
 
82
     *
 
83
     * @return void
 
84
     */
 
85
    public function tearDown()
 
86
    {
 
87
    }
 
88
 
 
89
    public function getView()
 
90
    {
 
91
        require_once 'Zend/View.php';
 
92
        $view = new Zend_View();
 
93
        $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
 
94
        return $view;
 
95
    }
 
96
 
 
97
    public function getElement()
 
98
    {
 
99
        $element = new Zend_Dojo_Form_Element_CurrencyTextBox(
 
100
            'foo',
 
101
            array(
 
102
                'value' => 'some text',
 
103
                'label' => 'CurrencyTextBox',
 
104
                'class' => 'someclass',
 
105
                'style' => 'width: 100px;',
 
106
            )
 
107
        );
 
108
        return $element;
 
109
    }
 
110
 
 
111
    public function testShouldExtendNumberTextBox()
 
112
    {
 
113
        $this->assertTrue($this->element instanceof Zend_Dojo_Form_Element_NumberTextBox);
 
114
    }
 
115
 
 
116
    public function testCurrencyAccessorsShouldProxyToDijitParams()
 
117
    {
 
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'));
 
123
    }
 
124
 
 
125
    public function testFractionalAccessorsShouldProxyToConstraints()
 
126
    {
 
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']);
 
132
    }
 
133
 
 
134
    public function testSymbolAccessorsShouldProxyToConstraints()
 
135
    {
 
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'));
 
141
    }
 
142
 
 
143
    public function testSymbolMutatorShouldCastToStringAndUppercaseAndLimitTo3Chars()
 
144
    {
 
145
        $this->element->setSymbol('usdollar');
 
146
        $this->assertEquals('USD', $this->element->getSymbol());
 
147
        $this->assertEquals('USD', $this->element->getConstraint('symbol'));
 
148
    }
 
149
 
 
150
    /**
 
151
     * @expectedException Zend_Form_Element_Exception
 
152
     */
 
153
    public function testSymbolMutatorShouldRaiseExceptionWhenFewerThan3CharsProvided()
 
154
    {
 
155
        $this->element->setSymbol('$');
 
156
    }
 
157
 
 
158
    public function testShouldRenderCurrencyTextBoxDijit()
 
159
    {
 
160
        $html = $this->element->render();
 
161
        $this->assertContains('dojoType="dijit.form.CurrencyTextBox"', $html);
 
162
    }
 
163
}
 
164
 
 
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();
 
168
}