OfflineTest.php 17 KB

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