/
NumberHelperTest.php
107 lines (94 loc) · 2.63 KB
/
NumberHelperTest.php
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
<?php
/**
* NumberHelperTest file
*
* PHP 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
* @package Cake.Test.Case.View.Helper
* @since CakePHP(tm) v 1.2.0.4206
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::uses('View', 'View');
App::uses('NumberHelper', 'View/Helper');
/**
* NumberHelperTestObject class
*/
class NumberHelperTestObject extends NumberHelper {
public function attach(CakeNumberMock $cakeNumber) {
$this->_engine = $cakeNumber;
}
public function engine() {
return $this->_engine;
}
}
/**
* CakeNumberMock class
*/
class CakeNumberMock {
}
/**
* NumberHelperTest class
*
* @package Cake.Test.Case.View.Helper
*/
class NumberHelperTest extends CakeTestCase {
/**
* setUp method
*
* @return void
*/
public function setUp() {
parent::setUp();
$this->View = new View(null);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown() {
parent::tearDown();
unset($this->View);
}
/**
* test CakeNumber class methods are called correctly
*/
public function testNumberHelperProxyMethodCalls() {
$methods = array(
'precision', 'toReadableSize', 'toPercentage', 'format',
'currency', 'addFormat',
);
$CakeNumber = $this->getMock('CakeNumberMock', $methods);
$Number = new NumberHelperTestObject($this->View, array('engine' => 'CakeNumberMock'));
$Number->attach($CakeNumber);
foreach ($methods as $method) {
$CakeNumber->expects($this->at(0))->method($method);
$Number->{$method}('who', 'what', 'when', 'where', 'how');
}
}
/**
* test engine override
*/
public function testEngineOverride() {
App::build(array(
'Utility' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Utility' . DS)
), App::REGISTER);
$Number = new NumberHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
$this->assertInstanceOf('TestAppEngine', $Number->engine());
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
));
CakePlugin::load('TestPlugin');
$Number = new NumberHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
$this->assertInstanceOf('TestPluginEngine', $Number->engine());
CakePlugin::unload('TestPlugin');
}
}