OfflineTest.php 17 KB

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