Base for a static organization website

FirePhpToolbarHelperTest.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Toolbar Abstract Helper Test Case
  4. *
  5. * PHP 5
  6. *
  7. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  8. * Copyright (c) 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 (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  14. * @link http://cakephp.org CakePHP(tm) Project
  15. * @since DebugKit 0.1
  16. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  17. **/
  18. $path = CakePlugin::path('DebugKit');
  19. App::uses('View', 'View');
  20. App::uses('Controller', 'Controller');
  21. App::uses('CakeResponse', 'Network');
  22. App::uses('Router', 'Routing');
  23. App::uses('ToolbarHelper', 'DebugKit.View/Helper');
  24. App::uses('FirePhpToolbarHelper', 'DebugKit.View/Helper');
  25. require_once $path . 'Test' . DS . 'Case' . DS . 'TestFireCake.php';
  26. /**
  27. * Class FirePhpToolbarHelperTestCase
  28. *
  29. * @since DebugKit 0.1
  30. */
  31. class FirePhpToolbarHelperTestCase extends CakeTestCase {
  32. /**
  33. * setUp
  34. *
  35. * @return void
  36. **/
  37. public function setUp() {
  38. parent::setUp();
  39. Router::connect('/:controller/:action');
  40. Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
  41. Router::parse('/');
  42. $this->Controller = new Controller($this->getMock('CakeRequest'), new CakeResponse());
  43. $this->View = new View($this->Controller);
  44. $this->Toolbar = new ToolbarHelper($this->View, array('output' => 'DebugKit.FirePhpToolbar'));
  45. $this->Toolbar->FirePhpToolbar = new FirePhpToolbarHelper($this->View);
  46. $this->firecake = FireCake::getInstance('TestFireCake');
  47. TestFireCake::reset();
  48. }
  49. /**
  50. * Start test - switch view paths
  51. *
  52. * @return void
  53. **/
  54. public static function setupBeforeClass() {
  55. App::build(array(
  56. 'View' => array(
  57. CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'Test' . DS . 'test_app' . DS . 'View' . DS,
  58. APP . 'Plugin' . DS . 'DebugKit' . DS . 'View' . DS,
  59. CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'View' . DS
  60. )), true);
  61. }
  62. /**
  63. * End Test
  64. *
  65. * @return void
  66. */
  67. public static function tearDownAfterClass() {
  68. App::build();
  69. }
  70. /**
  71. * TearDown
  72. *
  73. * @return void
  74. */
  75. public function tearDown() {
  76. parent::tearDown();
  77. unset($this->Toolbar, $this->Controller);
  78. TestFireCake::reset();
  79. }
  80. /**
  81. * Test neat array (dump)creation
  82. *
  83. * @return void
  84. */
  85. public function testMakeNeatArray() {
  86. $this->Toolbar->makeNeatArray(array(1,2,3));
  87. $result = $this->firecake->sentHeaders;
  88. $this->assertTrue(isset($result['X-Wf-1-1-1-1']));
  89. $this->assertRegexp('/\[1,2,3\]/', $result['X-Wf-1-1-1-1']);
  90. }
  91. /**
  92. * Test afterlayout element rendering
  93. *
  94. * @return void
  95. */
  96. public function testAfterLayout() {
  97. $this->Controller->viewPath = 'Posts';
  98. $request = new CakeRequest('/posts/index');
  99. $request->addParams(Router::parse($request->url));
  100. $request->addPaths(array(
  101. 'webroot' => '/',
  102. 'base' => '/',
  103. 'here' => '/posts/index',
  104. ));
  105. $this->Controller->setRequest($request);
  106. $this->Controller->layout = 'default';
  107. $this->Controller->uses = null;
  108. $this->Controller->components = array('DebugKit.Toolbar');
  109. $this->Controller->constructClasses();
  110. $this->Controller->Components->trigger('startup', array($this->Controller));
  111. $this->Controller->Components->trigger('beforeRender', array($this->Controller));
  112. $result = $this->Controller->render();
  113. $this->assertNotRegExp('/debug-toolbar/', (string)$result);
  114. $result = $this->firecake->sentHeaders;
  115. $this->assertTrue(is_array($result));
  116. }
  117. /**
  118. * test starting a panel
  119. *
  120. * @return void
  121. **/
  122. public function testPanelStart() {
  123. $this->Toolbar->panelStart('My Panel', 'my_panel');
  124. $result = $this->firecake->sentHeaders;
  125. $this->assertPattern('/GROUP_START.+My Panel/', $result['X-Wf-1-1-1-1']);
  126. }
  127. /**
  128. * test ending a panel
  129. *
  130. * @return void
  131. **/
  132. public function testPanelEnd() {
  133. $this->Toolbar->panelEnd();
  134. $result = $this->firecake->sentHeaders;
  135. $this->assertPattern('/GROUP_END/', $result['X-Wf-1-1-1-1']);
  136. }
  137. }