Exemple #1
0
 /**
  * Enter description here...
  *
  * @param unknown_type $aid
  * @param unknown_type $uid
  * @param unknown_type $infinite
  * @param unknown_type $key
  * @return unknown
  */
 public static function setUserAppSession($aid, $uid, $infinite = 0, $key)
 {
     if (Api_Dao_UserAppSession::isUserAppSession($uid, $aid)) {
         return Api_Dao_UserAppSession::updateUserAppSession($aid, $uid, $infinite, $key);
     } else {
         return Api_Dao_UserAppSession::createUserAppSession($aid, $uid, $infinite, $key);
     }
 }
 /**
  * @dataProvider provideForUserSession
  */
 public function testUserSession($uid, $aid, $sessionKey)
 {
     try {
         $userAppSession = Api_Dao_UserAppSession::getUserAppSession($uid, $aid);
     } catch (Exception $exception) {
         $this->fail("Unexpected get none exception " . $exception);
     }
     $this->assertEquals(0, count($userAppSession), "There should be no existing user app sesion for uid ({$uid}) aid ({$aid})");
     $infinite = 0;
     $ret = Api_Dao_UserAppSession::createUserAppSession($aid, $uid, $infinite, $sessionKey . '-1');
     $this->assertTrue($ret !== false);
     $userAppSession = null;
     try {
         $userAppSession = Api_Dao_UserAppSession::getUserAppSession($uid, $aid);
     } catch (Exception $exception) {
         $this->fail("Unexpected get first exception " . $exception);
     }
     $this->assertNotNull($userAppSession[0], "Inserted and should not be null");
     $this->assertEquals($uid, $userAppSession[0]->uid);
     $this->assertEquals($aid, $userAppSession[0]->aid);
     $this->assertEquals($sessionKey . "-1", $userAppSession[0]->session_key);
     $this->assertEquals(0, $userAppSession[0]->infinite);
     try {
         $ret = Api_Dao_UserAppSession::updateUserAppSession($aid, $uid, $infinite, $sessionKey . '-2');
         $this->assertGreaterThan(0, $ret);
     } catch (Exception $exception) {
         $this->fail("Unexpected updated exception " . $exception);
     }
     $userAppSession = null;
     try {
         $userAppSession = Api_Dao_UserAppSession::getUserAppSession($uid, $aid);
     } catch (Exception $exception) {
         $this->fail("Unexpected get updated exception " . $exception);
     }
     $this->assertNotNull($userAppSession[0], "Updated db, should not be null");
     $this->assertEquals($uid, $userAppSession[0]->uid);
     $this->assertEquals($aid, $userAppSession[0]->aid);
     $this->assertEquals($sessionKey . "-2", $userAppSession[0]->session_key);
     $this->assertEquals(0, $userAppSession[0]->infinite);
     try {
         $ret = Api_Dao_UserAppSession::deleteUserAppSession($aid, $uid);
         $this->assertEquals(1, $ret);
     } catch (Exception $exception) {
         $this->fail("Unexpected delete exception " . $exception);
     }
     $userAppSession = null;
     try {
         $userAppSession = Api_Dao_UserAppSession::getUserAppSession($uid, $aid);
     } catch (Exception $exception) {
         $this->fail("Unexpected get deleted  exception " . $exception);
     }
     $this->assertEquals(0, count($userAppSession), "Just deleted but still exists uid ({$uid}) aid ({$aid})");
 }
 /**
  * @dataProvider providerTestExecute
  */
 public function testExecute($uid, $aid, $ctxUid, $ctxAid, $defaultApp, $expected)
 {
     try {
         $infinite = $expected['infinite'] == 'true' ? 1 : 0;
         $uas = Api_Dao_UserAppSession::getUserAppSession($uid, $aid);
         if (count($uas) == 0) {
             Api_Dao_UserAppSession::createUserAppSession($aid, $uid, $infinite, $expected['session_key']);
         } else {
             Api_Dao_UserAppSession::updateUserAppSession($aid, $uid, $infinite, $expected['session_key']);
         }
     } catch (Exception $e) {
         $this->fail("Could not setup test properly");
     }
     $params = array();
     if ($ctxUid != $uid) {
         $params['user_id'] = $uid;
     }
     $params['app_id'] = $aid;
     $response = null;
     try {
         $method = $this->initRest(new UsersGetAppSession(), $params, $ctxUid, $ctxAid);
         $response = $method->execute();
     } catch (OpenFBAPIException $exception) {
         $this->assertFalse($defaultApp, "Unexpected exception " . $exception);
         return;
         //         $this->fail( "No exception expected " . $exception->getCode() );
     }
     // Validate that the calling application is a default application.
     $this->assertTrue($defaultApp, "Expected an error, app was not supposed to be a default app.");
     if (empty($response)) {
         $this->assertArrayHasKey('session', $response, "Expected empty results (ie session='') ");
     } else {
         $this->assertEquals($expected['infinite'], $response['infinite'], "infinite response does not match");
         $this->assertEquals($expected['session_key'], $response['session_key'], "Session key response does not match.");
     }
 }