TechnoratiTest.php 24 KB

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