pdo = new PDO('mysql:host=localhost;dbname=test', 'webuser', ''); return $this->createDefaultDBConnection($this->pdo, 'test'); } protected function getDataSet() { return $this->createFlatXMLDataSet(dirname(__FILE__).'/tokens.xml'); } protected function setUp() { parent::setUp(); $this->storage = new Rememberme_Storage_PDO(array( 'connection' => $this->pdo, 'tableName' => 'tokens', 'credentialColumn' => 'credential', 'tokenColumn' => 'token', 'persistentTokenColumn' => 'persistent_token', 'expiresColumn' => 'expires' )); } public function testFindTripletReturnsFoundIfDataMatches() { $result = $this->storage->findTriplet($this->userid, $this->validToken, $this->validPersistentToken); $this->assertEquals(Rememberme_Storage_StorageInterface::TRIPLET_FOUND, $result); } public function testFindTripletReturnsNotFoundIfNoDataMatches() { $this->pdo->exec("TRUNCATE tokens"); $result = $this->storage->findTriplet($this->userid, $this->validToken, $this->validPersistentToken); $this->assertEquals(Rememberme_Storage_StorageInterface::TRIPLET_NOT_FOUND, $result); } public function testFindTripletReturnsInvalidTokenIfTokenIsInvalid() { $result = $this->storage->findTriplet($this->userid, $this->invalidToken, $this->validPersistentToken); $this->assertEquals(Rememberme_Storage_StorageInterface::TRIPLET_INVALID, $result); } public function testStoreTripletSavesValuesIntoDatabase() { $this->pdo->exec("TRUNCATE tokens"); $this->storage->storeTriplet($this->userid, $this->validToken, $this->validPersistentToken, $this->expireTS); $result = $this->pdo->query("SELECT credential,token,persistent_token, expires FROM tokens"); $row = $result->fetch(PDO::FETCH_NUM); $this->assertEquals(array($this->userid, $this->validDBToken, $this->validDBPersistentToken, $this->expire), $row); $this->assertFalse($result->fetch()); } public function testCleanTripletRemovesEntryFromDatabase() { $this->storage->cleanTriplet($this->userid, $this->validPersistentToken); $this->assertEquals(0, $this->pdo->query("SELECT COUNT(*) FROM tokens")->fetchColumn()); } public function testCleanAllTripletsRemovesAllEntriesWithMatchingCredentialsFromDatabase() { $this->pdo->exec("INSERT INTO tokens VALUES ('{$this->userid}', 'dummy', 'dummy', NOW())"); $this->storage->cleanAllTriplets($this->userid); $this->assertEquals(0, $this->pdo->query("SELECT COUNT(*) FROM tokens")->fetchColumn()); } } ?>