/lib/Cake/Test/Case/View/Helper/NumberHelperTest.php

https://bitbucket.org/floresj/notetime · PHP · 107 lines · 50 code · 13 blank · 44 comment · 0 complexity · 12bca51c9647dda584e2d3c3b909139f MD5 · raw file

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