統計
| ブランチ: | リビジョン:

pictcode / lib / Cake / Test / Case / View / Helper / NumberHelperTest.php @ 635eef61

履歴 | 表示 | アノテート | ダウンロード (2.714 KB)

1 635eef61 spyder1211
<?php
2
/**
3
 * NumberHelperTest file
4
 *
5
 * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
6
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
7
 *
8
 * Licensed under The MIT License
9
 * For full copyright and license information, please see the LICENSE.txt
10
 * Redistributions of files must retain the above copyright notice
11
 *
12
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
13
 * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
14
 * @package       Cake.Test.Case.View.Helper
15
 * @since         CakePHP(tm) v 1.2.0.4206
16
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17
 */
18
19
App::uses('View', 'View');
20
App::uses('NumberHelper', 'View/Helper');
21
22
/**
23
 * NumberHelperTestObject class
24
 */
25
class NumberHelperTestObject extends NumberHelper {
26
27
        public function attach(CakeNumberMock $cakeNumber) {
28
                $this->_engine = $cakeNumber;
29
        }
30
31
        public function engine() {
32
                return $this->_engine;
33
        }
34
35
}
36
37
/**
38
 * CakeNumberMock class
39
 */
40
class CakeNumberMock {
41
}
42
43
/**
44
 * NumberHelperTest class
45
 *
46
 * @package       Cake.Test.Case.View.Helper
47
 */
48
class NumberHelperTest extends CakeTestCase {
49
50
/**
51
 * setUp method
52
 *
53
 * @return void
54
 */
55
        public function setUp() {
56
                parent::setUp();
57
                $this->View = new View(null);
58
        }
59
60
/**
61
 * tearDown method
62
 *
63
 * @return void
64
 */
65
        public function tearDown() {
66
                parent::tearDown();
67
                unset($this->View);
68
        }
69
70
/**
71
 * test CakeNumber class methods are called correctly
72
 *
73
 * @return void
74
 */
75
        public function testNumberHelperProxyMethodCalls() {
76
                $methods = array(
77
                        'precision', 'toReadableSize', 'toPercentage', 'format',
78
                        'currency', 'addFormat',
79
                        );
80
                $CakeNumber = $this->getMock('CakeNumberMock', $methods);
81
                $Number = new NumberHelperTestObject($this->View, array('engine' => 'CakeNumberMock'));
82
                $Number->attach($CakeNumber);
83
                foreach ($methods as $method) {
84
                        $CakeNumber->expects($this->at(0))->method($method);
85
                        $Number->{$method}('who', 'what', 'when', 'where', 'how');
86
                }
87
        }
88
89
/**
90
 * test engine override
91
 *
92
 * @return void
93
 */
94
        public function testEngineOverride() {
95
                App::build(array(
96
                        'Utility' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Utility' . DS)
97
                ), App::REGISTER);
98
                $Number = new NumberHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
99
                $this->assertInstanceOf('TestAppEngine', $Number->engine());
100
101
                App::build(array(
102
                        'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
103
                ));
104
                CakePlugin::load('TestPlugin');
105
                $Number = new NumberHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
106
                $this->assertInstanceOf('TestPluginEngine', $Number->engine());
107
                CakePlugin::unload('TestPlugin');
108
        }
109
110
}