PageRenderTime 59ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Joomla/Twitter/Tests/ListsTest.php

https://github.com/piotr-cz/joomla-framework
PHP | 2335 lines | 1562 code | 315 blank | 458 comment | 80 complexity | 3ecffc6e759f3dffcd8f987707fe753c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  4. * @license GNU General Public License version 2 or later; see LICENSE
  5. */
  6. namespace Joomla\Twitter\Tests;
  7. use Joomla\Twitter\Lists;
  8. use \DomainException;
  9. use \RuntimeException;
  10. use \stdClass;
  11. require_once __DIR__ . '/case/TwitterTestCase.php';
  12. /**
  13. * Test class for Twitter Lists.
  14. *
  15. * @since 1.0
  16. */
  17. class ListsTest extends TwitterTestCase
  18. {
  19. /**
  20. * @var string Sample JSON error message.
  21. * @since 12.3
  22. */
  23. protected $errorString = '{"error":"Generic error"}';
  24. /**
  25. * @var string Sample JSON string.
  26. * @since 1.0
  27. */
  28. protected $rateLimit = '{"resources": {"lists": {
  29. "/lists/list": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  30. "/lists/statuses": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  31. "/lists/subscribers": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  32. "/lists/subscribers/create": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  33. "/lists/members/show": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  34. "/lists/subscribers/show": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  35. "/lists/subscribers/destroy": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  36. "/lists/members/create_all": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  37. "/lists/members": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  38. "/lists/show": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  39. "/lists/subscriptions": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  40. "/lists/update": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  41. "/lists/create": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"},
  42. "/lists/destroy": {"remaining":15, "reset":"Mon Jun 25 17:20:53 +0000 2012"}
  43. }}}';
  44. /**
  45. * Sets up the fixture, for example, opens a network connection.
  46. * This method is called before a test is executed.
  47. *
  48. * @access protected
  49. *
  50. * @return void
  51. */
  52. protected function setUp()
  53. {
  54. parent::setUp();
  55. $this->object = new Lists($this->options, $this->client, $this->oauth);
  56. }
  57. /**
  58. * Provides test data for request format detection.
  59. *
  60. * @return array
  61. *
  62. * @since 1.0
  63. */
  64. public function seedUser()
  65. {
  66. // User ID or screen name
  67. return array(
  68. array(234654235457),
  69. array('testUser'),
  70. array(null)
  71. );
  72. }
  73. /**
  74. * Tests the getAllLists method
  75. *
  76. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  77. *
  78. * @return void
  79. *
  80. * @since 1.0
  81. * @dataProvider seedUser
  82. */
  83. public function testGetLists($user)
  84. {
  85. $reverse = true;
  86. $returnData = new stdClass;
  87. $returnData->code = 200;
  88. $returnData->body = $this->rateLimit;
  89. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  90. $this->client->expects($this->at(0))
  91. ->method('get')
  92. ->with($path)
  93. ->will($this->returnValue($returnData));
  94. $returnData = new stdClass;
  95. $returnData->code = 200;
  96. $returnData->body = $this->sampleString;
  97. // Set request parameters.
  98. if (is_numeric($user))
  99. {
  100. $data['user_id'] = $user;
  101. }
  102. elseif (is_string($user))
  103. {
  104. $data['screen_name'] = $user;
  105. }
  106. else
  107. {
  108. $this->setExpectedException('RuntimeException');
  109. $this->object->getLists($user);
  110. }
  111. $data['reverse'] = true;
  112. $path = $this->object->fetchUrl('/lists/list.json', $data);
  113. $this->client->expects($this->at(1))
  114. ->method('get')
  115. ->with($path)
  116. ->will($this->returnValue($returnData));
  117. $this->assertThat(
  118. $this->object->getLists($user, $reverse),
  119. $this->equalTo(json_decode($this->sampleString))
  120. );
  121. }
  122. /**
  123. * Tests the getAllLists method - failure
  124. *
  125. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  126. *
  127. * @return void
  128. *
  129. * @since 1.0
  130. * @dataProvider seedUser
  131. * @expectedException DomainException
  132. */
  133. public function testGetListsFailure($user)
  134. {
  135. $returnData = new stdClass;
  136. $returnData->code = 200;
  137. $returnData->body = $this->rateLimit;
  138. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  139. $this->client->expects($this->at(0))
  140. ->method('get')
  141. ->with($path)
  142. ->will($this->returnValue($returnData));
  143. $returnData = new stdClass;
  144. $returnData->code = 500;
  145. $returnData->body = $this->errorString;
  146. // Set request parameters.
  147. if (is_numeric($user))
  148. {
  149. $data['user_id'] = $user;
  150. }
  151. elseif (is_string($user))
  152. {
  153. $data['screen_name'] = $user;
  154. }
  155. else
  156. {
  157. $this->setExpectedException('RuntimeException');
  158. $this->object->getLists($user);
  159. }
  160. $path = $this->object->fetchUrl('/lists/list.json', $data);
  161. $this->client->expects($this->at(1))
  162. ->method('get')
  163. ->with($path)
  164. ->will($this->returnValue($returnData));
  165. $this->object->getLists($user);
  166. }
  167. /**
  168. * Provides test data for request format detection.
  169. *
  170. * @return array
  171. *
  172. * @since 1.0
  173. */
  174. public function seedListStatuses()
  175. {
  176. // List ID or slug and owner
  177. return array(
  178. array(234654235457, null),
  179. array('test-list', 'testUser'),
  180. array('test-list', 12345),
  181. array('test-list', null),
  182. array(null, null)
  183. );
  184. }
  185. /**
  186. * Tests the getListStatuses method
  187. *
  188. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  189. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  190. *
  191. * @return void
  192. *
  193. * @since 1.0
  194. * @dataProvider seedListStatuses
  195. */
  196. public function testGetStatuses($list, $owner)
  197. {
  198. $since_id = 12345;
  199. $max_id = 54321;
  200. $count = 10;
  201. $entities = true;
  202. $include_rts = true;
  203. $returnData = new stdClass;
  204. $returnData->code = 200;
  205. $returnData->body = $this->rateLimit;
  206. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  207. $this->client->expects($this->at(0))
  208. ->method('get')
  209. ->with($path)
  210. ->will($this->returnValue($returnData));
  211. $returnData = new stdClass;
  212. $returnData->code = 200;
  213. $returnData->body = $this->sampleString;
  214. // Set request parameters.
  215. if (is_numeric($list))
  216. {
  217. $data['list_id'] = $list;
  218. }
  219. elseif (is_string($list))
  220. {
  221. $data['slug'] = $list;
  222. if (is_numeric($owner))
  223. {
  224. $data['owner_id'] = $owner;
  225. }
  226. elseif (is_string($owner))
  227. {
  228. $data['owner_screen_name'] = $owner;
  229. }
  230. else
  231. {
  232. // We don't have a valid entry
  233. $this->setExpectedException('RuntimeException');
  234. $this->object->getStatuses($list, $owner);
  235. }
  236. }
  237. else
  238. {
  239. $this->setExpectedException('RuntimeException');
  240. $this->object->getStatuses($list, $owner);
  241. }
  242. $data['since_id'] = $since_id;
  243. $data['max_id'] = $max_id;
  244. $data['count'] = $count;
  245. $data['include_entities'] = $entities;
  246. $data['include_rts'] = $include_rts;
  247. $path = $this->object->fetchUrl('/lists/statuses.json', $data);
  248. $this->client->expects($this->at(1))
  249. ->method('get')
  250. ->with($path)
  251. ->will($this->returnValue($returnData));
  252. $this->assertThat(
  253. $this->object->getStatuses($list, $owner, $since_id, $max_id, $count, $entities, $include_rts),
  254. $this->equalTo(json_decode($this->sampleString))
  255. );
  256. }
  257. /**
  258. * Tests the getListStatuses method - failure
  259. *
  260. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  261. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  262. *
  263. * @return void
  264. *
  265. * @since 1.0
  266. * @dataProvider seedListStatuses
  267. * @expectedException DomainException
  268. */
  269. public function testGetStatusesFailure($list, $owner)
  270. {
  271. $returnData = new stdClass;
  272. $returnData->code = 200;
  273. $returnData->body = $this->rateLimit;
  274. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  275. $this->client->expects($this->at(0))
  276. ->method('get')
  277. ->with($path)
  278. ->will($this->returnValue($returnData));
  279. $returnData = new stdClass;
  280. $returnData->code = 500;
  281. $returnData->body = $this->errorString;
  282. // Set request parameters.
  283. if (is_numeric($list))
  284. {
  285. $data['list_id'] = $list;
  286. }
  287. elseif (is_string($list))
  288. {
  289. $data['slug'] = $list;
  290. if (is_numeric($owner))
  291. {
  292. $data['owner_id'] = $owner;
  293. }
  294. elseif (is_string($owner))
  295. {
  296. $data['owner_screen_name'] = $owner;
  297. }
  298. else
  299. {
  300. // We don't have a valid entry
  301. $this->setExpectedException('RuntimeException');
  302. $this->object->getStatuses($list, $owner);
  303. }
  304. }
  305. else
  306. {
  307. $this->setExpectedException('RuntimeException');
  308. $this->object->getStatuses($list, $owner);
  309. }
  310. $path = $this->object->fetchUrl('/lists/statuses.json', $data);
  311. $this->client->expects($this->at(1))
  312. ->method('get')
  313. ->with($path)
  314. ->will($this->returnValue($returnData));
  315. $this->object->getStatuses($list, $owner);
  316. }
  317. /**
  318. * Tests the getListSubscribers method
  319. *
  320. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  321. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  322. *
  323. * @return void
  324. *
  325. * @since 1.0
  326. * @dataProvider seedListStatuses
  327. */
  328. public function testGetSubscribers($list, $owner)
  329. {
  330. $cursor = 1234;
  331. $entities = true;
  332. $skip_status = true;
  333. $returnData = new stdClass;
  334. $returnData->code = 200;
  335. $returnData->body = $this->rateLimit;
  336. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  337. $this->client->expects($this->at(0))
  338. ->method('get')
  339. ->with($path)
  340. ->will($this->returnValue($returnData));
  341. $returnData = new stdClass;
  342. $returnData->code = 200;
  343. $returnData->body = $this->sampleString;
  344. // Set request parameters.
  345. if (is_numeric($list))
  346. {
  347. $data['list_id'] = $list;
  348. }
  349. elseif (is_string($list))
  350. {
  351. $data['slug'] = $list;
  352. if (is_numeric($owner))
  353. {
  354. $data['owner_id'] = $owner;
  355. }
  356. elseif (is_string($owner))
  357. {
  358. $data['owner_screen_name'] = $owner;
  359. }
  360. else
  361. {
  362. // We don't have a valid entry
  363. $this->setExpectedException('RuntimeException');
  364. $this->object->getSubscribers($list, $owner);
  365. }
  366. }
  367. else
  368. {
  369. $this->setExpectedException('RuntimeException');
  370. $this->object->getSubscribers($list, $owner);
  371. }
  372. $data['cursor'] = $cursor;
  373. $data['include_entities'] = $entities;
  374. $data['skip_status'] = $skip_status;
  375. $path = $this->object->fetchUrl('/lists/subscribers.json', $data);
  376. $this->client->expects($this->at(1))
  377. ->method('get')
  378. ->with($path)
  379. ->will($this->returnValue($returnData));
  380. $this->assertThat(
  381. $this->object->getSubscribers($list, $owner, $cursor, $entities, $skip_status),
  382. $this->equalTo(json_decode($this->sampleString))
  383. );
  384. }
  385. /**
  386. * Tests the getListSubscribers method - failure
  387. *
  388. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  389. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  390. *
  391. * @return void
  392. *
  393. * @since 1.0
  394. * @dataProvider seedListStatuses
  395. * @expectedException DomainException
  396. */
  397. public function testGetSubscribersFailure($list, $owner)
  398. {
  399. $cursor = 1234;
  400. $entities = true;
  401. $skip_status = true;
  402. $returnData = new stdClass;
  403. $returnData->code = 200;
  404. $returnData->body = $this->rateLimit;
  405. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  406. $this->client->expects($this->at(0))
  407. ->method('get')
  408. ->with($path)
  409. ->will($this->returnValue($returnData));
  410. $returnData = new stdClass;
  411. $returnData->code = 500;
  412. $returnData->body = $this->errorString;
  413. // Set request parameters.
  414. if (is_numeric($list))
  415. {
  416. $data['list_id'] = $list;
  417. }
  418. elseif (is_string($list))
  419. {
  420. $data['slug'] = $list;
  421. if (is_numeric($owner))
  422. {
  423. $data['owner_id'] = $owner;
  424. }
  425. elseif (is_string($owner))
  426. {
  427. $data['owner_screen_name'] = $owner;
  428. }
  429. else
  430. {
  431. // We don't have a valid entry
  432. $this->setExpectedException('RuntimeException');
  433. $this->object->getSubscribers($list, $owner);
  434. }
  435. }
  436. else
  437. {
  438. $this->setExpectedException('RuntimeException');
  439. $this->object->getSubscribers($list, $owner);
  440. }
  441. $data['cursor'] = $cursor;
  442. $data['include_entities'] = $entities;
  443. $data['skip_status'] = $skip_status;
  444. $path = $this->object->fetchUrl('/lists/subscribers.json', $data);
  445. $this->client->expects($this->at(1))
  446. ->method('get')
  447. ->with($path)
  448. ->will($this->returnValue($returnData));
  449. $this->object->getSubscribers($list, $owner, $cursor, $entities, $skip_status);
  450. }
  451. /**
  452. * Provides test data for request format detection.
  453. *
  454. * @return array
  455. *
  456. * @since 1.0
  457. */
  458. public function seedMembers()
  459. {
  460. // List, User ID, screen name and owner.
  461. return array(
  462. array(234654235457, null, '234654235457', null),
  463. array('test-list', null, 'userTest', 'testUser'),
  464. array('test-list', '234654235457', null, '56165105642'),
  465. array('test-list', 'testUser', null, null),
  466. array('test-list', null, null, 'testUser'),
  467. array('test-list', 'testUser', '234654235457', 'userTest'),
  468. array(null, null, null, null)
  469. );
  470. }
  471. /**
  472. * Tests the deleteListMembers method
  473. *
  474. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  475. * @param string $user_id A comma separated list of user IDs, up to 100 are allowed in a single request.
  476. * @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
  477. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  478. *
  479. * @return void
  480. *
  481. * @since 1.0
  482. * @dataProvider seedMembers
  483. */
  484. public function testDeleteMembers($list, $user_id, $screen_name, $owner)
  485. {
  486. $returnData = new stdClass;
  487. $returnData->code = 200;
  488. $returnData->body = $this->sampleString;
  489. // Set request parameters.
  490. if (is_numeric($list))
  491. {
  492. $data['list_id'] = $list;
  493. }
  494. elseif (is_string($list))
  495. {
  496. $data['slug'] = $list;
  497. if (is_numeric($owner))
  498. {
  499. $data['owner_id'] = $owner;
  500. }
  501. elseif (is_string($owner))
  502. {
  503. $data['owner_screen_name'] = $owner;
  504. }
  505. else
  506. {
  507. // We don't have a valid entry
  508. $this->setExpectedException('RuntimeException');
  509. $this->object->deleteMembers($list, $user_id, $screen_name, $owner);
  510. }
  511. }
  512. else
  513. {
  514. $this->setExpectedException('RuntimeException');
  515. $this->object->deleteMembers($list, $user_id, $screen_name, $owner);
  516. }
  517. if ($user_id)
  518. {
  519. $data['user_id'] = $user_id;
  520. }
  521. if ($screen_name)
  522. {
  523. $data['screen_name'] = $screen_name;
  524. }
  525. if ($user_id == null && $screen_name == null)
  526. {
  527. $this->setExpectedException('RuntimeException');
  528. $this->object->deleteMembers($list, $user_id, $screen_name, $owner);
  529. }
  530. $path = $this->object->fetchUrl('/lists/members/destroy_all.json');
  531. $this->client->expects($this->once())
  532. ->method('post')
  533. ->with($path, $data)
  534. ->will($this->returnValue($returnData));
  535. $this->assertThat(
  536. $this->object->deleteMembers($list, $user_id, $screen_name, $owner),
  537. $this->equalTo(json_decode($this->sampleString))
  538. );
  539. }
  540. /**
  541. * Tests the deleteListMembers method - failure
  542. *
  543. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  544. * @param string $user_id A comma separated list of user IDs, up to 100 are allowed in a single request.
  545. * @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
  546. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  547. *
  548. * @return void
  549. *
  550. * @since 1.0
  551. * @dataProvider seedMembers
  552. * @expectedException DomainException
  553. */
  554. public function testDeleteMembersFailure($list, $user_id, $screen_name, $owner)
  555. {
  556. $returnData = new stdClass;
  557. $returnData->code = 500;
  558. $returnData->body = $this->errorString;
  559. // Set request parameters.
  560. if (is_numeric($list))
  561. {
  562. $data['list_id'] = $list;
  563. }
  564. elseif (is_string($list))
  565. {
  566. $data['slug'] = $list;
  567. if (is_numeric($owner))
  568. {
  569. $data['owner_id'] = $owner;
  570. }
  571. elseif (is_string($owner))
  572. {
  573. $data['owner_screen_name'] = $owner;
  574. }
  575. else
  576. {
  577. // We don't have a valid entry
  578. $this->setExpectedException('RuntimeException');
  579. $this->object->deleteMembers($list, $user_id, $screen_name, $owner);
  580. }
  581. }
  582. else
  583. {
  584. $this->setExpectedException('RuntimeException');
  585. $this->object->deleteMembers($list, $user_id, $screen_name, $owner);
  586. }
  587. if ($user_id)
  588. {
  589. $data['user_id'] = $user_id;
  590. }
  591. if ($screen_name)
  592. {
  593. $data['screen_name'] = $screen_name;
  594. }
  595. if ($user_id == null && $screen_name == null)
  596. {
  597. $this->setExpectedException('RuntimeException');
  598. $this->object->deleteMembers($list, $user_id, $screen_name, $owner);
  599. }
  600. $path = $this->object->fetchUrl('/lists/members/destroy_all.json');
  601. $this->client->expects($this->once())
  602. ->method('post')
  603. ->with($path, $data)
  604. ->will($this->returnValue($returnData));
  605. $this->object->deleteMembers($list, $user_id, $screen_name, $owner);
  606. }
  607. /**
  608. * Tests the subscribe method
  609. *
  610. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  611. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  612. *
  613. * @return void
  614. *
  615. * @since 1.0
  616. * @dataProvider seedListStatuses
  617. */
  618. public function testSubscribe($list, $owner)
  619. {
  620. $returnData = new stdClass;
  621. $returnData->code = 200;
  622. $returnData->body = $this->rateLimit;
  623. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  624. $this->client->expects($this->at(0))
  625. ->method('get')
  626. ->with($path)
  627. ->will($this->returnValue($returnData));
  628. $returnData = new stdClass;
  629. $returnData->code = 200;
  630. $returnData->body = $this->sampleString;
  631. // Set request parameters.
  632. if (is_numeric($list))
  633. {
  634. $data['list_id'] = $list;
  635. }
  636. elseif (is_string($list))
  637. {
  638. $data['slug'] = $list;
  639. if (is_numeric($owner))
  640. {
  641. $data['owner_id'] = $owner;
  642. }
  643. elseif (is_string($owner))
  644. {
  645. $data['owner_screen_name'] = $owner;
  646. }
  647. else
  648. {
  649. // We don't have a valid entry
  650. $this->setExpectedException('RuntimeException');
  651. $this->object->subscribe($list, $owner);
  652. }
  653. }
  654. else
  655. {
  656. $this->setExpectedException('RuntimeException');
  657. $this->object->subscribe($list, $owner);
  658. }
  659. $path = $this->object->fetchUrl('/lists/subscribers/create.json');
  660. $this->client->expects($this->at(1))
  661. ->method('post')
  662. ->with($path, $data)
  663. ->will($this->returnValue($returnData));
  664. $this->assertThat(
  665. $this->object->subscribe($list, $owner),
  666. $this->equalTo(json_decode($this->sampleString))
  667. );
  668. }
  669. /**
  670. * Tests the subscribe method - failure
  671. *
  672. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  673. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  674. *
  675. * @return void
  676. *
  677. * @since 1.0
  678. * @dataProvider seedListStatuses
  679. * @expectedException DomainException
  680. */
  681. public function testSubscribeFailure($list, $owner)
  682. {
  683. $returnData = new stdClass;
  684. $returnData->code = 200;
  685. $returnData->body = $this->rateLimit;
  686. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  687. $this->client->expects($this->at(0))
  688. ->method('get')
  689. ->with($path)
  690. ->will($this->returnValue($returnData));
  691. $returnData = new stdClass;
  692. $returnData->code = 500;
  693. $returnData->body = $this->errorString;
  694. // Set request parameters.
  695. if (is_numeric($list))
  696. {
  697. $data['list_id'] = $list;
  698. }
  699. elseif (is_string($list))
  700. {
  701. $data['slug'] = $list;
  702. if (is_numeric($owner))
  703. {
  704. $data['owner_id'] = $owner;
  705. }
  706. elseif (is_string($owner))
  707. {
  708. $data['owner_screen_name'] = $owner;
  709. }
  710. else
  711. {
  712. // We don't have a valid entry
  713. $this->setExpectedException('RuntimeException');
  714. $this->object->subscribe($list, $owner);
  715. }
  716. }
  717. else
  718. {
  719. $this->setExpectedException('RuntimeException');
  720. $this->object->subscribe($list, $owner);
  721. }
  722. $path = $this->object->fetchUrl('/lists/subscribers/create.json');
  723. $this->client->expects($this->at(1))
  724. ->method('post')
  725. ->with($path, $data)
  726. ->will($this->returnValue($returnData));
  727. $this->object->subscribe($list, $owner);
  728. }
  729. /**
  730. * Provides test data for request format detection.
  731. *
  732. * @return array
  733. *
  734. * @since 1.0
  735. */
  736. public function seedListUserOwner()
  737. {
  738. // List, User and Owner.
  739. return array(
  740. array(234654235457, '234654235457', null),
  741. array('test-list', 'userTest', 'testUser'),
  742. array('test-list', '234654235457', '56165105642'),
  743. array('test-list', 'testUser', null),
  744. array('test-list', null, 'testUser'),
  745. array(null, null, null)
  746. );
  747. }
  748. /**
  749. * Tests the isListMember method
  750. *
  751. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  752. * @param mixed $user Either an integer containing the user ID or a string containing the screen name of the user to remove.
  753. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  754. *
  755. * @return void
  756. *
  757. * @since 1.0
  758. * @dataProvider seedListUserOwner
  759. */
  760. public function testIsMember($list, $user, $owner)
  761. {
  762. $entities = true;
  763. $skip_status = true;
  764. $returnData = new stdClass;
  765. $returnData->code = 200;
  766. $returnData->body = $this->rateLimit;
  767. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  768. $this->client->expects($this->at(0))
  769. ->method('get')
  770. ->with($path)
  771. ->will($this->returnValue($returnData));
  772. $returnData = new stdClass;
  773. $returnData->code = 200;
  774. $returnData->body = $this->sampleString;
  775. // Set request parameters.
  776. if (is_numeric($list))
  777. {
  778. $data['list_id'] = $list;
  779. }
  780. elseif (is_string($list))
  781. {
  782. $data['slug'] = $list;
  783. if (is_numeric($owner))
  784. {
  785. $data['owner_id'] = $owner;
  786. }
  787. elseif (is_string($owner))
  788. {
  789. $data['owner_screen_name'] = $owner;
  790. }
  791. else
  792. {
  793. // We don't have a valid entry
  794. $this->setExpectedException('RuntimeException');
  795. $this->object->isMember($list, $user, $owner);
  796. }
  797. }
  798. else
  799. {
  800. $this->setExpectedException('RuntimeException');
  801. $this->object->isMember($list, $user, $owner);
  802. }
  803. if (is_numeric($user))
  804. {
  805. $data['user_id'] = $user;
  806. }
  807. elseif (is_string($user))
  808. {
  809. $data['screen_name'] = $user;
  810. }
  811. else
  812. {
  813. // We don't have a valid entry
  814. $this->setExpectedException('RuntimeException');
  815. $this->object->isMember($list, $user, $owner);
  816. }
  817. $data['include_entities'] = $entities;
  818. $data['skip_status'] = $skip_status;
  819. $path = $this->object->fetchUrl('/lists/members/show.json', $data);
  820. $this->client->expects($this->at(1))
  821. ->method('get')
  822. ->with($path)
  823. ->will($this->returnValue($returnData));
  824. $this->assertThat(
  825. $this->object->isMember($list, $user, $owner, $entities, $skip_status),
  826. $this->equalTo(json_decode($this->sampleString))
  827. );
  828. }
  829. /**
  830. * Tests the isListMember method - failure
  831. *
  832. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  833. * @param mixed $user Either an integer containing the user ID or a string containing the screen name of the user to remove.
  834. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  835. *
  836. * @return void
  837. *
  838. * @since 1.0
  839. * @dataProvider seedListUserOwner
  840. * @expectedException DomainException
  841. */
  842. public function testIsMemberFailure($list, $user, $owner)
  843. {
  844. $entities = true;
  845. $skip_status = true;
  846. $returnData = new stdClass;
  847. $returnData->code = 200;
  848. $returnData->body = $this->rateLimit;
  849. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  850. $this->client->expects($this->at(0))
  851. ->method('get')
  852. ->with($path)
  853. ->will($this->returnValue($returnData));
  854. $returnData = new stdClass;
  855. $returnData->code = 500;
  856. $returnData->body = $this->errorString;
  857. // Set request parameters.
  858. if (is_numeric($list))
  859. {
  860. $data['list_id'] = $list;
  861. }
  862. elseif (is_string($list))
  863. {
  864. $data['slug'] = $list;
  865. if (is_numeric($owner))
  866. {
  867. $data['owner_id'] = $owner;
  868. }
  869. elseif (is_string($owner))
  870. {
  871. $data['owner_screen_name'] = $owner;
  872. }
  873. else
  874. {
  875. // We don't have a valid entry
  876. $this->setExpectedException('RuntimeException');
  877. $this->object->isMember($list, $user, $owner);
  878. }
  879. }
  880. else
  881. {
  882. $this->setExpectedException('RuntimeException');
  883. $this->object->isMember($list, $user, $owner);
  884. }
  885. if (is_numeric($user))
  886. {
  887. $data['user_id'] = $user;
  888. }
  889. elseif (is_string($user))
  890. {
  891. $data['screen_name'] = $user;
  892. }
  893. else
  894. {
  895. // We don't have a valid entry
  896. $this->setExpectedException('RuntimeException');
  897. $this->object->isMember($list, $user, $owner);
  898. }
  899. $data['include_entities'] = $entities;
  900. $data['skip_status'] = $skip_status;
  901. $path = $this->object->fetchUrl('/lists/members/show.json', $data);
  902. $this->client->expects($this->at(1))
  903. ->method('get')
  904. ->with($path)
  905. ->will($this->returnValue($returnData));
  906. $this->object->isMember($list, $user, $owner, $entities, $skip_status);
  907. }
  908. /**
  909. * Tests the isListSubscriber method
  910. *
  911. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  912. * @param mixed $user Either an integer containing the user ID or a string containing the screen name of the user to remove.
  913. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  914. *
  915. * @return void
  916. *
  917. * @since 1.0
  918. * @dataProvider seedListUserOwner
  919. */
  920. public function testIsSubscriber($list, $user, $owner)
  921. {
  922. $entities = true;
  923. $skip_status = true;
  924. $returnData = new stdClass;
  925. $returnData->code = 200;
  926. $returnData->body = $this->rateLimit;
  927. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  928. $this->client->expects($this->at(0))
  929. ->method('get')
  930. ->with($path)
  931. ->will($this->returnValue($returnData));
  932. $returnData = new stdClass;
  933. $returnData->code = 200;
  934. $returnData->body = $this->sampleString;
  935. // Set request parameters.
  936. if (is_numeric($list))
  937. {
  938. $data['list_id'] = $list;
  939. }
  940. elseif (is_string($list))
  941. {
  942. $data['slug'] = $list;
  943. if (is_numeric($owner))
  944. {
  945. $data['owner_id'] = $owner;
  946. }
  947. elseif (is_string($owner))
  948. {
  949. $data['owner_screen_name'] = $owner;
  950. }
  951. else
  952. {
  953. // We don't have a valid entry
  954. $this->setExpectedException('RuntimeException');
  955. $this->object->isSubscriber($list, $user, $owner);
  956. }
  957. }
  958. else
  959. {
  960. $this->setExpectedException('RuntimeException');
  961. $this->object->isSubscriber($list, $user, $owner);
  962. }
  963. if (is_numeric($user))
  964. {
  965. $data['user_id'] = $user;
  966. }
  967. elseif (is_string($user))
  968. {
  969. $data['screen_name'] = $user;
  970. }
  971. else
  972. {
  973. // We don't have a valid entry
  974. $this->setExpectedException('RuntimeException');
  975. $this->object->isSubscriber($list, $user, $owner);
  976. }
  977. $data['include_entities'] = $entities;
  978. $data['skip_status'] = $skip_status;
  979. $path = $this->object->fetchUrl('/lists/subscribers/show.json', $data);
  980. $this->client->expects($this->at(1))
  981. ->method('get')
  982. ->with($path)
  983. ->will($this->returnValue($returnData));
  984. $this->assertThat(
  985. $this->object->isSubscriber($list, $user, $owner, $entities, $skip_status),
  986. $this->equalTo(json_decode($this->sampleString))
  987. );
  988. }
  989. /**
  990. * Tests the isListSubscriber method - failure
  991. *
  992. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  993. * @param mixed $user Either an integer containing the user ID or a string containing the screen name of the user to remove.
  994. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name of the owner.
  995. *
  996. * @return void
  997. *
  998. * @since 1.0
  999. * @dataProvider seedListUserOwner
  1000. * @expectedException DomainException
  1001. */
  1002. public function testIsSubscriberFailure($list, $user, $owner)
  1003. {
  1004. $entities = true;
  1005. $skip_status = true;
  1006. $returnData = new stdClass;
  1007. $returnData->code = 200;
  1008. $returnData->body = $this->rateLimit;
  1009. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1010. $this->client->expects($this->at(0))
  1011. ->method('get')
  1012. ->with($path)
  1013. ->will($this->returnValue($returnData));
  1014. $returnData = new stdClass;
  1015. $returnData->code = 500;
  1016. $returnData->body = $this->errorString;
  1017. // Set request parameters.
  1018. if (is_numeric($list))
  1019. {
  1020. $data['list_id'] = $list;
  1021. }
  1022. elseif (is_string($list))
  1023. {
  1024. $data['slug'] = $list;
  1025. if (is_numeric($owner))
  1026. {
  1027. $data['owner_id'] = $owner;
  1028. }
  1029. elseif (is_string($owner))
  1030. {
  1031. $data['owner_screen_name'] = $owner;
  1032. }
  1033. else
  1034. {
  1035. // We don't have a valid entry
  1036. $this->setExpectedException('RuntimeException');
  1037. $this->object->isSubscriber($list, $user, $owner);
  1038. }
  1039. }
  1040. else
  1041. {
  1042. $this->setExpectedException('RuntimeException');
  1043. $this->object->isSubscriber($list, $user, $owner);
  1044. }
  1045. if (is_numeric($user))
  1046. {
  1047. $data['user_id'] = $user;
  1048. }
  1049. elseif (is_string($user))
  1050. {
  1051. $data['screen_name'] = $user;
  1052. }
  1053. else
  1054. {
  1055. // We don't have a valid entry
  1056. $this->setExpectedException('RuntimeException');
  1057. $this->object->isSubscriber($list, $user, $owner);
  1058. }
  1059. $data['include_entities'] = $entities;
  1060. $data['skip_status'] = $skip_status;
  1061. $path = $this->object->fetchUrl('/lists/subscribers/show.json', $data);
  1062. $this->client->expects($this->at(1))
  1063. ->method('get')
  1064. ->with($path)
  1065. ->will($this->returnValue($returnData));
  1066. $this->object->isSubscriber($list, $user, $owner, $entities, $skip_status);
  1067. }
  1068. /**
  1069. * Tests the unsubscribe method
  1070. *
  1071. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1072. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1073. *
  1074. * @return void
  1075. *
  1076. * @since 1.0
  1077. * @dataProvider seedListStatuses
  1078. */
  1079. public function testUnsubscribe($list, $owner)
  1080. {
  1081. $returnData = new stdClass;
  1082. $returnData->code = 200;
  1083. $returnData->body = $this->rateLimit;
  1084. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1085. $this->client->expects($this->at(0))
  1086. ->method('get')
  1087. ->with($path)
  1088. ->will($this->returnValue($returnData));
  1089. $returnData = new stdClass;
  1090. $returnData->code = 200;
  1091. $returnData->body = $this->sampleString;
  1092. // Set request parameters.
  1093. if (is_numeric($list))
  1094. {
  1095. $data['list_id'] = $list;
  1096. }
  1097. elseif (is_string($list))
  1098. {
  1099. $data['slug'] = $list;
  1100. if (is_numeric($owner))
  1101. {
  1102. $data['owner_id'] = $owner;
  1103. }
  1104. elseif (is_string($owner))
  1105. {
  1106. $data['owner_screen_name'] = $owner;
  1107. }
  1108. else
  1109. {
  1110. // We don't have a valid entry
  1111. $this->setExpectedException('RuntimeException');
  1112. $this->object->unsubscribe($list, $owner);
  1113. }
  1114. }
  1115. else
  1116. {
  1117. $this->setExpectedException('RuntimeException');
  1118. $this->object->unsubscribe($list, $owner);
  1119. }
  1120. $path = $this->object->fetchUrl('/lists/subscribers/destroy.json');
  1121. $this->client->expects($this->at(1))
  1122. ->method('post')
  1123. ->with($path, $data)
  1124. ->will($this->returnValue($returnData));
  1125. $this->assertThat(
  1126. $this->object->unsubscribe($list, $owner),
  1127. $this->equalTo(json_decode($this->sampleString))
  1128. );
  1129. }
  1130. /**
  1131. * Tests the unsubscribe method - failure
  1132. *
  1133. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1134. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1135. *
  1136. * @return void
  1137. *
  1138. * @since 1.0
  1139. * @dataProvider seedListStatuses
  1140. * @expectedException DomainException
  1141. */
  1142. public function testUnsubscribeFailure($list, $owner)
  1143. {
  1144. $returnData = new stdClass;
  1145. $returnData->code = 200;
  1146. $returnData->body = $this->rateLimit;
  1147. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1148. $this->client->expects($this->at(0))
  1149. ->method('get')
  1150. ->with($path)
  1151. ->will($this->returnValue($returnData));
  1152. $returnData = new stdClass;
  1153. $returnData->code = 500;
  1154. $returnData->body = $this->errorString;
  1155. // Set request parameters.
  1156. if (is_numeric($list))
  1157. {
  1158. $data['list_id'] = $list;
  1159. }
  1160. elseif (is_string($list))
  1161. {
  1162. $data['slug'] = $list;
  1163. if (is_numeric($owner))
  1164. {
  1165. $data['owner_id'] = $owner;
  1166. }
  1167. elseif (is_string($owner))
  1168. {
  1169. $data['owner_screen_name'] = $owner;
  1170. }
  1171. else
  1172. {
  1173. // We don't have a valid entry
  1174. $this->setExpectedException('RuntimeException');
  1175. $this->object->unsubscribe($list, $owner);
  1176. }
  1177. }
  1178. else
  1179. {
  1180. $this->setExpectedException('RuntimeException');
  1181. $this->object->unsubscribe($list, $owner);
  1182. }
  1183. $path = $this->object->fetchUrl('/lists/subscribers/destroy.json');
  1184. $this->client->expects($this->at(1))
  1185. ->method('post')
  1186. ->with($path, $data)
  1187. ->will($this->returnValue($returnData));
  1188. $this->object->unsubscribe($list, $owner);
  1189. }
  1190. /**
  1191. * Tests the addListMembers method
  1192. *
  1193. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1194. * @param string $user_id A comma separated list of user IDs, up to 100 are allowed in a single request.
  1195. * @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
  1196. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1197. *
  1198. * @return void
  1199. *
  1200. * @since 1.0
  1201. * @dataProvider seedMembers
  1202. */
  1203. public function testAddMembers($list, $user_id, $screen_name, $owner)
  1204. {
  1205. $returnData = new stdClass;
  1206. $returnData->code = 200;
  1207. $returnData->body = $this->rateLimit;
  1208. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1209. $this->client->expects($this->at(0))
  1210. ->method('get')
  1211. ->with($path)
  1212. ->will($this->returnValue($returnData));
  1213. $returnData = new stdClass;
  1214. $returnData->code = 200;
  1215. $returnData->body = $this->sampleString;
  1216. // Set request parameters.
  1217. if (is_numeric($list))
  1218. {
  1219. $data['list_id'] = $list;
  1220. }
  1221. elseif (is_string($list))
  1222. {
  1223. $data['slug'] = $list;
  1224. if (is_numeric($owner))
  1225. {
  1226. $data['owner_id'] = $owner;
  1227. }
  1228. elseif (is_string($owner))
  1229. {
  1230. $data['owner_screen_name'] = $owner;
  1231. }
  1232. else
  1233. {
  1234. // We don't have a valid entry
  1235. $this->setExpectedException('RuntimeException');
  1236. $this->object->addMembers($list, $user_id, $screen_name, $owner);
  1237. }
  1238. }
  1239. else
  1240. {
  1241. $this->setExpectedException('RuntimeException');
  1242. $this->object->addMembers($list, $user_id, $screen_name, $owner);
  1243. }
  1244. if ($user_id)
  1245. {
  1246. $data['user_id'] = $user_id;
  1247. }
  1248. if ($screen_name)
  1249. {
  1250. $data['screen_name'] = $screen_name;
  1251. }
  1252. if ($user_id == null && $screen_name == null)
  1253. {
  1254. $this->setExpectedException('RuntimeException');
  1255. $this->object->addMembers($list, $user_id, $screen_name, $owner);
  1256. }
  1257. $path = $this->object->fetchUrl('/lists/members/create_all.json');
  1258. $this->client->expects($this->at(1))
  1259. ->method('post')
  1260. ->with($path, $data)
  1261. ->will($this->returnValue($returnData));
  1262. $this->assertThat(
  1263. $this->object->addMembers($list, $user_id, $screen_name, $owner),
  1264. $this->equalTo(json_decode($this->sampleString))
  1265. );
  1266. }
  1267. /**
  1268. * Tests the addListMembers method - failure
  1269. *
  1270. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1271. * @param string $user_id A comma separated list of user IDs, up to 100 are allowed in a single request.
  1272. * @param string $screen_name A comma separated list of screen names, up to 100 are allowed in a single request.
  1273. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1274. *
  1275. * @return void
  1276. *
  1277. * @since 1.0
  1278. * @dataProvider seedMembers
  1279. * @expectedException DomainException
  1280. */
  1281. public function testAddMembersFailure($list, $user_id, $screen_name, $owner)
  1282. {
  1283. $returnData = new stdClass;
  1284. $returnData->code = 200;
  1285. $returnData->body = $this->rateLimit;
  1286. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1287. $this->client->expects($this->at(0))
  1288. ->method('get')
  1289. ->with($path)
  1290. ->will($this->returnValue($returnData));
  1291. $returnData = new stdClass;
  1292. $returnData->code = 500;
  1293. $returnData->body = $this->errorString;
  1294. // Set request parameters.
  1295. if (is_numeric($list))
  1296. {
  1297. $data['list_id'] = $list;
  1298. }
  1299. elseif (is_string($list))
  1300. {
  1301. $data['slug'] = $list;
  1302. if (is_numeric($owner))
  1303. {
  1304. $data['owner_id'] = $owner;
  1305. }
  1306. elseif (is_string($owner))
  1307. {
  1308. $data['owner_screen_name'] = $owner;
  1309. }
  1310. else
  1311. {
  1312. // We don't have a valid entry
  1313. $this->setExpectedException('RuntimeException');
  1314. $this->object->addMembers($list, $user_id, $screen_name, $owner);
  1315. }
  1316. }
  1317. else
  1318. {
  1319. $this->setExpectedException('RuntimeException');
  1320. $this->object->addMembers($list, $user_id, $screen_name, $owner);
  1321. }
  1322. if ($user_id)
  1323. {
  1324. $data['user_id'] = $user_id;
  1325. }
  1326. if ($screen_name)
  1327. {
  1328. $data['screen_name'] = $screen_name;
  1329. }
  1330. if ($user_id == null && $screen_name == null)
  1331. {
  1332. $this->setExpectedException('RuntimeException');
  1333. $this->object->addMembers($list, $user_id, $screen_name, $owner);
  1334. }
  1335. $path = $this->object->fetchUrl('/lists/members/create_all.json');
  1336. $this->client->expects($this->at(1))
  1337. ->method('post')
  1338. ->with($path, $data)
  1339. ->will($this->returnValue($returnData));
  1340. $this->object->addMembers($list, $user_id, $screen_name, $owner);
  1341. }
  1342. /**
  1343. * Tests the getListMembers method
  1344. *
  1345. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1346. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1347. *
  1348. * @return void
  1349. *
  1350. * @since 1.0
  1351. * @dataProvider seedListStatuses
  1352. */
  1353. public function testGetMembers($list, $owner)
  1354. {
  1355. $entities = true;
  1356. $skip_status = true;
  1357. $returnData = new stdClass;
  1358. $returnData->code = 200;
  1359. $returnData->body = $this->rateLimit;
  1360. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1361. $this->client->expects($this->at(0))
  1362. ->method('get')
  1363. ->with($path)
  1364. ->will($this->returnValue($returnData));
  1365. $returnData = new stdClass;
  1366. $returnData->code = 200;
  1367. $returnData->body = $this->sampleString;
  1368. // Set request parameters.
  1369. if (is_numeric($list))
  1370. {
  1371. $data['list_id'] = $list;
  1372. }
  1373. elseif (is_string($list))
  1374. {
  1375. $data['slug'] = $list;
  1376. if (is_numeric($owner))
  1377. {
  1378. $data['owner_id'] = $owner;
  1379. }
  1380. elseif (is_string($owner))
  1381. {
  1382. $data['owner_screen_name'] = $owner;
  1383. }
  1384. else
  1385. {
  1386. // We don't have a valid entry
  1387. $this->setExpectedException('RuntimeException');
  1388. $this->object->getMembers($list, $owner);
  1389. }
  1390. }
  1391. else
  1392. {
  1393. $this->setExpectedException('RuntimeException');
  1394. $this->object->getMembers($list, $owner);
  1395. }
  1396. $data['include_entities'] = $entities;
  1397. $data['skip_status'] = $skip_status;
  1398. $path = $this->object->fetchUrl('/lists/members.json', $data);
  1399. $this->client->expects($this->at(1))
  1400. ->method('get')
  1401. ->with($path)
  1402. ->will($this->returnValue($returnData));
  1403. $this->assertThat(
  1404. $this->object->getMembers($list, $owner, $entities, $skip_status),
  1405. $this->equalTo(json_decode($this->sampleString))
  1406. );
  1407. }
  1408. /**
  1409. * Tests the getListMembers method - failure
  1410. *
  1411. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1412. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1413. *
  1414. * @return void
  1415. *
  1416. * @since 1.0
  1417. * @dataProvider seedListStatuses
  1418. * @expectedException DomainException
  1419. */
  1420. public function testGetMembersFailure($list, $owner)
  1421. {
  1422. $entities = true;
  1423. $skip_status = true;
  1424. $returnData = new stdClass;
  1425. $returnData->code = 200;
  1426. $returnData->body = $this->rateLimit;
  1427. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1428. $this->client->expects($this->at(0))
  1429. ->method('get')
  1430. ->with($path)
  1431. ->will($this->returnValue($returnData));
  1432. $returnData = new stdClass;
  1433. $returnData->code = 500;
  1434. $returnData->body = $this->errorString;
  1435. // Set request parameters.
  1436. if (is_numeric($list))
  1437. {
  1438. $data['list_id'] = $list;
  1439. }
  1440. elseif (is_string($list))
  1441. {
  1442. $data['slug'] = $list;
  1443. if (is_numeric($owner))
  1444. {
  1445. $data['owner_id'] = $owner;
  1446. }
  1447. elseif (is_string($owner))
  1448. {
  1449. $data['owner_screen_name'] = $owner;
  1450. }
  1451. else
  1452. {
  1453. // We don't have a valid entry
  1454. $this->setExpectedException('RuntimeException');
  1455. $this->object->getMembers($list, $owner);
  1456. }
  1457. }
  1458. else
  1459. {
  1460. $this->setExpectedException('RuntimeException');
  1461. $this->object->getMembers($list, $owner);
  1462. }
  1463. $data['include_entities'] = $entities;
  1464. $data['skip_status'] = $skip_status;
  1465. $path = $this->object->fetchUrl('/lists/members.json', $data);
  1466. $this->client->expects($this->at(1))
  1467. ->method('get')
  1468. ->with($path)
  1469. ->will($this->returnValue($returnData));
  1470. $this->object->getMembers($list, $owner, $entities, $skip_status);
  1471. }
  1472. /**
  1473. * Tests the getListById method
  1474. *
  1475. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1476. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1477. *
  1478. * @return void
  1479. *
  1480. * @since 1.0
  1481. * @dataProvider seedListStatuses
  1482. */
  1483. public function testGetListById($list, $owner)
  1484. {
  1485. $returnData = new stdClass;
  1486. $returnData->code = 200;
  1487. $returnData->body = $this->rateLimit;
  1488. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1489. $this->client->expects($this->at(0))
  1490. ->method('get')
  1491. ->with($path)
  1492. ->will($this->returnValue($returnData));
  1493. $returnData = new stdClass;
  1494. $returnData->code = 200;
  1495. $returnData->body = $this->sampleString;
  1496. // Set request parameters.
  1497. if (is_numeric($list))
  1498. {
  1499. $data['list_id'] = $list;
  1500. }
  1501. elseif (is_string($list))
  1502. {
  1503. $data['slug'] = $list;
  1504. if (is_numeric($owner))
  1505. {
  1506. $data['owner_id'] = $owner;
  1507. }
  1508. elseif (is_string($owner))
  1509. {
  1510. $data['owner_screen_name'] = $owner;
  1511. }
  1512. else
  1513. {
  1514. // We don't have a valid entry
  1515. $this->setExpectedException('RuntimeException');
  1516. $this->object->getListById($list, $owner);
  1517. }
  1518. }
  1519. else
  1520. {
  1521. $this->setExpectedException('RuntimeException');
  1522. $this->object->getListById($list, $owner);
  1523. }
  1524. $path = $this->object->fetchUrl('/lists/show.json', $data);
  1525. $this->client->expects($this->at(1))
  1526. ->method('get')
  1527. ->with($path)
  1528. ->will($this->returnValue($returnData));
  1529. $this->assertThat(
  1530. $this->object->getListById($list, $owner),
  1531. $this->equalTo(json_decode($this->sampleString))
  1532. );
  1533. }
  1534. /**
  1535. * Tests the getListById method - failure
  1536. *
  1537. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1538. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1539. *
  1540. * @return void
  1541. *
  1542. * @since 1.0
  1543. * @dataProvider seedListStatuses
  1544. * @expectedException DomainException
  1545. */
  1546. public function testGetListByIdFailure($list, $owner)
  1547. {
  1548. $returnData = new stdClass;
  1549. $returnData->code = 200;
  1550. $returnData->body = $this->rateLimit;
  1551. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1552. $this->client->expects($this->at(0))
  1553. ->method('get')
  1554. ->with($path)
  1555. ->will($this->returnValue($returnData));
  1556. $returnData = new stdClass;
  1557. $returnData->code = 500;
  1558. $returnData->body = $this->errorString;
  1559. // Set request parameters.
  1560. if (is_numeric($list))
  1561. {
  1562. $data['list_id'] = $list;
  1563. }
  1564. elseif (is_string($list))
  1565. {
  1566. $data['slug'] = $list;
  1567. if (is_numeric($owner))
  1568. {
  1569. $data['owner_id'] = $owner;
  1570. }
  1571. elseif (is_string($owner))
  1572. {
  1573. $data['owner_screen_name'] = $owner;
  1574. }
  1575. else
  1576. {
  1577. // We don't have a valid entry
  1578. $this->setExpectedException('RuntimeException');
  1579. $this->object->getListById($list, $owner);
  1580. }
  1581. }
  1582. else
  1583. {
  1584. $this->setExpectedException('RuntimeException');
  1585. $this->object->getListById($list, $owner);
  1586. }
  1587. $path = $this->object->fetchUrl('/lists/show.json', $data);
  1588. $this->client->expects($this->at(1))
  1589. ->method('get')
  1590. ->with($path)
  1591. ->will($this->returnValue($returnData));
  1592. $this->object->getListById($list, $owner);
  1593. }
  1594. /**
  1595. * Tests the getSubscriptions method
  1596. *
  1597. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  1598. *
  1599. * @return void
  1600. *
  1601. * @since 1.0
  1602. * @dataProvider seedUser
  1603. */
  1604. public function testGetSubscriptions($user)
  1605. {
  1606. $count = 10;
  1607. $cursor = 1234;
  1608. $returnData = new stdClass;
  1609. $returnData->code = 200;
  1610. $returnData->body = $this->rateLimit;
  1611. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1612. $this->client->expects($this->at(0))
  1613. ->method('get')
  1614. ->with($path)
  1615. ->will($this->returnValue($returnData));
  1616. $returnData = new stdClass;
  1617. $returnData->code = 200;
  1618. $returnData->body = $this->sampleString;
  1619. // Set request parameters.
  1620. if (is_numeric($user))
  1621. {
  1622. $data['user_id'] = $user;
  1623. }
  1624. elseif (is_string($user))
  1625. {
  1626. $data['screen_name'] = $user;
  1627. }
  1628. else
  1629. {
  1630. $this->setExpectedException('RuntimeException');
  1631. $this->object->getSubscriptions($user);
  1632. }
  1633. $data['count'] = $count;
  1634. $data['cursor'] = $cursor;
  1635. $path = $this->object->fetchUrl('/lists/subscriptions.json', $data);
  1636. $this->client->expects($this->at(1))
  1637. ->method('get')
  1638. ->with($path)
  1639. ->will($this->returnValue($returnData));
  1640. $this->assertThat(
  1641. $this->object->getSubscriptions($user, $count, $cursor),
  1642. $this->equalTo(json_decode($this->sampleString))
  1643. );
  1644. }
  1645. /**
  1646. * Tests the getSubscriptions method - failure
  1647. *
  1648. * @param mixed $user Either an integer containing the user ID or a string containing the screen name.
  1649. *
  1650. * @return void
  1651. *
  1652. * @since 1.0
  1653. * @dataProvider seedUser
  1654. * @expectedException DomainException
  1655. */
  1656. public function testGetSubscriptionsFailure($user)
  1657. {
  1658. $count = 10;
  1659. $cursor = 1234;
  1660. $returnData = new stdClass;
  1661. $returnData->code = 200;
  1662. $returnData->body = $this->rateLimit;
  1663. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1664. $this->client->expects($this->at(0))
  1665. ->method('get')
  1666. ->with($path)
  1667. ->will($this->returnValue($returnData));
  1668. $returnData = new stdClass;
  1669. $returnData->code = 500;
  1670. $returnData->body = $this->errorString;
  1671. // Set request parameters.
  1672. if (is_numeric($user))
  1673. {
  1674. $data['user_id'] = $user;
  1675. }
  1676. elseif (is_string($user))
  1677. {
  1678. $data['screen_name'] = $user;
  1679. }
  1680. else
  1681. {
  1682. $this->setExpectedException('RuntimeException');
  1683. $this->object->getSubscriptions($user);
  1684. }
  1685. $data['count'] = $count;
  1686. $data['cursor'] = $cursor;
  1687. $path = $this->object->fetchUrl('/lists/subscriptions.json', $data);
  1688. $this->client->expects($this->at(1))
  1689. ->method('get')
  1690. ->with($path)
  1691. ->will($this->returnValue($returnData));
  1692. $this->object->getSubscriptions($user, $count, $cursor);
  1693. }
  1694. /**
  1695. * Tests the updateList method
  1696. *
  1697. * @param mixed $list Either an integer containing the list ID or a string containing the list slug.
  1698. * @param mixed $owner Either an integer containing the user ID or a string containing the screen name.
  1699. *
  1700. * @return void
  1701. *
  1702. * @since 1.0
  1703. * @dataProvider seedListStatuses
  1704. */
  1705. public function testUpdate($list, $owner)
  1706. {
  1707. $name = 'test list';
  1708. $mode = 'private';
  1709. $description = 'this is a description';
  1710. $returnData = new stdClass;
  1711. $returnData->code = 200;
  1712. $returnData->body = $this->rateLimit;
  1713. $path = $this->object->fetchUrl('/application/rate_limit_status.json', array("resources" => "lists"));
  1714. $this->client->expects($this->at(0))
  1715. ->method('get')
  1716. ->with($path)
  1717. ->will($this->returnValue($returnData));
  1718. $returnData = new stdClass;
  1719. $returnData->code = 200;
  1720. $returnData->body = $this->sampleString;
  1721. // Set request parameters.
  1722. if (is_numeric($list))
  1723. {
  1724. $data['list_id'] = $list;
  1725. }
  1726. elseif (is_string($list))
  1727. {
  1728. $data['slug'] = $list;
  1729. if (is_numeric($owner))
  1730. {
  1731. $data['owner_id'] = $owner;
  1732. }
  1733. elseif (is_string($owner))
  1734. {
  1735. $data['owner_screen_name'] = $owner;
  1736. }
  1737. else
  1738. {
  1739. // We don't have a valid entry
  1740. $this->setExpectedException('RuntimeException');
  1741. $this->object->update($list, $owner);
  1742. }
  1743. }
  1744. else
  1745. {
  1746. $this->setExpectedException('RuntimeException');
  1747. $this->object->update($list, $owner);
  1748. }
  1749. $data['name'] = $name;
  1750. $data['mode'] = $mode;
  1751. $data['description'] = $description;
  1752. $path = $this->object->fetchUrl('/lists/update.json');
  1753. $this->client->expects($this->at(1))
  1754. ->method('post')
  1755. ->with($p

Large files files are truncated, but you can click here to view the full file