test/snac/server/database/DBUserTest.php
/**
     * Test adding and removing a user
     */
Test adding and removing a user
Test adding and removing a user
public function testAutoUser()
    {
        $userObj = new \snac\data\User();
        $userObj->setFirstName("Malf");
        $userObj->setLastName("Torrent");
        $userObj->setFullName("Malf S Torrent");
        $userObj->setAvatar("http://example.com/avatar");
        $userObj->setAvatarSmall("http://example.com/avatar_small");
        $userObj->setAvatarLarge("http://example.com/avatar_large");
        $userObj->setEmail("mst3k@example.com");
        $userObj->setUserActive(true);
        $userObj->setToken(array('access_token' => 'foo',
                                 'expires' => time() + (60*60)));
        $csaReturn = $this->dbu->createUser($userObj);
        $cleanUpUser = clone($csaReturn);
        $foundUserID = $this->dbu->findUserID("mst3k@example.com");
        $this->assertEquals($foundUserID, $csaReturn->getUserID());
        $this->dbu->removeSession($csaReturn);
         if (! $this->dbu->sessionExists($csaReturn))
         {
             $this->dbu->addSession($csaReturn);
         }
        $this->assertEquals($csaReturn->getToken()['access_token'], 'foo');
        $this->assertTrue($this->dbu->sessionActive($csaReturn));
        $goodUserID = $csaReturn->getUserID();
        $csaReturn->setUserID('123456');
        $this->assertFalse($this->dbu->userExists($csaReturn));
        $firstUserList = $this->dbu->listUsers();
        $this->dbu->disableUser($cleanUpUser);
        $secondUserList = $this->dbu->listUsers();
        $thirdUserList = $this->dbu->listUsers(true);
        $this->assertEquals(count($firstUserList), count($thirdUserList));
        $this->assertEquals(count($firstUserList), count($secondUserList)+1);
        $this->dbu->eraseUser($cleanUpUser);
    }
public function testAutoUser ( ) { $ userObj = new \ snac \ data \ User ( ) ; $ userObj -> setFirstName ( " Malf " ) ; $ userObj -> setLastName ( " Torrent " ) ; $ userObj -> setFullName ( " Malf S Torrent " ) ; $ userObj -> setAvatar ( " http://example.com/avatar " ) ; $ userObj -> setAvatarSmall ( " http://example.com/avatar_small " ) ; $ userObj -> setAvatarLarge ( " http://example.com/avatar_large " ) ; $ userObj -> setEmail ( " mst3k@example.com " ) ; $ userObj -> setUserActive ( true ) ; $ userObj -> setToken ( array ( 'access_token' => 'foo' , 'expires' => time ( ) + ( 60 * 60 ) ) ) ; $ csaReturn = $ this -> dbu -> createUser ( $ userObj ) ; $ cleanUpUser = clone ( $ csaReturn ) ; $ foundUserID = $ this -> dbu -> findUserID ( " mst3k@example.com " ) ; $ this -> assertEquals ( $ foundUserID , $ csaReturn -> getUserID ( ) ) ; $ this -> dbu -> removeSession ( $ csaReturn ) ; if ( ! $ this -> dbu -> sessionExists ( $ csaReturn ) ) { $ this -> dbu -> addSession ( $ csaReturn ) ; } $ this -> assertEquals ( $ csaReturn -> getToken ( ) [ 'access_token' ] , 'foo' ) ; $ this -> assertTrue ( $ this -> dbu -> sessionActive ( $ csaReturn ) ) ; $ goodUserID = $ csaReturn -> getUserID ( ) ; $ csaReturn -> setUserID ( '123456' ) ; $ this -> assertFalse ( $ this -> dbu -> userExists ( $ csaReturn ) ) ; $ firstUserList = $ this -> dbu -> listUsers ( ) ; $ this -> dbu -> disableUser ( $ cleanUpUser ) ; $ secondUserList = $ this -> dbu -> listUsers ( ) ; $ thirdUserList = $ this -> dbu -> listUsers ( true ) ; $ this -> assertEquals ( count ( $ firstUserList ) , count ( $ thirdUserList ) ) ; $ this -> assertEquals ( count ( $ firstUserList ) , count ( $ secondUserList ) + 1 ) ; $ this -> dbu -> eraseUser ( $ cleanUpUser ) ; }
Test adding and removing a user
Test adding and removing a user
/*
         * Create a new user object
         */ /*
         * User does not exist in db.
         *
         * This is a more or less valid session, with an expires 1 hour in the future.
         */ /*
         * Test userExists() with the ficticious user id.
         */ /*
         * Check that listUsers for everyone includes the disabled (inactive) user. And that disableUser makes
         * the user inactive.
         */ /*
         * When things are normally successful, we might want to clean up.
         */