Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Slight changes to the constructors of JGoogle.
Browse files Browse the repository at this point in the history
Added unit test: JGoogleAuthOauth2Test.php
  • Loading branch information
aaronschmitz authored and LouisLandry committed Oct 12, 2012
1 parent 7a0e1e7 commit 7d0a513
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 16 deletions.
8 changes: 6 additions & 2 deletions libraries/joomla/google/auth.php
Expand Up @@ -36,6 +36,10 @@ abstract public function auth();
/**
* Abstract method to retrieve data from Google
*
* @param string $url The URL for the request.
* @param mixed $data The data to include in the request.
* @param array $headers The headers to send with the request.
*
* @return mixed Data from Google.
*
* @since 1234
Expand All @@ -53,7 +57,7 @@ abstract public function query($url, $data = null, $headers = null);
*/
public function getOption($key)
{
return $this->getOption($key);
return $this->options->get($key);
}

/**
Expand All @@ -68,7 +72,7 @@ public function getOption($key)
*/
public function setOption($key, $value)
{
$this->setOption($key, $value);
$this->options->set($key, $value);

return $this;
}
Expand Down
31 changes: 23 additions & 8 deletions libraries/joomla/google/google.php
Expand Up @@ -28,10 +28,10 @@ class JGoogle
protected $options;

/**
* @var JHttp The HTTP client object to use in sending HTTP requests.
* @var JAuth The authentication client object to use in sending authenticated HTTP requests.
* @since 1234
*/
protected $client;
protected $auth;

/**
* @var JGoogleData Google API object for data request.
Expand All @@ -49,27 +49,37 @@ class JGoogle
* Constructor.
*
* @param JRegistry $options Google options object.
* @param JHttp $client The HTTP client object.
* @param JAuth $auth The authentication client object.
*
* @since 1234
*/
public function __construct(JRegistry $options = null, JHttp $client = null)
public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
{
$this->options = isset($options) ? $options : new JRegistry;
$this->client = isset($client) ? $client : new JHttp($this->options);
$this->auth = isset($auth) ? $auth : new JAuthOauth2($this->options);
}

/**
* Method to create JGoogleData objects
*
* @param string $name Name of property to retrieve
* @param string $name Name of property to retrieve
* @param JRegistry $options Google options object.
* @param JAuth $auth The authentication client object.
*
* @return JGoogleData Google data API object.
*
* @since 1234
*/
public function data($name, $options = null, $auth = null)
{
if ($this->options && !$options)
{
$options = $this->options;
}
if ($this->auth && !$auth)
{
$auth = $this->auth;
}
switch ($name)
{
case 'picasa':
Expand All @@ -89,14 +99,19 @@ public function data($name, $options = null, $auth = null)
/**
* Method to create JGoogleEmbed objects
*
* @param string $name Name of property to retrieve
* @param string $name Name of property to retrieve
* @param JRegistry $options Google options object.
*
* @return JGoogleEmbed Google embed API object.
*
* @since 1234
*/
public function embed($name, $options)
public function embed($name, $options = null)
{
if ($this->options && !$options)
{
$options = $this->options;
}
switch ($name)
{
case 'maps':
Expand Down
95 changes: 95 additions & 0 deletions tests/suites/unit/joomla/google/JGoogleAuthOauth2Test.php
@@ -0,0 +1,95 @@
<?php
/**
* @package Joomla.UnitTest
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

require_once JPATH_PLATFORM . '/joomla/google/google.php';

/**
* Test class for JGoogle.
*/
class JGoogleAuthOauth2Test extends PHPUnit_Framework_TestCase
{
/**
* @var JRegistry Options for the JOauth2client object.
*/
protected $options;

/**
* @var JHttp Mock client object.
*/
protected $client;

/**
* @var JInput The input object to use in retrieving GET/POST data.
*/
protected $input;

/**
* @var JOauth2client The OAuth client for sending requests to Google.
*/
protected $oauth;

/**
* @var JGoogleAuthOauth2 Object under test.
*/
protected $object;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
$this->options = new JRegistry;
$this->client = $this->getMock('JHttp', array('post'));
$this->input = new JInput;
$this->oauth = new JOauth2client($this->options, $this->client, $this->input);
$this->object = new JGoogleAuthOauth2($this->options, $this->oauth);
}

/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
*/
protected function tearDown()
{
}

/**
* Tests the setOption method
* @group JGoogle
* @return void
*/
public function testSetOption()
{
$this->object->setOption('key', 'value');

$this->assertThat(
$this->options->get('key'),
$this->equalTo('value')
);
}

/**
* Tests the getOption method
* @group JGoogle
* @return void
*/
public function testStuff()
{
$this->options->set('key', 'value');

$this->assertThat(
$this->object->getOption('key'),
$this->equalTo('value')
);
}
}
11 changes: 5 additions & 6 deletions tests/suites/unit/joomla/google/JGoogleTest.php
@@ -1,7 +1,6 @@
<?php
/**
* @package Joomla.UnitTest
* @subpackage Client
*
* @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
Expand Down Expand Up @@ -55,9 +54,9 @@ protected function setUp()
$this->options = new JRegistry;
$this->client = $this->getMock('JHttp', array('post'));
$this->input = new JInput;
$this->oauth = new JOauth2client($this->options, $this->client, $this->input);
$this->auth = new JGoogleAuthOauth2($this->options, $this->oauth);
$this->object = new JGoogle($this->options, $this->client);
$this->oauth = new JOauth2client($this->options, $this->client, $this->input);
$this->auth = new JGoogleAuthOauth2($this->options, $this->oauth);
$this->object = new JGoogle($this->options, $this->auth);
}

/**
Expand All @@ -78,7 +77,7 @@ protected function tearDown()
public function test__GetData()
{
$this->assertThat(
$this->object->data('Picasa', $this->options, $this->auth),
$this->object->data('Picasa'),
$this->isInstanceOf('JGoogleDataPicasa')
);
}
Expand All @@ -91,7 +90,7 @@ public function test__GetData()
public function test__GetEmbed()
{
$this->assertThat(
$this->object->embed('Maps', $this->options),
$this->object->embed('Maps'),
$this->isInstanceOf('JGoogleEmbedMaps')
);
}
Expand Down

0 comments on commit 7d0a513

Please sign in to comment.