/**
  * Tests OAuth2->grantAccessToken() with successful Auth code grant, but without redreict_uri in the input
  */
 public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect()
 {
     $inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code' => 'foo');
     $storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);
     $mockStorage = $this->createBaseMock('IOAuth2GrantCode');
     $mockStorage->expects($this->any())->method('getAuthCode')->will($this->returnValue($storedToken));
     // Successful token grant will return a JSON encoded token:
     $this->expectOutputRegex('/{"access_token":".*","expires_in":\\d+,"token_type":"bearer"/');
     $this->fixture = new OAuth2($mockStorage);
     $this->fixture->setVariable(OAuth2::CONFIG_ENFORCE_INPUT_REDIRECT, false);
     $this->fixture->grantAccessToken($inputData, array());
 }
 /**
  * Tests OAuth2->grantAccessToken() with Auth code grant
  *
  */
 public function testGrantAccessTokenWithGrantAuthCodeMandatoryParams()
 {
     $mockStorage = $this->createBaseMock('IOAuth2GrantCode');
     $inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'a', 'client_secret' => 'b');
     $fakeAuthCode = array('client_id' => $inputData['client_id'], 'redirect_uri' => '/foo', 'expires' => time() + 60);
     $fakeAccessToken = array('access_token' => 'abcde');
     // Ensure redirect URI and auth-code is mandatory
     try {
         $this->fixture = new OAuth2($mockStorage);
         $this->fixture->setVariable(OAuth2::CONFIG_ENFORCE_INPUT_REDIRECT, true);
         // Only required when this is set
         $this->fixture->grantAccessToken($inputData + array('code' => 'foo'), array());
         $this->fail('The expected exception OAuth2ServerException was not thrown');
     } catch (OAuth2ServerException $e) {
         $this->assertEquals(OAuth2::ERROR_INVALID_REQUEST, $e->getMessage());
     }
     try {
         $this->fixture = new OAuth2($mockStorage);
         $this->fixture->grantAccessToken($inputData + array('redirect_uri' => 'foo'), array());
         $this->fail('The expected exception OAuth2ServerException was not thrown');
     } catch (OAuth2ServerException $e) {
         $this->assertEquals(OAuth2::ERROR_INVALID_REQUEST, $e->getMessage());
     }
 }