/tests/Zend/Controller/Action/Helper/FlashMessengerTest.php

https://github.com/Exercise/zf2 · PHP · 121 lines · 58 code · 15 blank · 48 comment · 3 complexity · 88ce76cdb0d92195829ba1450e0591ac MD5 · raw file

  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-2010 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. * @namespace
  24. */
  25. namespace ZendTest\Controller\Action\Helper;
  26. /**
  27. * @category Zend
  28. * @package Zend_Controller
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Controller
  33. * @group Zend_Controller_Action
  34. * @group Zend_Controller_Action_Helper
  35. */
  36. class FlashMessengerTest extends \PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * @var Zend_Controller_Action
  40. */
  41. public $controller;
  42. /**
  43. * @var Zend_Controller_Front
  44. */
  45. public $front;
  46. /**
  47. * @var Zend_Controller_Action_Helper_FlashMessenger
  48. */
  49. public $helper;
  50. /**
  51. * @var Zend_Controller_Request_HTTP
  52. */
  53. public $request;
  54. /**
  55. * @var Zend_Controller_Response_Cli
  56. */
  57. public $response;
  58. public function setUp()
  59. {
  60. $savePath = ini_get('session.save_path');
  61. if (strpos($savePath, ';')) {
  62. $savePath = explode(';', $savePath);
  63. $savePath = array_pop($savePath);
  64. }
  65. if (empty($savePath)) {
  66. $this->markTestSkipped('Cannot test FlashMessenger due to unavailable session save path');
  67. }
  68. if (headers_sent()) {
  69. $this->markTestSkipped('Cannot test FlashMessenger: cannot start session because headers already sent');
  70. }
  71. \Zend\Session\Manager::start();
  72. $this->front = \Zend\Controller\Front::getInstance();
  73. $this->front->resetInstance();
  74. $this->front->setControllerDirectory(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . '_files');
  75. $this->front->returnResponse(true);
  76. $this->request = new \Zend\Controller\Request\Http();
  77. $this->request->setControllerName('helper-flash-messenger');
  78. $this->response = new \Zend\Controller\Response\Cli();
  79. $this->controller = new \HelperFlashMessengerController($this->request, $this->response, array());
  80. $this->helper = new \Zend\Controller\Action\Helper\FlashMessenger($this->controller);
  81. }
  82. public function testLoadFlashMessenger()
  83. {
  84. $this->markTestSkipped();
  85. $response = $this->front->dispatch($this->request);
  86. $this->assertEquals('Zend_Controller_Action_Helper_FlashMessenger123456', $response->getBody());
  87. }
  88. public function testClearMessages()
  89. {
  90. $this->markTestSkipped();
  91. $this->helper->addMessage('foo');
  92. $this->helper->addMessage('bar');
  93. $this->assertTrue($this->helper->hasMessages());
  94. $this->assertEquals(2, count($this->helper));
  95. $this->helper->clearMessages();
  96. $this->assertFalse($this->helper->hasMessages());
  97. $this->assertEquals(0, count($this->helper));
  98. }
  99. public function testDirectProxiesToAddMessage()
  100. {
  101. $this->markTestSkipped();
  102. $this->helper->direct('foo');
  103. $this->assertTrue($this->helper->hasMessages());
  104. $this->assertEquals(1, count($this->helper));
  105. }
  106. }