TechnoratiTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  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_Technorati
  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. * Test helper
  24. */
  25. require_once dirname(__FILE__) . DIRECTORY_SEPARATOR .'TestCase.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Service_Technorati
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Service
  33. * @group Zend_Service_Technorati
  34. */
  35. class Zend_Service_Technorati_TechnoratiTest extends Zend_Service_Technorati_TestCase
  36. {
  37. const TEST_APY_KEY = 'somevalidapikey';
  38. const TEST_PARAM_COSMOS = 'http://www.simonecarletti.com/blog/';
  39. const TEST_PARAM_SEARCH = 'google';
  40. const TEST_PARAM_TAG = 'google';
  41. const TEST_PARAM_DAILYCOUNT = 'google';
  42. const TEST_PARAM_GETINFO = 'weppos';
  43. const TEST_PARAM_BLOGINFO = 'http://www.simonecarletti.com/blog/';
  44. const TEST_PARAM_BLOGPOSTTAGS = 'http://www.simonecarletti.com/blog/';
  45. public function setUp()
  46. {
  47. /**
  48. * @see Zend_Http_Client_Adapter_Test
  49. */
  50. require_once 'Zend/Http/Client/Adapter/Test.php';
  51. $adapter = new Zend_Http_Client_Adapter_Test();
  52. /**
  53. * @see Zend_Http_Client
  54. */
  55. require_once 'Zend/Http/Client.php';
  56. $client = new Zend_Http_Client(Zend_Service_Technorati::API_URI_BASE, array(
  57. 'adapter' => $adapter
  58. ));
  59. $this->technorati = new Zend_Service_Technorati(self::TEST_APY_KEY);
  60. $this->adapter = $adapter;
  61. $this->technorati->getRestClient()->setHttpClient($client);
  62. }
  63. public function testConstruct()
  64. {
  65. $this->_testConstruct('Zend_Service_Technorati', array(self::TEST_APY_KEY));
  66. }
  67. public function testApiKeyMatches()
  68. {
  69. $object = $this->technorati;
  70. $this->assertEquals(self::TEST_APY_KEY, $object->getApiKey());
  71. }
  72. public function testSetGetApiKey()
  73. {
  74. $object = $this->technorati;
  75. $set = 'just a test';
  76. $get = $object->setApiKey($set)->getApiKey();
  77. $this->assertEquals($set, $get);
  78. }
  79. public function testCosmos()
  80. {
  81. $result = $this->_setResponseFromFile('TestCosmosSuccess.xml')->cosmos(self::TEST_PARAM_COSMOS);
  82. $this->assertTrue($result instanceof Zend_Service_Technorati_CosmosResultSet);
  83. $this->assertEquals(2, $result->totalResults());
  84. $result->seek(0);
  85. $this->assertTrue($result->current() instanceof Zend_Service_Technorati_CosmosResult);
  86. // content is validated in Zend_Service_Technorati_CosmosResultSet tests
  87. }
  88. public function testCosmosThrowsExceptionWithError()
  89. {
  90. try {
  91. $this->_setResponseFromFile('TestCosmosError.xml')->cosmos(self::TEST_PARAM_COSMOS);
  92. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  93. } catch (Zend_Service_Technorati_Exception $e) {
  94. $this->assertContains("Invalid request: url is required", $e->getMessage());
  95. }
  96. }
  97. public function testCosmosThrowsExceptionWithInvalidUrl()
  98. {
  99. // url is mandatory --> validated by PHP interpreter
  100. // url must not be empty
  101. $this->_testThrowsExceptionWithInvalidMandatoryOption('cosmos', 'url');
  102. }
  103. public function testCosmosThrowsExceptionWithInvalidOption()
  104. {
  105. $options = array(
  106. array('type' => 'foo'),
  107. array('limit' => 'foo'),
  108. array('limit' => 0),
  109. array('limit' => 101),
  110. array('start' => 0),
  111. // 'current' => // cast to int
  112. // 'claim' => // cast to int
  113. // 'highlight' => // cast to int
  114. );
  115. $this->_testThrowsExceptionWithInvalidOption($options, 'TestCosmosSuccess.xml', 'cosmos', array(self::TEST_PARAM_COSMOS));
  116. }
  117. public function testCosmosOption()
  118. {
  119. $options = array(
  120. array('type' => 'link'),
  121. array('type' => 'weblog'),
  122. array('limit' => 1),
  123. array('limit' => 50),
  124. array('limit' => 100),
  125. array('start' => 1),
  126. array('start' => 1000),
  127. array('current' => false), // cast to int
  128. array('current' => 0), // cast to int
  129. array('claim' => false), // cast to int
  130. array('claim' => 0), // cast to int
  131. array('highlight' => false), // cast to int
  132. array('highlight' => 0), // cast to int
  133. );
  134. $this->_testOption($options, 'TestCosmosSuccess.xml', 'cosmos', array(self::TEST_PARAM_COSMOS));
  135. }
  136. public function testSearch()
  137. {
  138. $result = $this->_setResponseFromFile('TestSearchSuccess.xml')->search(self::TEST_PARAM_SEARCH);
  139. $this->assertTrue($result instanceof Zend_Service_Technorati_SearchResultSet);
  140. $this->assertEquals(2, $result->totalResults());
  141. $result->seek(0);
  142. $this->assertTrue($result->current() instanceof Zend_Service_Technorati_SearchResult);
  143. // content is validated in Zend_Service_Technorati_SearchResultSet tests
  144. }
  145. /**
  146. * @see /_files/MISSING
  147. *
  148. public function testSearchThrowsExceptionWithError()
  149. {
  150. try {
  151. $this->_setResponseFromFile('TestSearchError.xml')->cosmos(self::TEST_PARAM_COSMOS);
  152. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  153. } catch (Zend_Service_Technorati_Exception $e) {
  154. $this->assertContains("Invalid request: url is required", $e->getMessage());
  155. }
  156. } */
  157. public function testSearchThrowsExceptionWithInvalidQuery()
  158. {
  159. // query is mandatory --> validated by PHP interpreter
  160. // query must not be empty
  161. $this->_testThrowsExceptionWithInvalidMandatoryOption('search', 'query');
  162. }
  163. public function testSearchThrowsExceptionWithInvalidOption()
  164. {
  165. $options = array(
  166. array('authority' => 'foo'),
  167. array('limit' => 'foo'),
  168. array('limit' => 0),
  169. array('limit' => 101),
  170. array('start' => 0),
  171. // 'claim' => // cast to int
  172. );
  173. $this->_testThrowsExceptionWithInvalidOption($options, 'TestSearchSuccess.xml', 'search', array(self::TEST_PARAM_SEARCH));
  174. }
  175. public function testSearchOption()
  176. {
  177. $options = array(
  178. array('language' => 'en'), // not validated
  179. array('authority' => 'n'),
  180. array('authority' => 'a1'),
  181. array('authority' => 'a4'),
  182. array('authority' => 'a7'),
  183. array('limit' => 1),
  184. array('limit' => 50),
  185. array('limit' => 100),
  186. array('start' => 1),
  187. array('start' => 1000),
  188. array('claim' => false), // cast to int
  189. array('claim' => 0), // cast to int
  190. );
  191. $this->_testOption($options, 'TestSearchSuccess.xml', 'search', array(self::TEST_PARAM_SEARCH));
  192. }
  193. public function testTag()
  194. {
  195. $result = $this->_setResponseFromFile('TestTagSuccess.xml')->tag(self::TEST_PARAM_TAG);
  196. $this->assertTrue($result instanceof Zend_Service_Technorati_TagResultSet);
  197. $this->assertEquals(2, $result->totalResults());
  198. $result->seek(0);
  199. $this->assertTrue($result->current() instanceof Zend_Service_Technorati_TagResult);
  200. // content is validated in Zend_Service_Technorati_TagResultSet tests
  201. }
  202. public function testTagThrowsExceptionWithError()
  203. {
  204. try {
  205. $this->_setResponseFromFile('TestTagError.xml')->tag(self::TEST_PARAM_TAG);
  206. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  207. } catch (Zend_Service_Technorati_Exception $e) {
  208. $this->assertContains("Invalid request.", $e->getMessage());
  209. }
  210. }
  211. public function testTagThrowsExceptionWithInvalidTag()
  212. {
  213. // tag is mandatory --> validated by PHP interpreter
  214. // tag must not be empty
  215. $this->_testThrowsExceptionWithInvalidMandatoryOption('tag', 'tag');
  216. }
  217. public function testTagThrowsExceptionWithInvalidOption()
  218. {
  219. $options = array(
  220. array('limit' => 'foo'),
  221. array('limit' => 0),
  222. array('limit' => 101),
  223. array('start' => 0),
  224. // 'excerptsize' => // cast to int
  225. // 'topexcerptsize' => // cast to int
  226. );
  227. $this->_testThrowsExceptionWithInvalidOption($options, 'TestTagSuccess.xml', 'tag', array(self::TEST_PARAM_TAG));
  228. }
  229. public function testTagOption()
  230. {
  231. $options = array(
  232. array('excerptsize' => 150), // cast to int
  233. array('excerptsize' => '150'), // cast to int
  234. array('topexcerptsize' => 150), // cast to int
  235. array('topexcerptsize' => '150'), // cast to int
  236. array('limit' => 1),
  237. array('limit' => 50),
  238. array('limit' => 100),
  239. array('start' => 1),
  240. array('start' => 1000),
  241. );
  242. $this->_testOption($options, 'TestTagSuccess.xml', 'tag', array(self::TEST_PARAM_TAG));
  243. }
  244. public function testDailyCounts()
  245. {
  246. $result = $this->_setResponseFromFile('TestDailyCountsSuccess.xml')->dailyCounts(self::TEST_PARAM_DAILYCOUNT);
  247. $this->assertTrue($result instanceof Zend_Service_Technorati_DailyCountsResultSet);
  248. $this->assertEquals(180, $result->totalResults());
  249. $result->seek(0);
  250. $this->assertTrue($result->current() instanceof Zend_Service_Technorati_DailyCountsResult);
  251. // content is validated in Zend_Service_Technorati_DailyCountsResultSet tests
  252. }
  253. public function testDailyCountsThrowsExceptionWithError()
  254. {
  255. try {
  256. $this->_setResponseFromFile('TestDailyCountsError.xml')->dailyCounts(self::TEST_PARAM_DAILYCOUNT);
  257. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  258. } catch (Zend_Service_Technorati_Exception $e) {
  259. $this->assertContains("Missing required parameter", $e->getMessage());
  260. }
  261. }
  262. public function testDailyCountsThrowsExceptionWithInvalidQuery()
  263. {
  264. // q is mandatory --> validated by PHP interpreter
  265. // q must not be empty
  266. $this->_testThrowsExceptionWithInvalidMandatoryOption('dailyCounts', 'q');
  267. }
  268. public function testDailyCountsThrowsExceptionWithInvalidOption()
  269. {
  270. $options = array(
  271. array('days' => 0),
  272. array('days' => '0'),
  273. array('days' => 181),
  274. array('days' => '181'),
  275. );
  276. $this->_testThrowsExceptionWithInvalidOption($options, 'TestDailyCountsSuccess.xml', 'dailyCounts', array(self::TEST_PARAM_DAILYCOUNT));
  277. }
  278. public function testDailyCountsOption()
  279. {
  280. $options = array(
  281. array('days' => 120), // cast to int
  282. array('days' => '120'), // cast to int
  283. array('days' => 180), // cast to int
  284. array('days' => '180'), // cast to int
  285. );
  286. $this->_testOption($options, 'TestDailyCountsSuccess.xml', 'dailyCounts', array(self::TEST_PARAM_DAILYCOUNT));
  287. }
  288. public function testBlogInfo()
  289. {
  290. $result = $this->_setResponseFromFile('TestBlogInfoSuccess.xml')->blogInfo(self::TEST_PARAM_BLOGINFO);
  291. $this->assertTrue($result instanceof Zend_Service_Technorati_BlogInfoResult);
  292. // content is validated in Zend_Service_Technorati_BlogInfoResult tests
  293. }
  294. public function testBlogInfoThrowsExceptionWithError()
  295. {
  296. try {
  297. $this->_setResponseFromFile('TestBlogInfoError.xml')->blogInfo(self::TEST_PARAM_BLOGINFO);
  298. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  299. } catch (Zend_Service_Technorati_Exception $e) {
  300. $this->assertContains("Invalid request: url is required", $e->getMessage());
  301. }
  302. }
  303. public function testBlogInfoThrowsExceptionWithInvalidUrl()
  304. {
  305. // url is mandatory --> validated by PHP interpreter
  306. // url must not be empty
  307. $this->_testThrowsExceptionWithInvalidMandatoryOption('blogInfo', 'url');
  308. }
  309. public function testBlogInfoThrowsExceptionWithUrlNotWeblog()
  310. {
  311. // emulate Technorati exception
  312. // when URL is not a recognized weblog
  313. try {
  314. $this->_setResponseFromFile('TestBlogInfoErrorUrlNotWeblog.xml')->blogInfo('www.simonecarletti.com');
  315. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  316. } catch (Zend_Service_Technorati_Exception $e) {
  317. $this->assertContains("Technorati weblog", $e->getMessage());
  318. }
  319. }
  320. public function testBlogPostTags()
  321. {
  322. $result = $this->_setResponseFromFile('TestBlogPostTagsSuccess.xml')->blogPostTags(self::TEST_PARAM_BLOGPOSTTAGS);
  323. $this->assertTrue($result instanceof Zend_Service_Technorati_TagsResultSet);
  324. // content is validated in Zend_Service_Technorati_TagsResultSet tests
  325. }
  326. public function testBlogPostTagsThrowsExceptionWithError()
  327. {
  328. try {
  329. $this->_setResponseFromFile('TestBlogPostTagsError.xml')->blogPostTags(self::TEST_PARAM_BLOGPOSTTAGS);
  330. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  331. } catch (Zend_Service_Technorati_Exception $e) {
  332. $this->assertContains("Invalid request: url is required", $e->getMessage());
  333. }
  334. }
  335. public function testBlogPostTagsThrowsExceptionWithInvalidUrl()
  336. {
  337. // url is mandatory --> validated by PHP interpreter
  338. // url must not be empty
  339. $this->_testThrowsExceptionWithInvalidMandatoryOption('blogPostTags', 'url');
  340. }
  341. public function testBlogPostTagsThrowsExceptionWithInvalidOption()
  342. {
  343. $options = array(
  344. array('limit' => 'foo'),
  345. array('limit' => 0),
  346. array('limit' => 101),
  347. array('start' => 0),
  348. );
  349. $this->_testThrowsExceptionWithInvalidOption($options, 'TestBlogPostTagsSuccess.xml', 'blogPostTags', array(self::TEST_PARAM_BLOGPOSTTAGS));
  350. }
  351. public function testBlogPostTagsOption()
  352. {
  353. $options = array(
  354. array('limit' => 1),
  355. array('limit' => 50),
  356. array('limit' => 100),
  357. array('start' => 1),
  358. array('start' => 1000),
  359. );
  360. $this->_testOption($options, 'TestBlogPostTagsSuccess.xml', 'blogPostTags', array(self::TEST_PARAM_BLOGPOSTTAGS));
  361. }
  362. public function testTopTags()
  363. {
  364. $result = $this->_setResponseFromFile('TestTopTagsSuccess.xml')->topTags();
  365. $this->assertTrue($result instanceof Zend_Service_Technorati_TagsResultSet);
  366. // content is validated in Zend_Service_Technorati_TagsResultSet tests
  367. }
  368. public function testTopTagsThrowsExceptionWithError()
  369. {
  370. try {
  371. $this->_setResponseFromFile('TestTopTagsError.xml')->topTags();
  372. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  373. } catch (Zend_Service_Technorati_Exception $e) {
  374. $this->assertContains("Invalid key.", $e->getMessage());
  375. }
  376. }
  377. public function testTopTagsThrowsExceptionWithInvalidOption()
  378. {
  379. $options = array(
  380. array('limit' => 'foo'),
  381. array('limit' => 0),
  382. array('limit' => 101),
  383. array('start' => 0),
  384. );
  385. $this->_testThrowsExceptionWithInvalidOption($options, 'TestTopTagsSuccess.xml', 'topTags');
  386. }
  387. public function testTopTagsOption()
  388. {
  389. $options = array(
  390. array('limit' => 1),
  391. array('limit' => 50),
  392. array('limit' => 100),
  393. array('start' => 1),
  394. array('start' => 1000),
  395. );
  396. $this->_testOption($options, 'TestTopTagsSuccess.xml', 'topTags');
  397. }
  398. public function testGetInfo()
  399. {
  400. $result = $this->_setResponseFromFile('TestGetInfoSuccess.xml')->getInfo(self::TEST_PARAM_GETINFO);
  401. $this->assertTrue($result instanceof Zend_Service_Technorati_GetInfoResult);
  402. // content is validated in Zend_Service_Technorati_GetInfoResult tests
  403. }
  404. public function testGetInfoThrowsExceptionWithError()
  405. {
  406. try {
  407. $this->_setResponseFromFile('TestGetInfoError.xml')->getInfo(self::TEST_PARAM_GETINFO);
  408. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  409. } catch (Zend_Service_Technorati_Exception $e) {
  410. $this->assertContains("Username is a required field.", $e->getMessage());
  411. }
  412. }
  413. public function testGetInfoThrowsExceptionWithInvalidUsername()
  414. {
  415. // username is mandatory --> validated by PHP interpreter
  416. // username must not be empty
  417. $this->_testThrowsExceptionWithInvalidMandatoryOption('getInfo', 'username');
  418. }
  419. public function testKeyInfo()
  420. {
  421. $result = $this->_setResponseFromFile('TestKeyInfoSuccess.xml')->keyInfo();
  422. $this->assertTrue($result instanceof Zend_Service_Technorati_KeyInfoResult);
  423. // content is validated in Zend_Service_Technorati_KeyInfoResult tests
  424. }
  425. public function testKeyInfoThrowsExceptionWithError()
  426. {
  427. try {
  428. $this->_setResponseFromFile('TestKeyInfoError.xml')->keyInfo();
  429. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  430. } catch (Zend_Service_Technorati_Exception $e) {
  431. $this->assertContains("Invalid key.", $e->getMessage());
  432. }
  433. }
  434. public function testAllThrowsExceptionWithInvalidOptionFormat()
  435. {
  436. $invalidFormatOption = array('format' => 'rss');
  437. // format must be XML
  438. $methods = array('cosmos' => self::TEST_PARAM_COSMOS,
  439. 'search' => self::TEST_PARAM_SEARCH,
  440. 'tag' => self::TEST_PARAM_TAG,
  441. 'dailyCounts' => self::TEST_PARAM_DAILYCOUNT,
  442. 'topTags' => null,
  443. 'blogInfo' => self::TEST_PARAM_BLOGINFO,
  444. 'blogPostTags' => self::TEST_PARAM_BLOGPOSTTAGS,
  445. 'getInfo' => self::TEST_PARAM_GETINFO);
  446. $technorati = $this->technorati;
  447. foreach ($methods as $method => $param) {
  448. $options = array_merge((array) $param, array($invalidFormatOption));
  449. try {
  450. call_user_func_array(array($technorati, $method), $options);
  451. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  452. } catch (Zend_Service_Technorati_Exception $e) {
  453. $this->assertContains("'format'", $e->getMessage());
  454. }
  455. }
  456. }
  457. public function testAllThrowsExceptionWithUnknownOption()
  458. {
  459. $invalidOption = array('foo' => 'bar');
  460. $methods = array('cosmos' => self::TEST_PARAM_COSMOS,
  461. 'search' => self::TEST_PARAM_SEARCH,
  462. 'tag' => self::TEST_PARAM_TAG,
  463. 'dailyCounts' => self::TEST_PARAM_DAILYCOUNT,
  464. 'topTags' => null,
  465. 'blogInfo' => self::TEST_PARAM_BLOGINFO,
  466. 'blogPostTags' => self::TEST_PARAM_BLOGPOSTTAGS,
  467. 'getInfo' => self::TEST_PARAM_GETINFO);
  468. $technorati = $this->technorati;
  469. foreach ($methods as $method => $param) {
  470. $options = array_merge((array) $param, array($invalidOption));
  471. try {
  472. call_user_func_array(array($technorati, $method), $options);
  473. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  474. } catch (Zend_Service_Technorati_Exception $e) {
  475. $this->assertContains("'foo'", $e->getMessage());
  476. }
  477. }
  478. }
  479. /**
  480. * Tests whether $callbackMethod method throws an Exception
  481. * with Invalid Url.
  482. *
  483. * @param string $callbackMethod
  484. */
  485. private function _testThrowsExceptionWithInvalidMandatoryOption($callbackMethod, $name)
  486. {
  487. try {
  488. $this->technorati->$callbackMethod('');
  489. $this->fail('Expected Zend_Service_Technorati_Exception not thrown');
  490. } catch (Zend_Service_Technorati_Exception $e) {
  491. $this->assertContains("'$name'", $e->getMessage());
  492. }
  493. }
  494. /**
  495. * Tests whether for each $validOptions a method call is successful.
  496. *
  497. * @param array $validOptions
  498. * @param string $xmlFile
  499. * @param string $callbackMethod
  500. * @param null|array $callbackRequiredOptions
  501. */
  502. private function _testOption($validOptions, $xmlFile, $callbackMethod, $callbackRequiredOptions = null)
  503. {
  504. $technorati = $this->_setResponseFromFile($xmlFile);
  505. foreach ($validOptions as $pair) {
  506. list($option, $value) = each($pair);
  507. $options = is_array($callbackRequiredOptions) ?
  508. array_merge($callbackRequiredOptions, array($pair)) :
  509. array($pair);
  510. try {
  511. call_user_func_array(array($technorati, $callbackMethod), $options);
  512. } catch (Zend_Service_Technorati_Exception $e) {
  513. $this->fail("Exception " . $e->getMessage() . " thrown " .
  514. "for option '$option' value '$value'");
  515. }
  516. }
  517. }
  518. /**
  519. * Tests whether for each $validOptions a method call is successful.
  520. *
  521. * @param array $invalidOptions
  522. * @param string $xmlFile
  523. * @param string $callbackMethod
  524. * @param null|array $callbackRequiredOptions
  525. */
  526. private function _testThrowsExceptionWithInvalidOption($invalidOptions, $xmlFile, $callbackMethod, $callbackRequiredOptions = null)
  527. {
  528. $technorati = $this->_setResponseFromFile($xmlFile);
  529. foreach ($invalidOptions as $pair) {
  530. list($option, $value) = each($pair);
  531. $options = is_array($callbackRequiredOptions) ?
  532. array_merge($callbackRequiredOptions, array($pair)) :
  533. array($pair);
  534. try {
  535. call_user_func_array(array($technorati, $callbackMethod), $options);
  536. $this->fail("Expected Zend_Service_Technorati_Exception not thrown " .
  537. "for option '$option' value '$value'");
  538. } catch (Zend_Service_Technorati_Exception $e) {
  539. $this->assertContains("'$option'", $e->getMessage());
  540. }
  541. }
  542. }
  543. /**
  544. * Loads a response content from a test case file
  545. * and sets the content to current Test Adapter.
  546. *
  547. * Returns current Zend_Service_Technorati instance
  548. * to let developers use the powerful chain call.
  549. *
  550. * Do not execute any file validation. Please use this method carefully.
  551. *
  552. * @params string $file
  553. * @return Zend_Service_Technorati
  554. */
  555. private function _setResponseFromFile($file)
  556. {
  557. $response = "HTTP/1.0 200 OK\r\n"
  558. . "Date: " . date(DATE_RFC1123) . "\r\n"
  559. . "Server: Apache\r\n"
  560. . "Cache-Control: max-age=60\r\n"
  561. . "Content-Type: text/xml; charset=UTF-8\r\n"
  562. . "X-Powered-By: PHP/5.2.1\r\n"
  563. . "Connection: close\r\n"
  564. . "\r\n"
  565. . file_get_contents(dirname(__FILE__) . '/_files/' . $file) ;
  566. $this->adapter->setResponse($response);
  567. return $this->technorati; // allow chain call
  568. }
  569. }