Skip to content

Commit

Permalink
Merge pull request #7477 from wilsonge/applicationwebstub
Browse files Browse the repository at this point in the history
Use the mock application in the OAuth tests
  • Loading branch information
Michael Babker committed Jul 19, 2015
2 parents ab392fa + 3bdcfbd commit 46c4482
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Expand Up @@ -10,7 +10,6 @@
use Joomla\Registry\Registry;

include_once __DIR__ . '/stubs/JOAuth1ClientInspector.php';
include_once __DIR__ . '/../application/stubs/JApplicationWebInspector.php';

/**
* Test class for JOAuth1Client.
Expand Down Expand Up @@ -89,7 +88,7 @@ protected function setUp()
$this->options = new Registry;
$this->client = $this->getMock('JHttp', array('get', 'post', 'delete', 'put'));
$this->input = new JInput(array());
$this->application = new JApplicationWebInspector;
$this->application = $this->getMockWeb();

$this->options->set('consumer_key', $key);
$this->options->set('consumer_secret', $secret);
Expand Down
19 changes: 17 additions & 2 deletions tests/unit/suites/libraries/joomla/oauth2/JOauth2ClientTest.php
Expand Up @@ -43,6 +43,13 @@ class JOAuth2ClientTest extends TestCase
*/
protected $object;

/**
* Code that the app closes with.
*
* @var int
*/
private static $closed = null;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
Expand All @@ -62,7 +69,7 @@ protected function setUp()
$this->http = $this->getMock('JHttp', array('head', 'get', 'delete', 'trace', 'post', 'put', 'patch'), array($this->options));
$array = array();
$this->input = new JInput($array);
$this->application = new JApplicationWebInspector;
$this->application = $this->getMockWeb();
$this->object = new JOAuth2Client($this->options, $this->http, $this->input, $this->application);
}

Expand All @@ -82,7 +89,7 @@ public function testAuth()
$this->object->setOption('sendheaders', true);

$this->object->authenticate();
$this->assertEquals(0, $this->application->closed);
$this->assertEquals(0, static::$closed);

$this->object->setOption('tokenurl', 'https://accounts.google.com/o/oauth2/token');
$this->object->setOption('clientsecret', 'jeDs8rKw_jDJW8MMf-ff8ejs');
Expand Down Expand Up @@ -321,6 +328,14 @@ public function testRefreshTokenJson()
$this->assertEquals(3600, $result['expires_in']);
$this->assertLessThanOrEqual(1, time() - $result['created']);
}

/**
* @param integer $code The exit code (optional; default is 0).
*/
public static function mockClose($code = 0)
{
self::$closed = $code;
}
}

/**
Expand Down
Expand Up @@ -7,8 +7,6 @@
* @license GNU General Public License version 2 or later; see LICENSE
*/

include_once __DIR__ . '/../application/stubs/JApplicationWebInspector.php';

/**
* Test class for JLinkedinOauth.
*
Expand Down Expand Up @@ -78,8 +76,8 @@ protected function setUp()
$my_url = "http://127.0.0.1/twitter_test.php";

$this->options = new JRegistry;
$this->input = new JInput;
$this->application = new JApplicationWebInspector;
$this->input = $this->getMockInput();
$this->application = $this->getMockWeb();
$this->client = $this->getMock('JHttp', array('get', 'post', 'delete', 'put'));

$this->options->set('consumer_key', $key);
Expand Down

0 comments on commit 46c4482

Please sign in to comment.