| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Service_Twitter_Search
- * @subpackage UnitTests
- * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- require_once "PHPUnit/Framework/TestCase.php";
- require_once "PHPUnit/Framework/TestSuite.php";
- /** Zend_Service_Twitter_Search */
- require_once 'Zend/Service/Twitter/Search.php';
- /** Zend_Http_Client */
- require_once 'Zend/Http/Client.php';
- /** Zend_Http_Client_Adapter_Test */
- require_once 'Zend/Http/Client/Adapter/Test.php';
- /**
- * @category Zend
- * @package Zend_Service_Twitter_Search
- * @subpackage UnitTests
- * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Service_Twitter_SearchTest extends PHPUnit_Framework_TestCase
- {
- /**
- * Runs the test methods of this class.
- *
- * @return void
- */
- public static function main()
- {
- require_once "PHPUnit/TextUI/TestRunner.php";
- $suite = new PHPUnit_Framework_TestSuite("Zend_Service_Twitter_SearchTest");
- $result = PHPUnit_TextUI_TestRunner::run($suite);
- }
- /**
- * Sets up the fixture, for example, open a network connection.
- * This method is called before a test is executed.
- *
- * @return void
- */
- protected function setUp()
- {
- $this->twitter = new Zend_Service_Twitter_Search();
- }
- /**
- * Tears down the fixture, for example, close a network connection.
- * This method is called after a test is executed.
- *
- * @return void
- */
- protected function tearDown()
- {}
- public function testSetResponseTypeToJSON()
- {
- $this->twitter->setResponseType('json');
- $this->assertEquals('json', $this->twitter->getResponseType());
- }
- public function testSetResponseTypeToATOM()
- {
- $this->twitter->setResponseType('atom');
- $this->assertEquals('atom', $this->twitter->getResponseType());
- }
- public function testInvalidResponseTypeShouldThrowException()
- {
- try {
- $this->twitter->setResponseType('xml');
- $this->fail('Setting an invalid response type should throw an exception');
- } catch(Exception $e) {
- }
- }
- public function testValidResponseTypeShouldNotThrowException()
- {
- try {
- $this->twitter->setResponseType('atom');
- } catch(Exception $e) {
- $this->fail('Setting a valid response type should not throw an exception');
- }
- }
- public function testSearchTrendsReturnsArray()
- {
- $response = $this->twitter->trends();
- $this->assertType('array', $response);
- }
- public function testJsonSearchContainsWordReturnsArray()
- {
- $this->twitter->setResponseType('json');
- $response = $this->twitter->search('zend');
- $this->assertType('array', $response);
- }
- public function testAtomSearchContainsWordReturnsObject()
- {
- $this->twitter->setResponseType('atom');
- $response = $this->twitter->search('zend');
- $this->assertTrue($response instanceof Zend_Feed_Atom);
- }
- public function testJsonSearchRestrictsLanguageReturnsArray()
- {
- $this->twitter->setResponseType('json');
- $response = $this->twitter->search('zend', array('lang' => 'de'));
- $this->assertType('array', $response);
- $this->assertTrue((isset($response['results'][0]) && $response['results'][0]['iso_language_code'] == "de"));
- }
- public function testAtomSearchRestrictsLanguageReturnsObject()
- {
- $this->twitter->setResponseType('atom');
- /* @var $response Zend_Feed_Atom */
- $response = $this->twitter->search('zend', array('lang' => 'de'));
- $this->assertTrue($response instanceof Zend_Feed_Atom);
- $this->assertTrue((strpos($response->link('self'), 'lang=de') !== false));
- }
- public function testJsonSearchReturnThirtyResultsReturnsArray()
- {
- $this->twitter->setResponseType('json');
- $response = $this->twitter->search('zend', array('rpp' => '30'));
- $this->assertType('array', $response);
- $this->assertTrue((count($response['results']) == 30));
- }
- public function testAtomSearchReturnThirtyResultsReturnsObject()
- {
- $this->twitter->setResponseType('atom');
- /* @var $response Zend_Feed_Atom */
- $response = $this->twitter->search('zend', array('rpp' => '30'));
- $this->assertTrue($response instanceof Zend_Feed_Atom);
- $this->assertTrue(($response->count() == 30));
- }
- public function testAtomSearchShowUserReturnsObject()
- {
- $this->twitter->setResponseType('atom');
- /* @var $response Zend_Feed_Atom */
- $response = $this->twitter->search('zend', array('show_user' => 'true'));
- $this->assertTrue($response instanceof Zend_Feed_Atom);
- }
- }
|