source: sandbox/2.4.1-3/prototype/library/oauth2/tests/OAuth2OutputTest.php @ 6351

Revision 6351, 2.8 KB checked in by gustavo, 12 years ago (diff)

Ticket #2768 - Melhorias na inserção de destinatários na criacao de mensagem

  • Property svn:executable set to *
Line 
1<?php
2require __DIR__ . '/../lib/OAuth2.php';
3require __DIR__ . '/../lib/IOAuth2Storage.php';
4require __DIR__ . '/../lib/IOAuth2GrantCode.php';
5
6/**
7 * OAuth2 test cases that invovle capturing output.
8 */
9class OAuth2OutputTest extends PHPUnit_Extensions_OutputTestCase {
10 
11  /**
12   * @var OAuth2
13   */
14  private $fixture;
15 
16  /**
17   * Tests OAuth2->grantAccessToken() with successful Auth code grant
18   *
19   */
20  public function testGrantAccessTokenWithGrantAuthCodeSuccess() {
21    $inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'redirect_uri' => 'http://www.example.com/my/subdir', 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code'=> 'foo');
22    $storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);
23   
24    $mockStorage = $this->createBaseMock('IOAuth2GrantCode');
25    $mockStorage->expects($this->any())
26      ->method('getAuthCode')
27      ->will($this->returnValue($storedToken));
28     
29    // Successful token grant will return a JSON encoded token:
30    $this->expectOutputRegex('/{"access_token":".*","expires_in":\d+,"token_type":"bearer"/');
31    $this->fixture = new OAuth2($mockStorage);
32    $this->fixture->grantAccessToken($inputData, array());
33  }
34 
35  /**
36   * Tests OAuth2->grantAccessToken() with successful Auth code grant, but without redreict_uri in the input
37   */
38  public function testGrantAccessTokenWithGrantAuthCodeSuccessWithoutRedirect() {
39    $inputData = array('grant_type' => OAuth2::GRANT_TYPE_AUTH_CODE, 'client_id' => 'my_little_app', 'client_secret' => 'b', 'code'=> 'foo');
40    $storedToken = array('redirect_uri' => 'http://www.example.com', 'client_id' => 'my_little_app', 'expires' => time() + 60);
41   
42    $mockStorage = $this->createBaseMock('IOAuth2GrantCode');
43    $mockStorage->expects($this->any())
44      ->method('getAuthCode')
45      ->will($this->returnValue($storedToken));
46     
47    // Successful token grant will return a JSON encoded token:
48    $this->expectOutputRegex('/{"access_token":".*","expires_in":\d+,"token_type":"bearer"/');
49    $this->fixture = new OAuth2($mockStorage);
50    $this->fixture->setVariable(OAuth2::CONFIG_ENFORCE_INPUT_REDIRECT, false);
51    $this->fixture->grantAccessToken($inputData, array());
52  }
53 
54// Utility methods
55 
56  /**
57   *
58   * @param string $interfaceName
59   */
60  protected function createBaseMock($interfaceName) {
61    $mockStorage = $this->getMock($interfaceName);
62    $mockStorage->expects($this->any())
63      ->method('checkClientCredentials')
64      ->will($this->returnValue(TRUE)); // Always return true for any combination of user/pass
65    $mockStorage->expects($this->any())
66      ->method('checkRestrictedGrantType')
67      ->will($this->returnValue(TRUE)); // Always return true for any combination of user/pass
68     
69     return $mockStorage;
70  }
71 
72}
Note: See TracBrowser for help on using the repository browser.