PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/creovel/test/classes/ActiveSessionTest.php

http://creovel.googlecode.com/
PHP | 127 lines | 87 code | 18 blank | 22 comment | 0 complexity | af343271f5c242020ee7d778a9bf5945 MD5 | raw file
Possible License(s): JSON
  1. <?php
  2. /**
  3. * Unit tests for ActiveSession object.
  4. *
  5. * @access private
  6. * @package Creovel
  7. * @subpackage UnitTest
  8. * @license http://creovel.org/license MIT License
  9. * @since Class available since Release 0.4.5
  10. * @author Nesbert Hidalgo
  11. **/
  12. require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'env.php';
  13. class ActiveSessionTest extends PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @var ActiveSession
  17. */
  18. protected $o;
  19. protected $aq;
  20. protected $session_id;
  21. protected $session_val;
  22. /**
  23. * Sets up the fixture, for example, opens a network connection.
  24. * This method is called before a test is executed.
  25. */
  26. protected function setUp()
  27. {
  28. CREO('database', TestSetting::$mysql);
  29. CREO('mode', 'mysql');
  30. CREO('sessions_table', ActiveSession::$_table_name_);
  31. $this->drop_db_sql = "DROP DATABASE IF EXISTS `phpunit`;";
  32. $this->create_db_sql = "CREATE DATABASE `phpunit`;";
  33. $this->select_db_sql = "USE `phpunit`;";
  34. $this->drop_table_sql = "DROP TABLE IF EXISTS `".ActiveSession::$_table_name_."`;";
  35. $this->aq = new ActiveQuery(TestSetting::$mysql);
  36. $this->aq->query($this->drop_db_sql);
  37. $this->aq->query($this->create_db_sql);
  38. $this->aq->query($this->select_db_sql);
  39. ActiveSession::create_table();
  40. $this->o = new ActiveSession;
  41. $this->session_id = 'PHPUNIT'.time();
  42. $this->session_val = 'test data';
  43. }
  44. /**
  45. * Tears down the fixture, for example, closes a network connection.
  46. * This method is called after a test is executed.
  47. */
  48. protected function tearDown()
  49. {
  50. $this->aq->query($this->drop_table_sql);
  51. $this->aq->query($this->drop_db_sql);
  52. unset($this->aq);
  53. unset($this->o);
  54. }
  55. public function testOpen()
  56. {
  57. $this->assertEquals('user', ini_get('session.save_handler'));
  58. $this->assertTrue($this->o->open());
  59. }
  60. public function testClose()
  61. {
  62. $this->assertTrue($this->o->open());
  63. $this->assertTrue($this->o->close());
  64. }
  65. public function testRead()
  66. {
  67. $this->assertTrue($this->o->open());
  68. $this->assertFalse($this->o->read(''));
  69. $this->assertTrue($this->o->close());
  70. }
  71. public function testWrite()
  72. {
  73. $this->assertTrue($this->o->open());
  74. $this->assertEquals('', $this->o->read($this->session_id));
  75. $this->assertEquals(1, $this->o->write($this->session_id, $this->session_val));
  76. $this->assertEquals($this->session_val, $this->o->read($this->session_id));
  77. $this->assertTrue($this->o->close());
  78. }
  79. public function testDestroy()
  80. {
  81. $this->assertTrue($this->o->open());
  82. $this->assertEquals('', $this->o->read($this->session_id));
  83. $this->assertEquals(1, $this->o->write($this->session_id, $this->session_val));
  84. $this->assertEquals(1, $this->o->destroy($this->session_id));
  85. $this->assertEquals('', $this->o->read($this->session_id));
  86. $this->assertTrue($this->o->close());
  87. }
  88. public function testGc()
  89. {
  90. ini_set('session.gc_maxlifetime', HOUR*-1);
  91. $this->assertTrue($this->o->open());
  92. $this->assertEquals('', $this->o->read($this->session_id));
  93. $this->assertEquals(1, $this->o->write($this->session_id, $this->session_val));
  94. $this->assertEquals($this->session_val, $this->o->read($this->session_id));
  95. $this->assertEquals(1, $this->o->gc(''));
  96. $this->assertEquals('', $this->o->read($this->session_id));
  97. $this->assertTrue($this->o->close());
  98. }
  99. public function testCreate_table()
  100. {
  101. // test done at setup
  102. $this->assertTrue(method_exists($this->o, 'create_table'));
  103. }
  104. public function testStart()
  105. {
  106. $this->assertTrue(method_exists($this->o, 'start'));
  107. }
  108. }
  109. ?>