SessionTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_Application
  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. require_once "Zend/Application/Resource/ResourceAbstract.php";
  23. require_once "Zend/Application/Resource/Session.php";
  24. require_once "Zend/Session.php";
  25. require_once "Zend/Session/SaveHandler/Interface.php";
  26. /**
  27. * @category Zend
  28. * @package Zend_Application
  29. * @subpackage UnitTests
  30. * @group Zend_Application
  31. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. */
  34. class Zend_Application_Resource_SessionTest extends PHPUnit_Framework_TestCase
  35. {
  36. public $resource;
  37. public function setUp()
  38. {
  39. $this->resource = new Zend_Application_Resource_Session();
  40. }
  41. public function testSetSaveHandler()
  42. {
  43. $saveHandler = $this->getMock('Zend_Session_SaveHandler_Interface');
  44. $this->resource->setSaveHandler($saveHandler);
  45. $this->assertSame($saveHandler, $this->resource->getSaveHandler());
  46. }
  47. public function testSetSaveHandlerString()
  48. {
  49. $saveHandlerClassName = 'Zend_Application_Resource_SessionTestHandlerMock1';
  50. $saveHandler = $this->getMock('Zend_Session_SaveHandler_Interface', array(), array(), $saveHandlerClassName);
  51. $this->resource->setSaveHandler($saveHandlerClassName);
  52. $this->assertTrue($this->resource->getSaveHandler() instanceof $saveHandlerClassName);
  53. }
  54. public function testSetSaveHandlerArray()
  55. {
  56. $saveHandlerClassName = 'Zend_Application_Resource_SessionTestHandlerMock2';
  57. $saveHandler = $this->getMock('Zend_Session_SaveHandler_Interface', array(), array(), $saveHandlerClassName);
  58. $this->resource->setSaveHandler(array('class' => $saveHandlerClassName));
  59. $this->assertTrue($this->resource->getSaveHandler() instanceof $saveHandlerClassName);
  60. }
  61. public function testSetOptions()
  62. {
  63. Zend_Session::setOptions(array(
  64. 'use_only_cookies' => false,
  65. 'remember_me_seconds' => 3600,
  66. ));
  67. $this->resource->setOptions(array(
  68. 'use_only_cookies' => true,
  69. 'remember_me_seconds' => 7200,
  70. ));
  71. $this->resource->init();
  72. $this->assertEquals(1, Zend_Session::getOptions('use_only_cookies'));
  73. $this->assertEquals(7200, Zend_Session::getOptions('remember_me_seconds'));
  74. }
  75. public function testInitSetsSaveHandler()
  76. {
  77. $saveHandler = $this->getMock('Zend_Session_SaveHandler_Interface');
  78. $this->resource->setSaveHandler($saveHandler);
  79. $this->resource->init();
  80. $this->assertSame($saveHandler, Zend_Session::getSaveHandler());
  81. }
  82. }