PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/trunk/tests/Zend/Layout/PluginTest.php

http://firephp.googlecode.com/
PHP | 246 lines | 155 code | 36 blank | 55 comment | 5 complexity | 95ae3e1c38f40ee79ba59cf147ed1dec MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Layout
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: PluginTest.php 23772 2011-02-28 21:35:29Z ralph $
  21. */
  22. // Call Zend_LayoutTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Layout_PluginTest::main");
  25. }
  26. require_once 'Zend/Layout/Controller/Plugin/Layout.php';
  27. require_once 'Zend/Layout.php';
  28. require_once 'Zend/Controller/Front.php';
  29. require_once 'Zend/Controller/Action/HelperBroker.php';
  30. require_once 'Zend/Controller/Request/Simple.php';
  31. require_once 'Zend/Controller/Response/Cli.php';
  32. /**
  33. * Test class for Zend_Layout_Controller_Plugin_Layout
  34. *
  35. * @category Zend
  36. * @package Zend_Layout
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. * @group Zend_Layout
  41. */
  42. class Zend_Layout_PluginTest extends PHPUnit_Framework_TestCase
  43. {
  44. /**
  45. * Runs the test methods of this class.
  46. *
  47. * @return void
  48. */
  49. public static function main()
  50. {
  51. $suite = new PHPUnit_Framework_TestSuite("Zend_Layout_PluginTest");
  52. $result = PHPUnit_TextUI_TestRunner::run($suite);
  53. }
  54. /**
  55. * Sets up the fixture, for example, open a network connection.
  56. * This method is called before a test is executed.
  57. *
  58. * @return void
  59. */
  60. public function setUp()
  61. {
  62. Zend_Controller_Front::getInstance()->resetInstance();
  63. Zend_Layout_PluginTest_Layout::resetMvcInstance();
  64. if (Zend_Controller_Action_HelperBroker::hasHelper('Layout')) {
  65. Zend_Controller_Action_HelperBroker::removeHelper('Layout');
  66. }
  67. if (Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) {
  68. Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
  69. }
  70. }
  71. /**
  72. * Tears down the fixture, for example, close a network connection.
  73. * This method is called after a test is executed.
  74. *
  75. * @return void
  76. */
  77. public function tearDown()
  78. {
  79. Zend_Layout::resetMvcInstance();
  80. }
  81. public function testConstructorWithLayoutObject()
  82. {
  83. $layout = new Zend_Layout(array('mvcEnabled' => false));
  84. $plugin = new Zend_Layout_Controller_Plugin_Layout($layout);
  85. $this->assertSame($layout, $plugin->getLayout());
  86. }
  87. public function testGetLayoutReturnsNullWithNoLayoutPresent()
  88. {
  89. $plugin = new Zend_Layout_Controller_Plugin_Layout();
  90. $this->assertNull($plugin->getLayout());
  91. }
  92. public function testLayoutAccessorsWork()
  93. {
  94. $plugin = new Zend_Layout_Controller_Plugin_Layout();
  95. $this->assertNull($plugin->getLayout());
  96. $layout = new Zend_Layout(array('mvcEnabled' => false));
  97. $plugin->setlayout($layout);
  98. $this->assertSame($layout, $plugin->getLayout());
  99. }
  100. public function testGetLayoutReturnsLayoutObjectWhenPulledFromPluginBroker()
  101. {
  102. $layout = Zend_Layout::startMvc();
  103. $front = Zend_Controller_Front::getInstance();
  104. $this->assertTrue($front->hasPlugin('Zend_Layout_Controller_Plugin_Layout'));
  105. $plugin = $front->getPlugin('Zend_Layout_Controller_Plugin_Layout');
  106. $this->assertSame($layout, $plugin->getLayout());
  107. }
  108. public function testPostDispatchRendersLayout()
  109. {
  110. $front = Zend_Controller_Front::getInstance();
  111. $request = new Zend_Controller_Request_Simple();
  112. $response = new Zend_Controller_Response_Cli();
  113. $request->setDispatched(true);
  114. $response->setBody('Application content');
  115. $front->setRequest($request)
  116. ->setResponse($response);
  117. $layout = Zend_Layout::startMvc();
  118. $layout->setLayoutPath(dirname(__FILE__) . '/_files/layouts')
  119. ->setLayout('plugin.phtml')
  120. ->disableInflector();
  121. $helper = Zend_Controller_Action_HelperBroker::getStaticHelper('layout');
  122. $plugin = $front->getPlugin('Zend_Layout_Controller_Plugin_Layout');
  123. $plugin->setResponse($response);
  124. $helper->postDispatch();
  125. $plugin->postDispatch($request);
  126. $body = $response->getBody();
  127. $this->assertContains('Application content', $body, $body);
  128. $this->assertContains('Site Layout', $body, $body);
  129. }
  130. public function testPostDispatchDoesNotRenderLayoutWhenForwardDetected()
  131. {
  132. $front = Zend_Controller_Front::getInstance();
  133. $request = new Zend_Controller_Request_Simple();
  134. $response = new Zend_Controller_Response_Cli();
  135. $request->setDispatched(false);
  136. $response->setBody('Application content');
  137. $front->setRequest($request)
  138. ->setResponse($response);
  139. $layout = Zend_Layout::startMvc();
  140. $layout->setLayoutPath(dirname(__FILE__) . '/_files/layouts')
  141. ->setLayout('plugin.phtml')
  142. ->disableInflector();
  143. $plugin = $front->getPlugin('Zend_Layout_Controller_Plugin_Layout');
  144. $plugin->setResponse($response);
  145. $plugin->postDispatch($request);
  146. $body = $response->getBody();
  147. $this->assertContains('Application content', $body);
  148. $this->assertNotContains('Site Layout', $body);
  149. }
  150. public function testPostDispatchDoesNotRenderLayoutWhenLayoutDisabled()
  151. {
  152. $front = Zend_Controller_Front::getInstance();
  153. $request = new Zend_Controller_Request_Simple();
  154. $response = new Zend_Controller_Response_Cli();
  155. $request->setDispatched(true);
  156. $response->setBody('Application content');
  157. $front->setRequest($request)
  158. ->setResponse($response);
  159. $layout = Zend_Layout::startMvc();
  160. $layout->setLayoutPath(dirname(__FILE__) . '/_files/layouts')
  161. ->setLayout('plugin.phtml')
  162. ->disableInflector()
  163. ->disableLayout();
  164. $plugin = $front->getPlugin('Zend_Layout_Controller_Plugin_Layout');
  165. $plugin->setResponse($response);
  166. $plugin->postDispatch($request);
  167. $body = $response->getBody();
  168. $this->assertContains('Application content', $body);
  169. $this->assertNotContains('Site Layout', $body);
  170. }
  171. /**
  172. * @group ZF-8041
  173. */
  174. public function testPostDispatchDoesNotRenderLayoutWhenResponseRedirected()
  175. {
  176. $front = Zend_Controller_Front::getInstance();
  177. $request = new Zend_Controller_Request_Simple();
  178. $response = new Zend_Controller_Response_Cli();
  179. $request->setDispatched(true);
  180. $response->setHttpResponseCode(302);
  181. $response->setBody('Application content');
  182. $front->setRequest($request)
  183. ->setResponse($response);
  184. $layout = Zend_Layout::startMvc();
  185. $layout->setLayoutPath(dirname(__FILE__) . '/_files/layouts')
  186. ->setLayout('plugin.phtml')
  187. ->setMvcSuccessfulActionOnly(false)
  188. ->disableInflector();
  189. $plugin = $front->getPlugin('Zend_Layout_Controller_Plugin_Layout');
  190. $plugin->setResponse($response);
  191. $plugin->postDispatch($request);
  192. $body = $response->getBody();
  193. $this->assertContains('Application content', $body);
  194. $this->assertNotContains('Site Layout', $body);
  195. }
  196. }
  197. /**
  198. * Zend_Layout extension to allow resetting MVC instance
  199. */
  200. class Zend_Layout_PluginTest_Layout extends Zend_Layout
  201. {
  202. public static function resetMvcInstance()
  203. {
  204. self::$_mvcInstance = null;
  205. }
  206. }
  207. // Call Zend_Layout_PluginTest::main() if this source file is executed directly.
  208. if (PHPUnit_MAIN_METHOD == "Zend_Layout_PluginTest::main") {
  209. Zend_Layout_PluginTest::main();
  210. }