TwitterSearchTest.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Twitter_Search
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2006 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once "PHPUnit/Framework/TestCase.php";
  22. require_once "PHPUnit/Framework/TestSuite.php";
  23. /** Zend_Service_Twitter_Search */
  24. require_once 'Zend/Service/Twitter/Search.php';
  25. /** Zend_Http_Client */
  26. require_once 'Zend/Http/Client.php';
  27. /** Zend_Http_Client_Adapter_Test */
  28. require_once 'Zend/Http/Client/Adapter/Test.php';
  29. /**
  30. * @category Zend
  31. * @package Zend_Service_Twitter_Search
  32. * @subpackage UnitTests
  33. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  34. * @license http://framework.zend.com/license/new-bsd New BSD License
  35. */
  36. class Zend_Service_Twitter_SearchTest extends PHPUnit_Framework_TestCase
  37. {
  38. /**
  39. * Runs the test methods of this class.
  40. *
  41. * @return void
  42. */
  43. public static function main()
  44. {
  45. require_once "PHPUnit/TextUI/TestRunner.php";
  46. $suite = new PHPUnit_Framework_TestSuite("Zend_Service_Twitter_SearchTest");
  47. $result = PHPUnit_TextUI_TestRunner::run($suite);
  48. }
  49. /**
  50. * Sets up the fixture, for example, open a network connection.
  51. * This method is called before a test is executed.
  52. *
  53. * @return void
  54. */
  55. protected function setUp()
  56. {
  57. $this->twitter = new Zend_Service_Twitter_Search();
  58. }
  59. /**
  60. * Tears down the fixture, for example, close a network connection.
  61. * This method is called after a test is executed.
  62. *
  63. * @return void
  64. */
  65. protected function tearDown()
  66. {}
  67. public function testSetResponseTypeToJSON()
  68. {
  69. $this->twitter->setResponseType('json');
  70. $this->assertEquals('json', $this->twitter->getResponseType());
  71. }
  72. public function testSetResponseTypeToATOM()
  73. {
  74. $this->twitter->setResponseType('atom');
  75. $this->assertEquals('atom', $this->twitter->getResponseType());
  76. }
  77. public function testInvalidResponseTypeShouldThrowException()
  78. {
  79. try {
  80. $this->twitter->setResponseType('xml');
  81. $this->fail('Setting an invalid response type should throw an exception');
  82. } catch(Exception $e) {
  83. }
  84. }
  85. public function testValidResponseTypeShouldNotThrowException()
  86. {
  87. try {
  88. $this->twitter->setResponseType('atom');
  89. } catch(Exception $e) {
  90. $this->fail('Setting a valid response type should not throw an exception');
  91. }
  92. }
  93. public function testSearchTrendsReturnsArray()
  94. {
  95. $response = $this->twitter->trends();
  96. $this->assertType('array', $response);
  97. }
  98. public function testJsonSearchContainsWordReturnsArray()
  99. {
  100. $this->twitter->setResponseType('json');
  101. $response = $this->twitter->search('zend');
  102. $this->assertType('array', $response);
  103. }
  104. public function testAtomSearchContainsWordReturnsObject()
  105. {
  106. $this->twitter->setResponseType('atom');
  107. $response = $this->twitter->search('zend');
  108. $this->assertTrue($response instanceof Zend_Feed_Atom);
  109. }
  110. public function testJsonSearchRestrictsLanguageReturnsArray()
  111. {
  112. $this->twitter->setResponseType('json');
  113. $response = $this->twitter->search('zend', array('lang' => 'de'));
  114. $this->assertType('array', $response);
  115. $this->assertTrue((isset($response['results'][0]) && $response['results'][0]['iso_language_code'] == "de"));
  116. }
  117. public function testAtomSearchRestrictsLanguageReturnsObject()
  118. {
  119. $this->twitter->setResponseType('atom');
  120. /* @var $response Zend_Feed_Atom */
  121. $response = $this->twitter->search('zend', array('lang' => 'de'));
  122. $this->assertTrue($response instanceof Zend_Feed_Atom);
  123. $this->assertTrue((strpos($response->link('self'), 'lang=de') !== false));
  124. }
  125. public function testJsonSearchReturnThirtyResultsReturnsArray()
  126. {
  127. $this->twitter->setResponseType('json');
  128. $response = $this->twitter->search('zend', array('rpp' => '30'));
  129. $this->assertType('array', $response);
  130. $this->assertTrue((count($response['results']) == 30));
  131. }
  132. public function testAtomSearchReturnThirtyResultsReturnsObject()
  133. {
  134. $this->twitter->setResponseType('atom');
  135. /* @var $response Zend_Feed_Atom */
  136. $response = $this->twitter->search('zend', array('rpp' => '30'));
  137. $this->assertTrue($response instanceof Zend_Feed_Atom);
  138. $this->assertTrue(($response->count() == 30));
  139. }
  140. public function testAtomSearchShowUserReturnsObject()
  141. {
  142. $this->twitter->setResponseType('atom');
  143. /* @var $response Zend_Feed_Atom */
  144. $response = $this->twitter->search('zend', array('show_user' => 'true'));
  145. $this->assertTrue($response instanceof Zend_Feed_Atom);
  146. }
  147. }