OfflineTest.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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_Yahoo
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Test helper
  24. */
  25. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  26. /**
  27. * @see Zend_Service_Yahoo
  28. */
  29. require_once 'Zend/Service/Yahoo.php';
  30. /**
  31. * @see Zend_Service_Yahoo_ResultSet
  32. */
  33. require_once 'Zend/Service/Yahoo/ResultSet.php';
  34. /**
  35. * @see Zend_Http_Client_Adapter_Socket
  36. */
  37. require_once 'Zend/Http/Client/Adapter/Socket.php';
  38. /**
  39. * @see Zend_Http_Client_Adapter_Test
  40. */
  41. require_once 'Zend/Http/Client/Adapter/Test.php';
  42. /**
  43. * @see Zend_Service_Yahoo_WebResult
  44. */
  45. require_once 'Zend/Service/Yahoo/WebResult.php';
  46. /**
  47. * @category Zend
  48. * @package Zend_Service_Yahoo
  49. * @subpackage UnitTests
  50. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  51. * @license http://framework.zend.com/license/new-bsd New BSD License
  52. * @group Zend_Service
  53. * @group Zend_Service_Yahoo
  54. */
  55. class Zend_Service_Yahoo_OfflineTest extends PHPUnit_Framework_TestCase
  56. {
  57. /**
  58. * Reference to Yahoo service consumer object
  59. *
  60. * @var Zend_Service_Yahoo
  61. */
  62. protected $_yahoo;
  63. /**
  64. * Socket based HTTP client adapter
  65. *
  66. * @var Zend_Http_Client_Adapter_Socket
  67. */
  68. protected $_httpClientAdapterSocket;
  69. /**
  70. * HTTP client adapter for testing
  71. *
  72. * @var Zend_Http_Client_Adapter_Test
  73. */
  74. protected $_httpClientAdapterTest;
  75. /**
  76. * Sets up this test case
  77. *
  78. * @return void
  79. */
  80. public function setUp()
  81. {
  82. $this->_yahoo = new Zend_Service_Yahoo(constant('TESTS_ZEND_SERVICE_YAHOO_ONLINE_APPID'));
  83. $this->_httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
  84. $this->_httpClientAdapterTest = new Zend_Http_Client_Adapter_Test();
  85. }
  86. /**
  87. * Ensures that Zend_Service_Yahoo_ResultSet::current() throws an exception
  88. *
  89. * @return void
  90. */
  91. public function testResultSetCurrentException()
  92. {
  93. $domDocument = new DOMDocument();
  94. $domDocument->appendChild($domDocument->createElement('ResultSet'));
  95. $resultSet = new Zend_Service_Yahoo_OfflineTest_ResultSet($domDocument);
  96. try {
  97. $resultSet->current();
  98. $this->fail('Expected Zend_Service_Exception not thrown');
  99. } catch (Zend_Service_Exception $e) {
  100. $this->assertContains('implemented by child', $e->getMessage());
  101. }
  102. }
  103. /**
  104. * Ensures that inlinkDataSearch() throws an exception when the results option is invalid
  105. *
  106. * @return void
  107. */
  108. public function testInlinkDataSearchExceptionResultsInvalid()
  109. {
  110. try {
  111. $this->_yahoo->inlinkDataSearch('http://framework.zend.com/', array('results' => 101));
  112. $this->fail('Expected Zend_Service_Exception not thrown');
  113. } catch (Zend_Service_Exception $e) {
  114. $this->assertContains("option 'results'", $e->getMessage());
  115. }
  116. }
  117. /**
  118. * Ensures that inlinkDataSearch() throws an exception when the start option is invalid
  119. *
  120. * @return void
  121. */
  122. public function testInlinkDataSearchExceptionStartInvalid()
  123. {
  124. try {
  125. $this->_yahoo->inlinkDataSearch('http://framework.zend.com/', array('start' => 1001));
  126. $this->fail('Expected Zend_Service_Exception not thrown');
  127. } catch (Zend_Service_Exception $e) {
  128. $this->assertContains("option 'start'", $e->getMessage());
  129. }
  130. }
  131. /**
  132. * Ensures that inlinkDataSearch() throws an exception when the omit_inlinks option is invalid
  133. *
  134. * @return void
  135. */
  136. public function testInlinkDataSearchExceptionOmitLinksInvalid()
  137. {
  138. try {
  139. $this->_yahoo->inlinkDataSearch('http://framework.zend.com/', array('omit_inlinks' => 'oops'));
  140. $this->fail('Expected Zend_Service_Exception not thrown');
  141. } catch (Zend_Service_Exception $e) {
  142. $this->assertContains("option 'omit_inlinks'", $e->getMessage());
  143. }
  144. }
  145. /**
  146. * Ensures that imageSearch() throws an exception when the type option is invalid
  147. *
  148. * @return void
  149. */
  150. public function testImageSearchExceptionTypeInvalid()
  151. {
  152. try {
  153. $this->_yahoo->imageSearch('php', array('type' => 'oops'));
  154. $this->fail('Expected Zend_Service_Exception not thrown');
  155. } catch (Zend_Service_Exception $e) {
  156. $this->assertContains("option 'type'", $e->getMessage());
  157. }
  158. }
  159. /**
  160. * Ensures that imageSearch() throws an exception when the results option is invalid
  161. *
  162. * @return void
  163. */
  164. public function testImageSearchExceptionResultsInvalid()
  165. {
  166. try {
  167. $this->_yahoo->imageSearch('php', array('results' => 500));
  168. $this->fail('Expected Zend_Service_Exception not thrown');
  169. } catch (Zend_Service_Exception $e) {
  170. $this->assertContains("option 'results'", $e->getMessage());
  171. }
  172. }
  173. /**
  174. * Ensures that imageSearch() throws an exception when the start option is invalid
  175. *
  176. * @return void
  177. */
  178. public function testImageSearchExceptionStartInvalid()
  179. {
  180. try {
  181. $this->_yahoo->imageSearch('php', array('start' => 1001));
  182. $this->fail('Expected Zend_Service_Exception not thrown');
  183. } catch (Zend_Service_Exception $e) {
  184. $this->assertContains("option 'start'", $e->getMessage());
  185. }
  186. }
  187. /**
  188. * Ensures that imageSearch() throws an exception when the format option is invalid
  189. *
  190. * @return void
  191. */
  192. public function testImageSearchExceptionFormatInvalid()
  193. {
  194. try {
  195. $this->_yahoo->imageSearch('php', array('format' => 'oops'));
  196. $this->fail('Expected Zend_Service_Exception not thrown');
  197. } catch (Zend_Service_Exception $e) {
  198. $this->assertContains("option 'format'", $e->getMessage());
  199. }
  200. }
  201. /**
  202. * Ensures that imageSearch() throws an exception when the coloration option is invalid
  203. *
  204. * @return void
  205. */
  206. public function testImageSearchExceptionColorationInvalid()
  207. {
  208. try {
  209. $this->_yahoo->imageSearch('php', array('coloration' => 'oops'));
  210. $this->fail('Expected Zend_Service_Exception not thrown');
  211. } catch (Zend_Service_Exception $e) {
  212. $this->assertContains("option 'coloration'", $e->getMessage());
  213. }
  214. }
  215. /**
  216. * Ensures that localSearch() throws an exception when the results option is invalid
  217. *
  218. * @return void
  219. */
  220. public function testLocalSearchExceptionResultsInvalid()
  221. {
  222. try {
  223. $this->_yahoo->localSearch('php', array('results' => 'oops'));
  224. $this->fail('Expected Zend_Service_Exception not thrown');
  225. } catch (Zend_Service_Exception $e) {
  226. $this->assertContains("option 'results'", $e->getMessage());
  227. }
  228. }
  229. /**
  230. * Ensures that localSearch() throws an exception when the start option is invalid
  231. *
  232. * @return void
  233. */
  234. public function testLocalSearchExceptionStartInvalid()
  235. {
  236. try {
  237. $this->_yahoo->localSearch('php', array('start' => 'oops'));
  238. $this->fail('Expected Zend_Service_Exception not thrown');
  239. } catch (Zend_Service_Exception $e) {
  240. $this->assertContains("option 'start'", $e->getMessage());
  241. }
  242. }
  243. /**
  244. * Ensures that localSearch() throws an exception when the longitude option is invalid
  245. *
  246. * @return void
  247. */
  248. public function testLocalSearchExceptionLongitudeInvalid()
  249. {
  250. try {
  251. $this->_yahoo->localSearch('php', array('longitude' => -91));
  252. $this->fail('Expected Zend_Service_Exception not thrown');
  253. } catch (Zend_Service_Exception $e) {
  254. $this->assertContains("option 'longitude'", $e->getMessage());
  255. }
  256. }
  257. /**
  258. * Ensures that localSearch() throws an exception when the latitude option is invalid
  259. *
  260. * @return void
  261. */
  262. public function testLocalSearchExceptionLatitudeInvalid()
  263. {
  264. try {
  265. $this->_yahoo->localSearch('php', array('latitude' => -181));
  266. $this->fail('Expected Zend_Service_Exception not thrown');
  267. } catch (Zend_Service_Exception $e) {
  268. $this->assertContains("option 'latitude'", $e->getMessage());
  269. }
  270. }
  271. /**
  272. * Ensures that localSearch() throws an exception when the zip option is invalid
  273. *
  274. * @return void
  275. */
  276. public function testLocalSearchExceptionZipInvalid()
  277. {
  278. try {
  279. $this->_yahoo->localSearch('php', array('zip' => 'oops'));
  280. $this->fail('Expected Zend_Service_Exception not thrown');
  281. } catch (Zend_Service_Exception $e) {
  282. $this->assertContains("option 'zip'", $e->getMessage());
  283. }
  284. }
  285. /**
  286. * Ensures that localSearch() throws an exception when location data are missing
  287. *
  288. * @return void
  289. */
  290. public function testLocalSearchExceptionLocationMissing()
  291. {
  292. try {
  293. $this->_yahoo->localSearch('php');
  294. $this->fail('Expected Zend_Service_Exception not thrown');
  295. } catch (Zend_Service_Exception $e) {
  296. $this->assertContains('Location data', $e->getMessage());
  297. }
  298. }
  299. /**
  300. * Ensures that localSearch() throws an exception when the sort option is invalid
  301. *
  302. * @return void
  303. */
  304. public function testLocalSearchExceptionSortInvalid()
  305. {
  306. try {
  307. $this->_yahoo->localSearch('php', array('location' => '95014', 'sort' => 'oops'));
  308. $this->fail('Expected Zend_Service_Exception not thrown');
  309. } catch (Zend_Service_Exception $e) {
  310. $this->assertContains("option 'sort'", $e->getMessage());
  311. }
  312. }
  313. /**
  314. * Ensures that newsSearch() throws an exception when the results option is invalid
  315. *
  316. * @return void
  317. */
  318. public function testNewsSearchExceptionResultsInvalid()
  319. {
  320. try {
  321. $this->_yahoo->newsSearch('php', array('results' => 51));
  322. $this->fail('Expected Zend_Service_Exception not thrown');
  323. } catch (Zend_Service_Exception $e) {
  324. $this->assertContains("option 'results'", $e->getMessage());
  325. }
  326. }
  327. /**
  328. * Ensures that newsSearch() throws an exception when the start option is invalid
  329. *
  330. * @return void
  331. */
  332. public function testNewsSearchExceptionStartInvalid()
  333. {
  334. try {
  335. $this->_yahoo->newsSearch('php', array('start' => 'oops'));
  336. $this->fail('Expected Zend_Service_Exception not thrown');
  337. } catch (Zend_Service_Exception $e) {
  338. $this->assertContains("option 'start'", $e->getMessage());
  339. }
  340. }
  341. /**
  342. * Ensures that newsSearch() throws an exception when the language option is invalid
  343. *
  344. * @return void
  345. */
  346. public function testNewsSearchExceptionLanguageInvalid()
  347. {
  348. try {
  349. $this->_yahoo->newsSearch('php', array('language' => 'oops'));
  350. $this->fail('Expected Zend_Service_Exception not thrown');
  351. } catch (Zend_Service_Exception $e) {
  352. $this->assertContains('selected language', $e->getMessage());
  353. }
  354. }
  355. /**
  356. * Ensures that pageDataSearch() throws an exception when the results option is invalid
  357. *
  358. * @return void
  359. */
  360. public function testPageDataSearchExceptionResultsInvalid()
  361. {
  362. try {
  363. $this->_yahoo->pageDataSearch('http://framework.zend.com/', array('results' => 101));
  364. $this->fail('Expected Zend_Service_Exception not thrown');
  365. } catch (Zend_Service_Exception $e) {
  366. $this->assertContains("option 'results'", $e->getMessage());
  367. }
  368. }
  369. /**
  370. * Ensures that pageDataSearch() throws an exception when the start option is invalid
  371. *
  372. * @return void
  373. */
  374. public function testPageDataSearchExceptionStartInvalid()
  375. {
  376. try {
  377. $this->_yahoo->pageDataSearch('http://framework.zend.com/', array('start' => 1001));
  378. $this->fail('Expected Zend_Service_Exception not thrown');
  379. } catch (Zend_Service_Exception $e) {
  380. $this->assertContains("option 'start'", $e->getMessage());
  381. }
  382. }
  383. /**
  384. * Ensures that videoSearch() throws an exception when the type option is invalid
  385. *
  386. * @return void
  387. */
  388. public function testVideoSearchExceptionTypeInvalid()
  389. {
  390. try {
  391. $this->_yahoo->videoSearch('php', array('type' => 'oops'));
  392. $this->fail('Expected Zend_Service_Exception not thrown');
  393. } catch (Zend_Service_Exception $e) {
  394. $this->assertContains("option 'type'", $e->getMessage());
  395. }
  396. }
  397. /**
  398. * Ensures that videoSearch() throws an exception when the results option is invalid
  399. *
  400. * @return void
  401. */
  402. public function testVideoSearchExceptionResultsInvalid()
  403. {
  404. try {
  405. $this->_yahoo->videoSearch('php', array('results' => 500));
  406. $this->fail('Expected Zend_Service_Exception not thrown');
  407. } catch (Zend_Service_Exception $e) {
  408. $this->assertContains("option 'results'", $e->getMessage());
  409. }
  410. }
  411. /**
  412. * Ensures that videoSearch() throws an exception when the start option is invalid
  413. *
  414. * @return void
  415. */
  416. public function testVideoSearchExceptionStartInvalid()
  417. {
  418. try {
  419. $this->_yahoo->videoSearch('php', array('start' => 1001));
  420. $this->fail('Expected Zend_Service_Exception not thrown');
  421. } catch (Zend_Service_Exception $e) {
  422. $this->assertContains("option 'start'", $e->getMessage());
  423. }
  424. }
  425. /**
  426. * Ensures that videoSearch() throws an exception when the format option is invalid
  427. *
  428. * @return void
  429. */
  430. public function testVideoSearchExceptionFormatInvalid()
  431. {
  432. try {
  433. $this->_yahoo->videoSearch('php', array('format' => 'oops'));
  434. $this->fail('Expected Zend_Service_Exception not thrown');
  435. } catch (Zend_Service_Exception $e) {
  436. $this->assertContains("option 'format'", $e->getMessage());
  437. }
  438. }
  439. /**
  440. * Ensures that webSearch() throws an exception when the results option is invalid
  441. *
  442. * @return void
  443. */
  444. public function testWebSearchExceptionResultsInvalid()
  445. {
  446. try {
  447. $this->_yahoo->webSearch('php', array('results' => 101));
  448. $this->fail('Expected Zend_Service_Exception not thrown');
  449. } catch (Zend_Service_Exception $e) {
  450. $this->assertContains("option 'results'", $e->getMessage());
  451. }
  452. }
  453. /**
  454. * Ensures that webSearch() throws an exception when the start option is invalid
  455. *
  456. * @return void
  457. */
  458. public function testWebSearchExceptionStartInvalid()
  459. {
  460. try {
  461. $this->_yahoo->webSearch('php', array('start' => 'oops'));
  462. $this->fail('Expected Zend_Service_Exception not thrown');
  463. } catch (Zend_Service_Exception $e) {
  464. $this->assertContains("option 'start'", $e->getMessage());
  465. }
  466. }
  467. /**
  468. * Ensures that webSearch() throws an exception when the start option is invalid
  469. *
  470. * @return void
  471. */
  472. public function testWebSearchExceptionOptionInvalid()
  473. {
  474. try {
  475. $this->_yahoo->webSearch('php', array('oops' => 'oops'));
  476. $this->fail('Expected Zend_Service_Exception not thrown');
  477. } catch (Zend_Service_Exception $e) {
  478. $this->assertContains('parameters are invalid', $e->getMessage());
  479. }
  480. }
  481. /**
  482. * Ensures that webSearch() throws an exception when the type option is invalid
  483. *
  484. * @return void
  485. */
  486. public function testWebSearchExceptionTypeInvalid()
  487. {
  488. try {
  489. $this->_yahoo->webSearch('php', array('type' => 'oops'));
  490. $this->fail('Expected Zend_Service_Exception not thrown');
  491. } catch (Zend_Service_Exception $e) {
  492. $this->assertContains("option 'type'", $e->getMessage());
  493. }
  494. }
  495. /**
  496. * WebResult should check if the result has a Cache section or not
  497. *
  498. * @group ZF-3636
  499. */
  500. public function testWebResultCache(){
  501. // create empty result eg. without cache section
  502. $domDoc = new DOMDocument();
  503. $element = $domDoc->createElement('Result');
  504. // this should not result in errors
  505. $webResult = new Zend_Service_Yahoo_WebResult($element);
  506. }
  507. }
  508. class Zend_Service_Yahoo_OfflineTest_ResultSet extends Zend_Service_Yahoo_ResultSet
  509. {
  510. protected $_namespace = '';
  511. }