2012-02-06 10:12:01 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* NumberHelperTest file
|
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2013-02-08 11:59:49 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-02-06 10:12:01 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2012-02-06 10:12:01 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
2013-02-08 11:59:49 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2012-02-06 10:12:01 +00:00
|
|
|
* @package Cake.Test.Case.View.Helper
|
|
|
|
* @since CakePHP(tm) v 1.2.0.4206
|
2013-05-30 22:11:14 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
2012-02-06 10:12:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
App::uses('View', 'View');
|
|
|
|
App::uses('NumberHelper', 'View/Helper');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NumberHelperTestObject class
|
|
|
|
*/
|
|
|
|
class NumberHelperTestObject extends NumberHelper {
|
|
|
|
|
2012-02-13 02:13:39 +00:00
|
|
|
public function attach(CakeNumberMock $cakeNumber) {
|
2012-02-14 16:14:18 +00:00
|
|
|
$this->_engine = $cakeNumber;
|
2012-02-06 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 15:56:48 +00:00
|
|
|
public function engine() {
|
2012-02-14 16:14:18 +00:00
|
|
|
return $this->_engine;
|
2012-02-14 15:56:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
2012-02-13 02:13:39 +00:00
|
|
|
/**
|
|
|
|
* CakeNumberMock class
|
|
|
|
*/
|
|
|
|
class CakeNumberMock {
|
|
|
|
}
|
|
|
|
|
2012-02-06 10:12:01 +00:00
|
|
|
/**
|
|
|
|
* NumberHelperTest class
|
|
|
|
*
|
|
|
|
* @package Cake.Test.Case.View.Helper
|
|
|
|
*/
|
|
|
|
class NumberHelperTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
2012-02-13 02:13:39 +00:00
|
|
|
$this->View = new View(null);
|
2012-02-06 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
2012-02-13 02:13:39 +00:00
|
|
|
unset($this->View);
|
2012-02-06 10:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test CakeNumber class methods are called correctly
|
2014-04-02 01:02:37 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2012-02-06 10:12:01 +00:00
|
|
|
*/
|
|
|
|
public function testNumberHelperProxyMethodCalls() {
|
|
|
|
$methods = array(
|
|
|
|
'precision', 'toReadableSize', 'toPercentage', 'format',
|
|
|
|
'currency', 'addFormat',
|
|
|
|
);
|
2012-02-13 02:13:39 +00:00
|
|
|
$CakeNumber = $this->getMock('CakeNumberMock', $methods);
|
|
|
|
$Number = new NumberHelperTestObject($this->View, array('engine' => 'CakeNumberMock'));
|
|
|
|
$Number->attach($CakeNumber);
|
2012-02-06 10:12:01 +00:00
|
|
|
foreach ($methods as $method) {
|
2012-02-13 02:13:39 +00:00
|
|
|
$CakeNumber->expects($this->at(0))->method($method);
|
|
|
|
$Number->{$method}('who', 'what', 'when', 'where', 'how');
|
2012-02-06 10:12:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 15:56:48 +00:00
|
|
|
/**
|
|
|
|
* test engine override
|
2014-04-02 01:02:37 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2012-02-14 15:56:48 +00:00
|
|
|
*/
|
|
|
|
public function testEngineOverride() {
|
|
|
|
App::build(array(
|
|
|
|
'Utility' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Utility' . DS)
|
2012-02-18 12:04:54 +00:00
|
|
|
), App::REGISTER);
|
2012-02-14 15:56:48 +00:00
|
|
|
$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)
|
2012-02-18 12:04:54 +00:00
|
|
|
));
|
2012-02-14 15:56:48 +00:00
|
|
|
CakePlugin::load('TestPlugin');
|
|
|
|
$Number = new NumberHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
|
|
|
|
$this->assertInstanceOf('TestPluginEngine', $Number->engine());
|
|
|
|
CakePlugin::unload('TestPlugin');
|
|
|
|
}
|
|
|
|
|
2012-02-06 10:12:01 +00:00
|
|
|
}
|