| 13532 |
anikendra |
1 |
<?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 |
public function testNumberHelperProxyMethodCalls() {
|
|
|
74 |
$methods = array(
|
|
|
75 |
'precision', 'toReadableSize', 'toPercentage', 'format',
|
|
|
76 |
'currency', 'addFormat',
|
|
|
77 |
);
|
|
|
78 |
$CakeNumber = $this->getMock('CakeNumberMock', $methods);
|
|
|
79 |
$Number = new NumberHelperTestObject($this->View, array('engine' => 'CakeNumberMock'));
|
|
|
80 |
$Number->attach($CakeNumber);
|
|
|
81 |
foreach ($methods as $method) {
|
|
|
82 |
$CakeNumber->expects($this->at(0))->method($method);
|
|
|
83 |
$Number->{$method}('who', 'what', 'when', 'where', 'how');
|
|
|
84 |
}
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* test engine override
|
|
|
89 |
*/
|
|
|
90 |
public function testEngineOverride() {
|
|
|
91 |
App::build(array(
|
|
|
92 |
'Utility' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Utility' . DS)
|
|
|
93 |
), App::REGISTER);
|
|
|
94 |
$Number = new NumberHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
|
|
|
95 |
$this->assertInstanceOf('TestAppEngine', $Number->engine());
|
|
|
96 |
|
|
|
97 |
App::build(array(
|
|
|
98 |
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
|
|
|
99 |
));
|
|
|
100 |
CakePlugin::load('TestPlugin');
|
|
|
101 |
$Number = new NumberHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
|
|
|
102 |
$this->assertInstanceOf('TestPluginEngine', $Number->engine());
|
|
|
103 |
CakePlugin::unload('TestPlugin');
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
}
|