PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/cases/helpers/monitor.test.php

http://github.com/joebeeson/sassy
PHP | 188 lines | 85 code | 30 blank | 73 comment | 6 complexity | fb392e2a287c7d021f6069980bc473b6 MD5 | raw file
  1. <?php
  2. // We'll need the helper for testing...
  3. App::import('Helper', 'Sassy.Monitor');
  4. /**
  5. * MonitorHelperTest
  6. * Tests the MonitorHelper of the Sassy plugin
  7. * @author Joe Beeson <jbeeson@gmail.com>
  8. */
  9. class MonitorHelperText extends CakeTestCase {
  10. /**
  11. * Executed at the start of each test
  12. * @return null
  13. * @access public
  14. */
  15. public function startTest() {
  16. $this->Helper = new MonitorHelperProxy();
  17. }
  18. /**
  19. * Executed at the end of each test.
  20. * @return null
  21. * @access public
  22. */
  23. public function endTest() {
  24. unset($this->Helper);
  25. ClassRegistry::flush();
  26. }
  27. /**
  28. * Tests the _getMonitorFolders method of the helper
  29. * @return null
  30. * @access public
  31. */
  32. public function testGetMonitorFolders() {
  33. if (!is_null(Configure::read(MonitorHelper::RECOMPILE_FOLDERS))) {
  34. Configure::delete(MonitorHelper::RECOMPILE_FOLDERS);
  35. }
  36. // We default to the CSS folder if nothing is set...
  37. $this->assertIdentical(
  38. $this->Helper->_getMonitorFolders(),
  39. array(
  40. CSS => CSS
  41. )
  42. );
  43. // Lets write some new folders to the configuration...
  44. Configure::write(MonitorHelper::RECOMPILE_FOLDERS, array(
  45. '/from/folder' => '/to/folder'
  46. ));
  47. // ... confirm it worked correctly...
  48. $this->assertIdentical(
  49. $this->Helper->_getMonitorFolders(),
  50. array(
  51. // Notice how we added the DS to it
  52. '/from/folder' . DS => '/to/folder' . DS
  53. )
  54. );
  55. }
  56. /**
  57. * Tests the _recompilePercentage method of the helper
  58. * @return null
  59. * @access public
  60. */
  61. public function testRecompilePercentage() {
  62. if (!is_null(Configure::read('Sassy.Recompile.Percentage'))) {
  63. // We don't want this set, lets remove it...
  64. Configure::delete('Sassy.Recompile.Percentage');
  65. }
  66. // This should default to the helper constant
  67. $this->assertIdentical(
  68. $this->Helper->_recompilePercentage(),
  69. MonitorHelper::RECOMPILE_PERCENTAGE_DEFAULT
  70. );
  71. // Now lets set it and make sure it changes...
  72. Configure::write('Sassy.Recompile.Percentage', 11);
  73. $this->assertIdentical(
  74. $this->Helper->_recompilePercentage(),
  75. 11
  76. );
  77. }
  78. /**
  79. * Tests the _recompileParameter method of the helper
  80. * @return null
  81. * @access public
  82. */
  83. public function testRecompileParameter() {
  84. if (!is_null(Configure::read('Sassy.Recompile.Parameter'))) {
  85. // We don't want this set, lets remove it...
  86. Configure::delete('Sassy.Recompile.Parameter');
  87. }
  88. // This should default to the helper constant
  89. $this->assertIdentical(
  90. $this->Helper->_recompileParameter(),
  91. MonitorHelper::RECOMPILE_PARAMETER_DEFAULT
  92. );
  93. // Now lets set it and make sure it changes...
  94. Configure::write('Sassy.Recompile.Parameter', 'testing');
  95. $this->assertIdentical(
  96. $this->Helper->_recompileParameter(),
  97. 'testing'
  98. );
  99. }
  100. /**
  101. * Tests the _hasRecompilePercentage method of the helper
  102. * @return null
  103. * @access public
  104. */
  105. public function testHasRecompilePercentage() {
  106. if (!is_null(Configure::read('Sassy.Recompile.Percentage'))) {
  107. // We don't want this set, lets remove it...
  108. Configure::delete('Sassy.Recompile.Percentage');
  109. }
  110. // There should be no recompile percentage set
  111. $this->assertFalse($this->Helper->_hasRecompilePercentage());
  112. // Now lets set it...
  113. Configure::write('Sassy.Recompile.Percentage', 10);
  114. // ... now lets confirm this works correctly...
  115. $this->assertTrue($this->Helper->_hasRecompilePercentage());
  116. }
  117. /**
  118. * Tests the _hasRecompileParameter method of the helper
  119. * @return null
  120. * @access public
  121. */
  122. public function testHasRecompileParameter() {
  123. if (!is_null(Configure::read('Sassy.Recompile.Parameter'))) {
  124. // We don't want this set, lets remove it...
  125. Configure::delete('Sassy.Recompile.Parameter');
  126. }
  127. // There should be no recompile parameter set
  128. $this->assertFalse($this->Helper->_hasRecompileParameter());
  129. // Now lets set it...
  130. Configure::write('Sassy.Recompile.Parameter', 'sassy');
  131. // ... now lets confirm this works correctly...
  132. $this->assertTrue($this->Helper->_hasRecompileParameter());
  133. }
  134. }
  135. /**
  136. * MonitorHelperProxy
  137. * Acts as a proxy between our test and the MonitorHelper to provide access
  138. * to various protected methods and variables.
  139. * @author Joe Beeson <jbeeson@gmail.com>
  140. */
  141. class MonitorHelperProxy extends MonitorHelper {
  142. /**
  143. * Catches failed method calls and "reroutes" them to the class. This
  144. * will allow us to get around the protected declarations.
  145. * @param string $method
  146. * @param array $arguments
  147. * @return mixed
  148. * @access public
  149. */
  150. public function __call($method, $arguments) {
  151. if (method_exists($this, $method)) {
  152. return call_user_func_array(
  153. array($this, $method),
  154. $arguments
  155. );
  156. }
  157. }
  158. }