public function testAddingResponseType()
 {
     $storage = $this->getMock('OAuth2_Storage_Memory');
     $storage->expects($this->any())->method('getClientDetails')->will($this->returnValue(array('client_id' => 'some_client')));
     $storage->expects($this->any())->method('checkRestrictedGrantType')->will($this->returnValue(true));
     // add with the "code" key explicitly set
     $codeType = new OAuth2_ResponseType_AuthorizationCode($storage);
     $server = new OAuth2_Server();
     $server->addStorage($storage);
     $server->addResponseType($codeType);
     $request = new OAuth2_Request(array('response_type' => 'code', 'client_id' => 'some_client', 'redirect_uri' => 'http://example.com', 'state' => 'xyx'));
     $server->handleAuthorizeRequest($request, $response = new OAuth2_Response(), true);
     // the response is successful
     $this->assertEquals($response->getStatusCode(), 302);
     $parts = parse_url($response->getHttpHeader('Location'));
     parse_str($parts['query'], $query);
     $this->assertTrue(isset($query['code']));
     $this->assertFalse(isset($query['error']));
     // add with the "code" key not set
     $codeType = new OAuth2_ResponseType_AuthorizationCode($storage);
     $server = new OAuth2_Server(array($storage), array(), array(), array($codeType));
     $request = new OAuth2_Request(array('response_type' => 'code', 'client_id' => 'some_client', 'redirect_uri' => 'http://example.com', 'state' => 'xyx'));
     $server->handleAuthorizeRequest($request, $response = new OAuth2_Response(), true);
     // the response is successful
     $this->assertEquals($response->getStatusCode(), 302);
     $parts = parse_url($response->getHttpHeader('Location'));
     parse_str($parts['query'], $query);
     $this->assertTrue(isset($query['code']));
     $this->assertFalse(isset($query['error']));
 }
 public function testAddingStorageWithValidKeyOnlySetsThatKey()
 {
     if (version_compare(phpversion(), '5.3', '<')) {
         // cannot run this test in 5.2
         return;
     }
     $server = new OAuth2_Server();
     $server->addStorage($this->getMock('OAuth2_Storage_Memory'), 'access_token');
     $reflection = new ReflectionClass($server);
     $prop = $reflection->getProperty('storages');
     $prop->setAccessible(true);
     $storages = $prop->getValue($server);
     // get the private "storages" property
     $this->assertEquals(1, count($storages));
     $this->assertTrue(isset($storages['access_token']));
     $this->assertFalse(isset($storages['authorization_code']));
 }