Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make isAuth method more robust and add unit test.

  • Loading branch information...
commit 01cc3c6111675e5728257ab67c2191c8239b2fe6 1 parent 870abf6
@aaronschmitz aaronschmitz authored LouisLandry committed
Showing with 31 additions and 6 deletions.
  1. +31 −6 tests/suites/unit/joomla/oauth/JOauthV2clientTest.php
View
37 tests/suites/unit/joomla/oauth/JOauthV2clientTest.php
@@ -102,7 +102,7 @@ public function testAuth()
$this->object->setOption('tokenurl', 'https://accounts.google.com/o/oauth2/token');
$this->object->setOption('clientsecret', 'jeDs8rKw_jDJW8MMf-ff8ejs');
$this->input->set('code', '4/wEr_dK8SDkjfpwmc98KejfiwJP-f4wm.kdowmnr82jvmeisjw94mKFIJE48mcEM');
- $this->http->expects($this->once())->method('post')->will($this->returnCallback('postCallback'));
+ $this->http->expects($this->once())->method('post')->will($this->returnCallback('postOauthCallback'));
$result = $this->object->auth();
$this->assertEquals('accessvalue', $result['access_token']);
$this->assertEquals('refreshvalue', $result['refresh_token']);
@@ -111,6 +111,31 @@ public function testAuth()
}
/**
+ * Tests the isauth method
+ *
+ * @group JOauth
+ * @return void
+ */
+ public function testIsAuth()
+ {
+ $this->assertEquals(false, $this->object->isAuth());
+
+ $token['access_token'] = 'accessvalue';
+ $token['refresh_token'] = 'refreshvalue';
+ $token['created'] = time();
+ $token['expires_in'] = 3600;
+ $this->object->setToken($token);
+
+ $this->assertEquals(true, $this->object->isAuth());
+
+ $token['created'] = time() - 4000;
+ $token['expires_in'] = 3600;
+ $this->object->setToken($token);
+
+ $this->assertEquals(false, $this->object->isAuth());
+ }
+
+ /**
* Tests the auth method
*
* @group JOauth
@@ -148,12 +173,12 @@ public function testQuery()
$token['expires_in'] = 3600;
$this->object->setToken($token);
- $this->http->expects($this->once())->method('get')->will($this->returnCallback('getCallback'));
+ $this->http->expects($this->once())->method('get')->will($this->returnCallback('getOauthCallback'));
$result = $this->object->query('https://www.googleapis.com/auth/calendar', array('param' => 'value'), array(), 'get');
$this->assertEquals($result->body, 'Lorem ipsum dolor sit amet.');
$this->assertEquals(200, $result->code);
- $this->http->expects($this->once())->method('post')->will($this->returnCallback('postCallback'));
+ $this->http->expects($this->once())->method('post')->will($this->returnCallback('postOauthCallback'));
$result = $this->object->query('https://www.googleapis.com/auth/calendar', array('param' => 'value'), array(), 'post');
$this->assertEquals($result->body, 'Lorem ipsum dolor sit amet.');
$this->assertEquals(200, $result->code);
@@ -252,7 +277,7 @@ public function testRefreshToken()
$this->object->setOption('userefresh', true);
$this->object->setToken(array('access_token' => 'RANDOM STRING OF DATA', 'expires' => 3600, 'refresh_token' => ' RANDOM STRING OF DATA'));
- $this->http->expects($this->once())->method('post')->will($this->returnCallback('postCallback'));
+ $this->http->expects($this->once())->method('post')->will($this->returnCallback('postOauthCallback'));
$result = $this->object->refreshToken();
$this->assertEquals('accessvalue', $result['access_token']);
$this->assertEquals('refreshvalue', $result['refresh_token']);
@@ -273,7 +298,7 @@ public function testRefreshToken()
*
* @since 12.2
*/
-function postCallback($url, $data, array $headers = null, $timeout = null)
+function postOauthCallback($url, $data, array $headers = null, $timeout = null)
{
if (isset($data['grant_type']))
{
@@ -301,7 +326,7 @@ function postCallback($url, $data, array $headers = null, $timeout = null)
*
* @since 12.2
*/
-function getCallback($url, array $headers = null, $timeout = null)
+function getOauthCallback($url, array $headers = null, $timeout = null)
{
$response->code = 200;
$response->headers = array('Content-Type' => 'text/html');
Please sign in to comment.
Something went wrong with that request. Please try again.