diff --git a/libraries/joomla/google/auth.php b/libraries/joomla/google/auth.php index 83a5bde66b..f7e59fb38b 100644 --- a/libraries/joomla/google/auth.php +++ b/libraries/joomla/google/auth.php @@ -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 @@ -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); } /** @@ -68,7 +72,7 @@ public function getOption($key) */ public function setOption($key, $value) { - $this->setOption($key, $value); + $this->options->set($key, $value); return $this; } diff --git a/libraries/joomla/google/google.php b/libraries/joomla/google/google.php index eedc67ef18..ce0bd79bee 100644 --- a/libraries/joomla/google/google.php +++ b/libraries/joomla/google/google.php @@ -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. @@ -49,20 +49,22 @@ 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. * @@ -70,6 +72,14 @@ public function __construct(JRegistry $options = null, JHttp $client = null) */ 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': @@ -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': diff --git a/tests/suites/unit/joomla/google/JGoogleAuthOauth2Test.php b/tests/suites/unit/joomla/google/JGoogleAuthOauth2Test.php new file mode 100644 index 0000000000..e5c26aa3ff --- /dev/null +++ b/tests/suites/unit/joomla/google/JGoogleAuthOauth2Test.php @@ -0,0 +1,95 @@ +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') + ); + } +} diff --git a/tests/suites/unit/joomla/google/JGoogleTest.php b/tests/suites/unit/joomla/google/JGoogleTest.php index 6b4bc44827..a1867c917b 100644 --- a/tests/suites/unit/joomla/google/JGoogleTest.php +++ b/tests/suites/unit/joomla/google/JGoogleTest.php @@ -1,7 +1,6 @@ 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); } /** @@ -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') ); } @@ -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') ); }