Exemplo n.º 1
0
 /**
  * @visible for testing.
  *
  * @param Google_Http_Request $request
  *
  * @return Google_Http_Request|bool Returns the cached object or
  *                                  false if the operation was unsuccessful.
  */
 public function getCachedRequest(Google_Http_Request $request)
 {
     if (false === Google_Http_CacheParser::isRequestCacheable($request)) {
         return false;
     }
     return $this->client->getCache()->get($request->getCacheKey());
 }
Exemplo n.º 2
0
 public function testSettersGetters()
 {
     $client = new Google_Client();
     $client->setClientId("client1");
     $client->setClientSecret('client1secret');
     $client->setState('1');
     $client->setApprovalPrompt('force');
     $client->setAccessType('offline');
     global $apiConfig;
     $this->assertEquals('client1', $apiConfig['oauth2_client_id']);
     $this->assertEquals('client1secret', $apiConfig['oauth2_client_secret']);
     $client->setRedirectUri('localhost');
     $client->setApplicationName('me');
     $client->setUseObjects(false);
     $this->assertEquals('object', gettype($client->getAuth()));
     $this->assertEquals('object', gettype($client->getCache()));
     $this->assertEquals('object', gettype($client->getIo()));
     $client->setAuthClass('Google_AuthNone');
     $client->setAuthClass('Google_OAuth2');
     try {
         $client->setAccessToken(null);
         die('Should have thrown an Google_AuthException.');
     } catch (Google_AuthException $e) {
         $this->assertEquals('Could not json decode the token', $e->getMessage());
     }
     $token = json_encode(array('access_token' => 'token'));
     $client->setAccessToken($token);
     $this->assertEquals($token, $client->getAccessToken());
 }
Exemplo n.º 3
0
 /**
  * @requires extension Memcached
  */
 public function testAppEngineAutoConfig()
 {
     $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
     $client = new Google_Client();
     $this->assertInstanceOf('Google_Cache_Memcache', $client->getCache());
     $this->assertInstanceOf('Google_Io_Stream', $client->getIo());
     unset($_SERVER['SERVER_SOFTWARE']);
 }
Exemplo n.º 4
0
 public function testAppEngineAutoConfig()
 {
     if (!class_exists("Memcached")) {
         $this->markTestSkipped('Test requires memcache');
     }
     $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
     $client = new Google_Client();
     $this->assertInstanceOf('Google_Cache_Memcache', $client->getCache());
     unset($_SERVER['SERVER_SOFTWARE']);
 }
Exemplo n.º 5
0
 public function testSettersGetters()
 {
     $client = new Google_Client();
     $client->setClientId("client1");
     $client->setClientSecret('client1secret');
     $client->setState('1');
     $client->setApprovalPrompt('force');
     $client->setAccessType('offline');
     $client->setRedirectUri('localhost');
     $client->setConfig('application_name', 'me');
     $client->setCache($this->getMock('Psr\\Cache\\CacheItemPoolInterface'));
     $this->assertEquals('object', gettype($client->getCache()));
     try {
         $client->setAccessToken(null);
         $this->fail('Should have thrown an Exception.');
     } catch (InvalidArgumentException $e) {
         $this->assertEquals('invalid json token', $e->getMessage());
     }
     $token = array('access_token' => 'token');
     $client->setAccessToken($token);
     $this->assertEquals($token, $client->getAccessToken());
 }
 /**
  * @requires extension Memcached
  */
 public function testAppEngineAutoConfig()
 {
     $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
     $client = new Google_Client();
     $this->assertInstanceOf('Google_Cache_Memcache', $client->getCache());
     // check Stream Handler is used
     $http = $client->getHttpClient();
     $class = new ReflectionClass(get_class($http));
     $property = $class->getProperty('fsm');
     $property->setAccessible(true);
     $fsm = $property->getValue($http);
     $class = new ReflectionClass(get_class($fsm));
     $property = $class->getProperty('handler');
     $property->setAccessible(true);
     $handler = $property->getValue($fsm);
     $this->assertInstanceOf('GuzzleHttp\\Ring\\Client\\StreamHandler', $handler);
     unset($_SERVER['SERVER_SOFTWARE']);
 }