Skip to content

Commit

Permalink
Merging in ./tests for ZendService\Flickr
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphschindler committed Jul 18, 2012
2 parents 51beb8b + 4876451 commit 5674e01
Show file tree
Hide file tree
Showing 28 changed files with 1,133 additions and 0 deletions.
490 changes: 490 additions & 0 deletions tests/ZendService/Flickr/OfflineTest.php

Large diffs are not rendered by default.

203 changes: 203 additions & 0 deletions tests/ZendService/Flickr/OnlineTest.php
@@ -0,0 +1,203 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Service
*/

namespace ZendTest\Service\Flickr;

use Zend\Http\Client\Adapter\Socket as SocketAdapter;
use Zend\Service\Flickr\Flickr;
use Zend\Service\Flickr\Exception\OutOfBoundsException;

/**
* @category Zend
* @package Zend_Service_Flickr
* @subpackage UnitTests
* @group Zend_Service
* @group Zend_Service_Flickr
*/
class OnlineTest extends \PHPUnit_Framework_TestCase
{
/**
* Reference to Flickr service consumer object
*
* @var Flickr
*/
protected $flickr;

/**
* Socket based HTTP client adapter
*
* @var SocketAdapter
*/
protected $httpClientAdapterSocket;

/**
* Sets up this test case
*
* @return void
*/
public function setUp()
{
if (!constant('TESTS_ZEND_SERVICE_FLICKR_ONLINE_ENABLED')) {
$this->markTestSkipped('Zend_Service_Flickr online tests are not enabled');
}

$this->flickr = new Flickr(constant('TESTS_ZEND_SERVICE_FLICKR_ONLINE_APIKEY'));

$this->httpClientAdapterSocket = new SocketAdapter();

$this->flickr->getRestClient()
->getHttpClient()
->setAdapter($this->httpClientAdapterSocket);
}

/**
* Basic testing to ensure that groupPoolGetPhotos works as expected
*
* @return void
*/
public function testGroupPoolGetPhotosBasic()
{
$options = array('per_page' => 10,
'page' => 1,
'extras' => 'license, date_upload, date_taken, owner_name, icon_server');

$resultSet = $this->flickr->groupPoolGetPhotos('20083316@N00', $options);

$this->assertGreaterThan(20000, $resultSet->totalResultsAvailable);
$this->assertEquals(10, $resultSet->totalResults());
$this->assertEquals(10, $resultSet->totalResultsReturned);
$this->assertEquals(1, $resultSet->firstResultPosition);

$this->assertEquals(0, $resultSet->key());

try {
$resultSet->seek(-1);
$this->fail('Expected OutOfBoundsException not thrown');
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}

$resultSet->seek(9);

try {
$resultSet->seek(10);
$this->fail('Expected OutOfBoundsException not thrown');
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}

$resultSet->rewind();

$count = 0;
foreach ($resultSet as $result) {
$this->assertInstanceOf('Zend\Service\Flickr\Result', $result);
$count++;
}

$this->assertEquals(10, $count);
}

/**
* Basic testing to ensure that userSearch() works as expected
*
* @return void
*/
public function testUserSearchBasic()
{
$options = array('per_page' => 10,
'page' => 1,
'extras' => 'license, date_upload, date_taken, owner_name, icon_server');

$resultSet = $this->flickr->userSearch('darby.felton@yahoo.com', $options);

$this->assertEquals(16, $resultSet->totalResultsAvailable);
$this->assertEquals(10, $resultSet->totalResults());
$this->assertEquals(10, $resultSet->totalResultsReturned);
$this->assertEquals(1, $resultSet->firstResultPosition);

$this->assertEquals(0, $resultSet->key());

try {
$resultSet->seek(-1);
$this->fail('Expected OutOfBoundsException not thrown');
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}

$resultSet->seek(9);

try {
$resultSet->seek(10);
$this->fail('Expected OutOfBoundsException not thrown');
} catch (OutOfBoundsException $e) {
$this->assertContains('Illegal index', $e->getMessage());
}

$resultSet->rewind();

$count = 0;
foreach ($resultSet as $result) {
$this->assertInstanceOf('Zend\Service\Flickr\Result', $result);
$count++;
}

$this->assertEquals(10, $count);
}

/**
* Basic testing to ensure that getIdByUsername() works as expected
*
* @return void
*/
public function testGetIdByUsernameBasic()
{
$userId = $this->flickr->getIdByUsername('darby.felton');
$this->assertEquals('7414329@N07', $userId);
}

/**
* Ensures that tagSearch() works as expected with the sort option
*
* @return void
*/
public function testTagSearchOptionSort()
{
$options = array(
'per_page' => 10,
'page' => 1,
'tag_mode' => 'or',
'sort' => 'date-taken-asc',
'extras' => 'license, date_upload, date_taken, owner_name, icon_server'
);

$resultSet = $this->flickr->tagSearch('php', $options);

$this->assertTrue(10 < $resultSet->totalResultsAvailable);
$this->assertEquals(10, $resultSet->totalResults());
$this->assertEquals(10, $resultSet->totalResultsReturned);
$this->assertEquals(1, $resultSet->firstResultPosition);

foreach ($resultSet as $result) {
$this->assertInstanceOf('Zend\Service\Flickr\Result', $result);
if (isset($dateTakenPrevious)) {
$this->assertTrue(strcmp($result->datetaken, $dateTakenPrevious) > 0);
}
$dateTakenPrevious = $result->datetaken;
}
}

/**
* @group ZF-6397
*/
public function testTotalForEmptyResultSet()
{
$this->assertEquals(0, $this->flickr->tagSearch('zendflickrtesttagnoresults')->totalResults());
}
}
43 changes: 43 additions & 0 deletions tests/ZendService/Flickr/TestAsset/FlickrProtectedMethodProxy.php
@@ -0,0 +1,43 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Service
*/

