Author: chabotc
Date: Thu Nov  6 03:49:54 2008
New Revision: 711845

URL: http://svn.apache.org/viewvc?rev=711845&view=rev
Log:
Fixes to BasicSecurityToken and CacheFile test's by Pan Jie

Modified:
    incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php
    incubator/shindig/trunk/php/test/common/CacheFileTest.php

Modified: incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php?rev=711845&r1=711844&r2=711845&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php 
(original)
+++ incubator/shindig/trunk/php/test/common/BasicSecurityTokenTest.php Thu Nov  
6 03:49:54 2008
@@ -13,6 +13,11 @@
         * @var BasicSecurityToken
         */
        private $BasicSecurityToken;
+       
+       /**
+        * @var BasicSecurityToken
+        */
+       private $anonymousToken;
 
        /**
         * Prepares the environment before running a test.
@@ -21,6 +26,7 @@
        {
                parent::setUp();
                $this->BasicSecurityToken = 
BasicSecurityToken::createFromValues('owner', 'viewer', 'app', 'domain', 
'appUrl', '1');
+               $this->anonymousToken = BasicSecurityToken::createFromValues(0, 
0, 'app', 'domain', 'appUrl', '1');
        }
 
        /**
@@ -28,12 +34,13 @@
         */
        protected function tearDown()
        {
-               $this->BasicSecurityToken = null;               
+               $this->BasicSecurityToken = null;
+               $this->anonymousToken = null;
                parent::tearDown();
        }
 
        /**
-        * Tests BasicSecurityToken::createFromValues()
+        * Tests BasicSecurityToken::createFromValues(), toSerialForm() and 
createFromToken() 
         */
        public function testCreateFromValues()
        {
@@ -44,6 +51,15 @@
                $this->assertEquals('domain', $token->getDomain());
                $this->assertEquals('appUrl', $token->getAppUrl());
                $this->assertEquals('1', $token->getModuleId());
+               
+               $stringToken = urldecode($token->toSerialForm());
+               $duplicatedToken = 
BasicSecurityToken::createFromToken($stringToken, Config::get('token_max_age'));
+               $this->assertEquals('owner', $duplicatedToken->getOwnerId());
+               $this->assertEquals('viewer', $duplicatedToken->getViewerId());
+               $this->assertEquals('app', $duplicatedToken->getAppId());
+               $this->assertEquals('domain', $duplicatedToken->getDomain());
+               $this->assertEquals('appUrl', $duplicatedToken->getAppUrl());
+               $this->assertEquals('1', $duplicatedToken->getModuleId());
        }
 
        /**
@@ -51,7 +67,9 @@
         */
        public function testGetAppId()
        {
-               $this->assertEquals('app', 
$this->BasicSecurityToken->getAppId());      
+               $this->assertEquals('app', 
$this->BasicSecurityToken->getAppId());
+               $this->setExpectedException('Exception');
+               $this->anonymousToken->getAppId();
        }
 
        /**
@@ -60,6 +78,8 @@
        public function testGetAppUrl()
        {
                $this->assertEquals('appUrl', 
$this->BasicSecurityToken->getAppUrl());
+               $this->setExpectedException('Exception');
+               $this->anonymousToken->getAppUrl();
        }
 
        /**
@@ -68,6 +88,8 @@
        public function testGetDomain()
        {
                $this->assertEquals('domain', 
$this->BasicSecurityToken->getDomain());
+               $this->setExpectedException('Exception');
+               $this->anonymousToken->getDomain();
        }
 
        /**
@@ -76,6 +98,8 @@
        public function testGetModuleId()
        {
                $this->assertEquals(1, 
$this->BasicSecurityToken->getModuleId());
+               $this->setExpectedException('Exception');
+               $this->anonymousToken->getModuleId();
        }
 
        /**
@@ -84,6 +108,8 @@
        public function testGetOwnerId()
        {
                $this->assertEquals('owner', 
$this->BasicSecurityToken->getOwnerId());
+               $this->setExpectedException('Exception');
+               $this->anonymousToken->getOwnerId();
        }
 
        /**
@@ -92,6 +118,8 @@
        public function testGetViewerId()
        {
                $this->assertEquals('viewer', 
$this->BasicSecurityToken->getViewerId());
+               $this->setExpectedException('Exception');
+               $this->anonymousToken->getViewerId();
        }
 
        /**
@@ -101,4 +129,4 @@
        {
                $this->assertFalse($this->BasicSecurityToken->isAnonymous());
        }
-}
+}
\ No newline at end of file

Modified: incubator/shindig/trunk/php/test/common/CacheFileTest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/test/common/CacheFileTest.php?rev=711845&r1=711844&r2=711845&view=diff
==============================================================================
--- incubator/shindig/trunk/php/test/common/CacheFileTest.php (original)
+++ incubator/shindig/trunk/php/test/common/CacheFileTest.php Thu Nov  6 
03:49:54 2008
@@ -51,28 +51,69 @@
         */
        public function testDelete()
        {
+               @rmdir("/tmp/shindig/te");
                $cache = new CacheFile();
                $cache->set("test", "testing");
                $cache->delete("test");
                $this->assertEquals("", $cache->get("test"));
+               $this->assertTrue(rmdir("/tmp/shindig/te"));
+       }
+
+       /**
+        * Tests CacheFile->delete()
+        */
+       public function testDeleteException()
+       {
+               $cache = new CacheFile();
+               $this->setExpectedException("CacheException");
+               $cache->delete("test");
        }
 
        /**
         * Tests CacheFile->get()
         */
        public function testGet()
-       {       
-               $this->CacheFile->set("test", "testing");       
+       {
+               $this->CacheFile->set("test", "testing");
                $this->assertEquals("testing", $this->CacheFile->get("test"));
        }
 
        /**
+        * Tests CacheFile->get()
+        */
+       public function testExpiredGet()
+       {
+               $this->CacheFile->set("test", "testing");
+               @sleep(1);
+               $this->assertFalse($this->CacheFile->get("test", 1));
+       }
+
+       /**
         * Tests CacheFile->set()
         */
        public function testSet()
        {
-               $this->CacheFile->set("test", "testing");       
+               @unlink("/tmp/shindig/te/test");
+               @rmdir("/tmp/shindig/te");
+               $this->CacheFile->set("test", "testing");
                $this->assertEquals("testing", $this->CacheFile->get("test"));
+               @unlink("/tmp/shindig/te/test");
+               @rmdir("/tmp/shindig/te");
        }
 
+       /**
+        * Tests CacheFile->set()
+        */
+       public function testSetException()
+       {
+               @rmdir("/tmp/shindig/te");
+               $this->assertTrue(touch("/tmp/shindig/te"));
+               $this->setExpectedException("CacheException");
+               try {
+                       $this->CacheFile->set("test", "testing");
+               } catch (Exception $e) {
+                       $this->assertTrue(unlink("/tmp/shindig/te"));
+                       throw $e;
+               }
+       }
 }
\ No newline at end of file


Reply via email to