FlashMessengerTest.php 4.8 KB

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