namespace ZendTest\Service\Flickr\TestAsset;

use Zend\Service\Flickr\Flickr;

/**
* @category Zend
* @package Zend_Service_Flickr
* @subpackage UnitTests
* @group Zend_Service
* @group Zend_Service_Flickr
*/
class FlickrProtectedMethodProxy extends Flickr
{
public function proxyValidateUserSearch(array $options)
{
$this->validateUserSearch($options);
}

public function proxyValidateTagSearch(array $options)
{
$this->validateTagSearch($options);
}

public function proxyValidateGroupPoolGetPhotos(array $options)
{
$this->validateGroupPoolGetPhotos($options);
}

public function proxyCompareOptions(array $options, array $validOptions)
{
$this->compareOptions($options, $validOptions);
}
}
@@ -0,0 +1,16 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:47 GMT
Server: Apache/2.0.52
Content-length: 828
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/146/427883923_25902ff728_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883923&amp;size=sq" />
<size label="Thumbnail" width="100" height="8" source="http://farm1.static.flickr.com/146/427883923_25902ff728_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883923&amp;size=t" />
<size label="Small" width="221" height="17" source="http://farm1.static.flickr.com/146/427883923_25902ff728_m.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883923&amp;size=s" />
<size label="Large" width="221" height="17" source="http://farm1.static.flickr.com/146/427883923_398e28d146_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427883923&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:48 GMT
Server: Apache/2.0.52
Content-length: 1012
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/162/427883924_bbfdee1f96_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883924&amp;size=sq" />
<size label="Thumbnail" width="100" height="3" source="http://farm1.static.flickr.com/162/427883924_bbfdee1f96_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883924&amp;size=t" />
<size label="Small" width="240" height="8" source="http://farm1.static.flickr.com/162/427883924_bbfdee1f96_m.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883924&amp;size=s" />
<size label="Medium" width="500" height="16" source="http://farm1.static.flickr.com/162/427883924_bbfdee1f96.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883924&amp;size=m" />
<size label="Large" width="531" height="17" source="http://farm1.static.flickr.com/162/427883924_e27b0e1bf3_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427883924&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,16 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:46 GMT
Server: Apache/2.0.52
Content-length: 829
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/163/427883929_e46c580947_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883929&amp;size=sq" />
<size label="Thumbnail" width="100" height="11" source="http://farm1.static.flickr.com/163/427883929_e46c580947_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883929&amp;size=t" />
<size label="Small" width="116" height="13" source="http://farm1.static.flickr.com/163/427883929_e46c580947_m.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883929&amp;size=s" />
<size label="Large" width="116" height="13" source="http://farm1.static.flickr.com/163/427883929_f0230e0d5a_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427883929&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,15 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:48 GMT
Server: Apache/2.0.52
Content-length: 639
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/163/427883930_37e83d6bde_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883930&amp;size=sq" />
<size label="Thumbnail" width="23" height="3" source="http://farm1.static.flickr.com/163/427883930_37e83d6bde_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427883930&amp;size=t" />
<size label="Large" width="23" height="3" source="http://farm1.static.flickr.com/163/427883930_edb91cc3a2_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427883930&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,15 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:47 GMT
Server: Apache/2.0.52
Content-length: 641
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/145/427884394_48678fb007_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884394&amp;size=sq" />
<size label="Thumbnail" width="92" height="37" source="http://farm1.static.flickr.com/145/427884394_48678fb007_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884394&amp;size=t" />
<size label="Large" width="92" height="37" source="http://farm1.static.flickr.com/145/427884394_d1e788022b_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427884394&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:48 GMT
Server: Apache/2.0.52
Content-length: 1012
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/154/427884398_ab68b726ae_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884398&amp;size=sq" />
<size label="Thumbnail" width="100" height="3" source="http://farm1.static.flickr.com/154/427884398_ab68b726ae_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884398&amp;size=t" />
<size label="Small" width="240" height="7" source="http://farm1.static.flickr.com/154/427884398_ab68b726ae_m.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884398&amp;size=s" />
<size label="Medium" width="500" height="14" source="http://farm1.static.flickr.com/154/427884398_ab68b726ae.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884398&amp;size=m" />
<size label="Large" width="531" height="15" source="http://farm1.static.flickr.com/154/427884398_c372035a18_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427884398&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,17 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:49 GMT
Server: Apache/2.0.52
Content-length: 1012
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/160/427884401_b561b6636a_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884401&amp;size=sq" />
<size label="Thumbnail" width="100" height="3" source="http://farm1.static.flickr.com/160/427884401_b561b6636a_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884401&amp;size=t" />
<size label="Small" width="240" height="8" source="http://farm1.static.flickr.com/160/427884401_b561b6636a_m.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884401&amp;size=s" />
<size label="Medium" width="500" height="16" source="http://farm1.static.flickr.com/160/427884401_b561b6636a.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884401&amp;size=m" />
<size label="Large" width="531" height="17" source="http://farm1.static.flickr.com/160/427884401_6356f5fae7_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427884401&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,15 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:46 GMT
Server: Apache/2.0.52
Content-length: 639
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/183/427884403_fb2ebbb275_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884403&amp;size=sq" />
<size label="Thumbnail" width="23" height="3" source="http://farm1.static.flickr.com/183/427884403_fb2ebbb275_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427884403&amp;size=t" />
<size label="Large" width="23" height="3" source="http://farm1.static.flickr.com/183/427884403_bd4c170074_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427884403&amp;size=o" />
</sizes>
</rsp>
@@ -0,0 +1,15 @@
HTTP/1.1 200 OK
Date: Thu, 22 Mar 2007 19:09:47 GMT
Server: Apache/2.0.52
Content-length: 639
Connection: close
Content-type: text/xml; charset=utf-8

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
<sizes>
<size label="Square" width="75" height="75" source="http://farm1.static.flickr.com/156/427887192_a5a5781ea0_s.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427887192&amp;size=sq" />
<size label="Thumbnail" width="11" height="1" source="http://farm1.static.flickr.com/156/427887192_a5a5781ea0_t.jpg" url="http://www.flickr.com/photo_zoom.gne?id=427887192&amp;size=t" />
<size label="Large" width="11" height="1" source="http://farm1.static.flickr.com/156/427887192_ebd45dbf31_o.gif" url="http://www.flickr.com/photo_zoom.gne?id=427887192&amp;size=o" />
</sizes>
</rsp>

0 comments on commit 5674e01

Please sign in to comment.