FlashMessengerTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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_Controller
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  26. // Call Zend_Controller_Action_Helper_FlashMessengerTest::main() if this source file is executed directly.
  27. if (!defined("PHPUnit_MAIN_METHOD")) {
  28. define("PHPUnit_MAIN_METHOD", "Zend_Controller_Action_Helper_FlashMessengerTest::main");
  29. }
  30. require_once 'Zend/Controller/Front.php';
  31. require_once 'Zend/Controller/Request/Http.php';
  32. require_once 'Zend/Controller/Response/Cli.php';
  33. require_once 'Zend/Controller/Action/HelperBroker.php';
  34. require_once 'Zend/Controller/Action/Helper/FlashMessenger.php';
  35. require_once 'Zend/Session.php';
  36. require_once dirname(dirname(dirname(__FILE__))) . '/_files/HelperFlashMessengerController.php';
  37. /**
  38. * @category Zend
  39. * @package Zend_Controller
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. * @group Zend_Controller
  44. * @group Zend_Controller_Action
  45. * @group Zend_Controller_Action_Helper
  46. */
  47. class Zend_Controller_Action_Helper_FlashMessengerTest extends PHPUnit_Framework_TestCase
  48. {
  49. /**
  50. * @var Zend_Controller_Action
  51. */
  52. public $controller;
  53. /**
  54. * @var Zend_Controller_Front
  55. */
  56. public $front;
  57. /**
  58. * @var Zend_Controller_Action_Helper_FlashMessenger
  59. */
  60. public $helper;
  61. /**
  62. * @var Zend_Controller_Request_Http
  63. */
  64. public $request;
  65. /**
  66. * @var Zend_Controller_Response_Cli
  67. */
  68. public $response;
  69. /**
  70. * Runs the test methods of this class.
  71. *
  72. * @access public
  73. * @static
  74. */
  75. public static function main()
  76. {
  77. $suite = new PHPUnit_Framework_TestSuite("Zend_Controller_Action_Helper_FlashMessengerTest");
  78. $result = PHPUnit_TextUI_TestRunner::run($suite);
  79. }
  80. public function setUp()
  81. {
  82. $savePath = ini_get('session.save_path');
  83. if (strpos($savePath, ';')) {
  84. $savePath = explode(';', $savePath);
  85. $savePath = array_pop($savePath);
  86. }
  87. if (empty($savePath)) {
  88. $this->markTestSkipped('Cannot test FlashMessenger due to unavailable session save path');
  89. }
  90. if (headers_sent()) {
  91. $this->markTestSkipped('Cannot test FlashMessenger: cannot start session because headers already sent');
  92. }
  93. Zend_Session::start();
  94. $this->front = Zend_Controller_Front::getInstance();
  95. $this->front->resetInstance();
  96. $this->front->setControllerDirectory(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . '_files');
  97. $this->front->returnResponse(true);
  98. $this->request = new Zend_Controller_Request_Http();
  99. $this->request->setControllerName('helper-flash-messenger');
  100. $this->response = new Zend_Controller_Response_Cli();
  101. $this->controller = new HelperFlashMessengerController($this->request, $this->response, array());
  102. $this->helper = new Zend_Controller_Action_Helper_FlashMessenger($this->controller);
  103. }
  104. public function testLoadFlashMessenger()
  105. {
  106. $this->markTestSkipped();
  107. $response = $this->front->dispatch($this->request);
  108. $this->assertEquals('Zend_Controller_Action_Helper_FlashMessenger123456', $response->getBody());
  109. }
  110. public function testClearMessages()
  111. {
  112. $this->markTestSkipped();
  113. $this->helper->addMessage('foo');
  114. $this->helper->addMessage('bar');
  115. $this->assertTrue($this->helper->hasMessages());
  116. $this->assertEquals(2, count($this->helper));
  117. $this->helper->clearMessages();
  118. $this->assertFalse($this->helper->hasMessages());
  119. $this->assertEquals(0, count($this->helper));
  120. }
  121. public function testDirectProxiesToAddMessage()
  122. {
  123. $this->markTestSkipped();
  124. $this->helper->direct('foo');
  125. $this->assertTrue($this->helper->hasMessages());
  126. $this->assertEquals(1, count($this->helper));
  127. }
  128. }
  129. // Call Zend_Controller_Action_Helper_FlashMessengerTest::main() if this source file is executed directly.
  130. if (PHPUnit_MAIN_METHOD == "Zend_Controller_Action_Helper_FlashMessengerTest::main") {
  131. Zend_Controller_Action_Helper_FlashMessengerTest::main();
  132. }