From bd08d47c6e8fe2f732c52d7c1f249224e4383fc8 Mon Sep 17 00:00:00 2001 From: carl <> Date: Fri, 27 Jul 2007 08:46:05 +0000 Subject: #682 - testing of TCacheHttpSession --- tests/unit/Web/TCacheHttpSessionTest.php | 129 +++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 tests/unit/Web/TCacheHttpSessionTest.php (limited to 'tests/unit/Web/TCacheHttpSessionTest.php') diff --git a/tests/unit/Web/TCacheHttpSessionTest.php b/tests/unit/Web/TCacheHttpSessionTest.php new file mode 100644 index 00000000..7d5523d6 --- /dev/null +++ b/tests/unit/Web/TCacheHttpSessionTest.php @@ -0,0 +1,129 @@ +app = new TApplication($basePath); + self::$cache = new TMemCache(); + self::$cache->setKeyPrefix('MyCache'); + self::$cache->init(null); + $this->app->setModule('MyCache',self::$cache); + } + } + + protected function tearDown() + { + $this->app = null; + $this->cache = null; + $this->session = null; + } + + public function testInit() + { + $session = new TCacheHttpSession(); + try + { + $session->init(null); + $this->fail("Expected TConfigurationException is not raised"); + } + catch(TConfigurationException $e) + { + } + unset($session); + + $session = new TCacheHttpSession(); + try + { + $session->setCacheModuleID('MaiCache'); + $session->init(null); + $this->fail("Expected TConfigurationException is not raised"); + $session->open(); + } + catch(TConfigurationException $e) + { + } + unset($session); + + self::$session = new TCacheHttpSession(); + try + { + self::$session->setCacheModuleID('MyCache'); + self::$session->init(null); + } + catch(TConfigurationException $e) + { + $this->fail('TConfigurationException is not expected'); + self::markTestSkipped('Cannot continue this test'); + } + } + + public function testGetCache() + { + $cache = self::$session->getCache(); + $this->assertEquals(true, $cache instanceof TMemCache); + } + + public function testCacheModuleID() + { + $id = 'value'; + self::$session->setCacheModuleID('value'); + self::assertEquals($id, self::$session->getCacheModuleID()); + } + + public function testKeyPrefix() + { + $id = 'value'; + self::$session->setKeyPrefix('value'); + self::assertEquals($id, self::$session->getKeyPrefix()); + } + + public function testSetAndGet() + { + self::$session['key'] = 'value'; + self::assertEquals('value', self::$session['key']); + } + + public function testAdd() + { + self::$session->add('anotherkey', 'value'); + self::assertEquals('value', self::$session['anotherkey']); + } + + public function testRemove() + { + self::$session->remove('key'); + self::assertEquals(false, self::$session['key']); + } + + public function testDestroyAndIsStarted() + { + $this->testSetAndGet(); + self::$session->destroy(); + self::assertEquals(false, self::$session->getIsStarted()); + } +} +?> \ No newline at end of file -- cgit v1.2.3