NumberHelperTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. * @since CakePHP(tm) v 1.2.0.4206
  15. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  16. */
  17. namespace Cake\Test\TestCase\View\Helper;
  18. use Cake\Core\App;
  19. use Cake\Core\Configure;
  20. use Cake\Core\Plugin;
  21. use Cake\TestSuite\TestCase;
  22. use Cake\View\Helper\NumberHelper;
  23. use Cake\View\View;
  24. /**
  25. * NumberHelperTestObject class
  26. */
  27. class NumberHelperTestObject extends NumberHelper {
  28. public function attach(NumberMock $cakeNumber) {
  29. $this->_engine = $cakeNumber;
  30. }
  31. public function engine() {
  32. return $this->_engine;
  33. }
  34. }
  35. /**
  36. * NumberMock class
  37. */
  38. class NumberMock {
  39. }
  40. /**
  41. * NumberHelperTest class
  42. *
  43. */
  44. class NumberHelperTest extends TestCase {
  45. /**
  46. * setUp method
  47. *
  48. * @return void
  49. */
  50. public function setUp() {
  51. parent::setUp();
  52. $this->View = new View(null);
  53. $this->_appNamespace = Configure::read('App.namespace');
  54. Configure::write('App.namespace', 'TestApp');
  55. }
  56. /**
  57. * tearDown method
  58. *
  59. * @return void
  60. */
  61. public function tearDown() {
  62. parent::tearDown();
  63. Configure::write('App.namespace', $this->_appNamespace);
  64. unset($this->View);
  65. }
  66. /**
  67. * test CakeNumber class methods are called correctly
  68. */
  69. public function testNumberHelperProxyMethodCalls() {
  70. $methods = array(
  71. 'precision', 'toReadableSize', 'toPercentage', 'format',
  72. 'currency', 'addFormat',
  73. );
  74. $CakeNumber = $this->getMock(__NAMESPACE__ . '\NumberMock', $methods);
  75. $Number = new NumberHelperTestObject($this->View, array('engine' => __NAMESPACE__ . '\NumberMock'));
  76. $Number->attach($CakeNumber);
  77. foreach ($methods as $method) {
  78. $CakeNumber->expects($this->at(0))->method($method);
  79. $Number->{$method}('who', 'what', 'when', 'where', 'how');
  80. }
  81. }
  82. /**
  83. * test engine override
  84. */
  85. public function testEngineOverride() {
  86. $Number = new NumberHelperTestObject($this->View, array('engine' => 'TestAppEngine'));
  87. $this->assertInstanceOf('TestApp\Utility\TestAppEngine', $Number->engine());
  88. Plugin::load('TestPlugin');
  89. $Number = new NumberHelperTestObject($this->View, array('engine' => 'TestPlugin.TestPluginEngine'));
  90. $this->assertInstanceOf('TestPlugin\Utility\TestPluginEngine', $Number->engine());
  91. Plugin::unload('TestPlugin');
  92. }
  93. }