PageRenderTime 83ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 1ms

/tests/unit/suites/libraries/joomla/linkedin/JLinkedinGroupsTest.php

https://github.com/kochen/joomla-rtl
PHP | 1748 lines | 988 code | 319 blank | 441 comment | 9 complexity | fb8fd30ff704512565c44fef94ef7126 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, Apache-2.0
  1. <?php
  2. /**
  3. * @package Joomla.UnitTest
  4. * @subpackage Linkedin
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. require_once JPATH_PLATFORM . '/joomla/linkedin/groups.php';
  10. /**
  11. * Test class for JLinkedinGroups.
  12. *
  13. * @package Joomla.UnitTest
  14. * @subpackage Linkedin
  15. * @since 13.1
  16. */
  17. class JLinkedinGroupsTest extends TestCase
  18. {
  19. /**
  20. * @var JRegistry Options for the Linkedin object.
  21. * @since 13.1
  22. */
  23. protected $options;
  24. /**
  25. * @var JHttp Mock http object.
  26. * @since 13.1
  27. */
  28. protected $client;
  29. /**
  30. * @var JInput The input object to use in retrieving GET/POST data.
  31. * @since 13.1
  32. */
  33. protected $input;
  34. /**
  35. * @var JLinkedinGroups Object under test.
  36. * @since 13.1
  37. */
  38. protected $object;
  39. /**
  40. * @var JLinkedinOAuth Authentication object for the Twitter object.
  41. * @since 13.1
  42. */
  43. protected $oauth;
  44. /**
  45. * @var string Sample JSON string.
  46. * @since 13.1
  47. */
  48. protected $sampleString = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
  49. /**
  50. * @var string Sample JSON error message.
  51. * @since 13.1
  52. */
  53. protected $errorString = '{"errorCode":401, "message": "Generic error"}';
  54. /**
  55. * Sets up the fixture, for example, opens a network connection.
  56. * This method is called before a test is executed.
  57. *
  58. * @return void
  59. */
  60. protected function setUp()
  61. {
  62. parent::setUp();
  63. $_SERVER['HTTP_HOST'] = 'example.com';
  64. $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0';
  65. $_SERVER['REQUEST_URI'] = '/index.php';
  66. $_SERVER['SCRIPT_NAME'] = '/index.php';
  67. $key = "app_key";
  68. $secret = "app_secret";
  69. $my_url = "http://127.0.0.1/gsoc/joomla-platform/linkedin_test.php";
  70. $this->options = new JRegistry;
  71. $this->input = new JInput;
  72. $this->client = $this->getMock('JHttp', array('get', 'post', 'delete', 'put'));
  73. $this->oauth = new JLinkedinOauth($this->options, $this->client, $this->input);
  74. $this->oauth->setToken(array('key' => $key, 'secret' => $secret));
  75. $this->object = new JLinkedinGroups($this->options, $this->client, $this->oauth);
  76. $this->options->set('consumer_key', $key);
  77. $this->options->set('consumer_secret', $secret);
  78. $this->options->set('callback', $my_url);
  79. }
  80. /**
  81. * Tears down the fixture, for example, closes a network connection.
  82. * This method is called after a test is executed.
  83. *
  84. * @return void
  85. */
  86. protected function tearDown()
  87. {
  88. }
  89. /**
  90. * Tests the getGroup method
  91. *
  92. * @return void
  93. *
  94. * @since 13.1
  95. */
  96. public function testGetGroup()
  97. {
  98. $id = '12345';
  99. $fields = '(id,name,short-description,description,relation-to-viewer:(membership-state,available-actions),is-open-to-non-members)';
  100. $start = 1;
  101. $count = 10;
  102. // Set request parameters.
  103. $data['format'] = 'json';
  104. $data['start'] = $start;
  105. $data['count'] = $count;
  106. $path = '/v1/groups/' . $id;
  107. $path .= ':' . $fields;
  108. $returnData = new stdClass;
  109. $returnData->code = 200;
  110. $returnData->body = $this->sampleString;
  111. $path = $this->oauth->toUrl($path, $data);
  112. $this->client->expects($this->once())
  113. ->method('get')
  114. ->with($path)
  115. ->will($this->returnValue($returnData));
  116. $this->assertThat(
  117. $this->object->getGroup($id, $fields, $start, $count),
  118. $this->equalTo(json_decode($this->sampleString))
  119. );
  120. }
  121. /**
  122. * Tests the getGroup method - failure
  123. *
  124. * @return void
  125. *
  126. * @since 13.1
  127. * @expectedException DomainException
  128. */
  129. public function testGetGroupFailure()
  130. {
  131. $id = '12345';
  132. $fields = '(id,name,short-description,description,relation-to-viewer:(membership-state,available-actions),is-open-to-non-members)';
  133. $start = 1;
  134. $count = 10;
  135. // Set request parameters.
  136. $data['format'] = 'json';
  137. $data['start'] = $start;
  138. $data['count'] = $count;
  139. $path = '/v1/groups/' . $id;
  140. $path .= ':' . $fields;
  141. $returnData = new stdClass;
  142. $returnData->code = 401;
  143. $returnData->body = $this->errorString;
  144. $path = $this->oauth->toUrl($path, $data);
  145. $this->client->expects($this->once())
  146. ->method('get')
  147. ->with($path)
  148. ->will($this->returnValue($returnData));
  149. $this->object->getGroup($id, $fields, $start, $count);
  150. }
  151. /**
  152. * Provides test data for request format detection.
  153. *
  154. * @return array
  155. *
  156. * @since 13.1
  157. */
  158. public function seedId()
  159. {
  160. // Member ID
  161. return array(
  162. array('lcnIwDU0S6'),
  163. array(null)
  164. );
  165. }
  166. /**
  167. * Tests the getMemberships method
  168. *
  169. * @param string $person_id The unique identifier for a user.
  170. *
  171. * @return void
  172. *
  173. * @dataProvider seedId
  174. * @since 13.1
  175. */
  176. public function testGetMemberships($person_id)
  177. {
  178. $fields = '(id,name,short-description,description,relation-to-viewer:(membership-state,available-actions),is-open-to-non-members)';
  179. $start = 1;
  180. $count = 10;
  181. $membership_state = 'member';
  182. // Set request parameters.
  183. $data['format'] = 'json';
  184. $data['start'] = $start;
  185. $data['count'] = $count;
  186. $data['membership-state'] = $membership_state;
  187. if ($person_id)
  188. {
  189. $path = '/v1/people/' . $person_id . '/group-memberships';
  190. }
  191. else
  192. {
  193. $path = '/v1/people/~/group-memberships';
  194. }
  195. $path .= ':' . $fields;
  196. $returnData = new stdClass;
  197. $returnData->code = 200;
  198. $returnData->body = $this->sampleString;
  199. $path = $this->oauth->toUrl($path, $data);
  200. $this->client->expects($this->once())
  201. ->method('get')
  202. ->with($path)
  203. ->will($this->returnValue($returnData));
  204. $this->assertThat(
  205. $this->object->getMemberships($person_id, $fields, $start, $count, $membership_state),
  206. $this->equalTo(json_decode($this->sampleString))
  207. );
  208. }
  209. /**
  210. * Tests the getMemberships method - failure
  211. *
  212. * @param string $person_id The unique identifier for a user.
  213. *
  214. * @return void
  215. *
  216. * @dataProvider seedId
  217. * @expectedException DomainException
  218. * @since 13.1
  219. */
  220. public function testGetMembershipsFailure($person_id)
  221. {
  222. $fields = '(id,name,short-description,description,relation-to-viewer:(membership-state,available-actions),is-open-to-non-members)';
  223. $start = 1;
  224. $count = 10;
  225. $membership_state = 'member';
  226. // Set request parameters.
  227. $data['format'] = 'json';
  228. $data['start'] = $start;
  229. $data['count'] = $count;
  230. $data['membership-state'] = $membership_state;
  231. if ($person_id)
  232. {
  233. $path = '/v1/people/' . $person_id . '/group-memberships';
  234. }
  235. else
  236. {
  237. $path = '/v1/people/~/group-memberships';
  238. }
  239. $path .= ':' . $fields;
  240. $returnData = new stdClass;
  241. $returnData->code = 401;
  242. $returnData->body = $this->errorString;
  243. $path = $this->oauth->toUrl($path, $data);
  244. $this->client->expects($this->once())
  245. ->method('get')
  246. ->with($path)
  247. ->will($this->returnValue($returnData));
  248. $this->object->getMemberships($person_id, $fields, $start, $count, $membership_state);
  249. }
  250. /**
  251. * Tests the getSettings method
  252. *
  253. * @param string $person_id The unique identifier for a user.
  254. *
  255. * @return void
  256. *
  257. * @dataProvider seedId
  258. * @since 13.1
  259. */
  260. public function testGetSettings($person_id)
  261. {
  262. $group_id = '12345';
  263. $fields = '(group:(id,name),membership-state,email-digest-frequency,email-announcements-from-managers,
  264. allow-messages-from-members,email-for-every-new-post)';
  265. $start = 1;
  266. $count = 10;
  267. // Set request parameters.
  268. $data['format'] = 'json';
  269. $data['start'] = $start;
  270. $data['count'] = $count;
  271. if ($person_id)
  272. {
  273. $path = '/v1/people/' . $person_id . '/group-memberships';
  274. }
  275. else
  276. {
  277. $path = '/v1/people/~/group-memberships';
  278. }
  279. $path .= '/' . $group_id;
  280. $path .= ':' . $fields;
  281. $returnData = new stdClass;
  282. $returnData->code = 200;
  283. $returnData->body = $this->sampleString;
  284. $path = $this->oauth->toUrl($path, $data);
  285. $this->client->expects($this->once())
  286. ->method('get')
  287. ->with($path)
  288. ->will($this->returnValue($returnData));
  289. $this->assertThat(
  290. $this->object->getSettings($person_id, $group_id, $fields, $start, $count),
  291. $this->equalTo(json_decode($this->sampleString))
  292. );
  293. }
  294. /**
  295. * Tests the getSettings method - failure
  296. *
  297. * @param string $person_id The unique identifier for a user.
  298. *
  299. * @return void
  300. *
  301. * @dataProvider seedId
  302. * @expectedException DomainException
  303. * @since 13.1
  304. */
  305. public function testGetSettingsFailure($person_id)
  306. {
  307. $group_id = '12345';
  308. $fields = '(group:(id,name),membership-state,email-digest-frequency,email-announcements-from-managers,
  309. allow-messages-from-members,email-for-every-new-post)';
  310. $start = 1;
  311. $count = 10;
  312. // Set request parameters.
  313. $data['format'] = 'json';
  314. $data['start'] = $start;
  315. $data['count'] = $count;
  316. if ($person_id)
  317. {
  318. $path = '/v1/people/' . $person_id . '/group-memberships';
  319. }
  320. else
  321. {
  322. $path = '/v1/people/~/group-memberships';
  323. }
  324. $path .= '/' . $group_id;
  325. $path .= ':' . $fields;
  326. $returnData = new stdClass;
  327. $returnData->code = 401;
  328. $returnData->body = $this->errorString;
  329. $path = $this->oauth->toUrl($path, $data);
  330. $this->client->expects($this->once())
  331. ->method('get')
  332. ->with($path)
  333. ->will($this->returnValue($returnData));
  334. $this->object->getSettings($person_id, $group_id, $fields, $start, $count);
  335. }
  336. /**
  337. * Tests the changeSettings method
  338. *
  339. * @return void
  340. *
  341. * @since 13.1
  342. */
  343. public function testChangeSettings()
  344. {
  345. $group_id = '12345';
  346. $show_logo = true;
  347. $digest_frequency = 'daily';
  348. $announcements = true;
  349. $allow_messages = true;
  350. $new_post = true;
  351. $path = '/v1/people/~/group-memberships/' . $group_id;
  352. $xml = '<group-membership>
  353. <show-group-logo-in-profile>true</show-group-logo-in-profile>
  354. <email-digest-frequency>
  355. <code>daily</code>
  356. </email-digest-frequency>
  357. <email-announcements-from-managers>true</email-announcements-from-managers>
  358. <allow-messages-from-members>true</allow-messages-from-members>
  359. <email-for-every-new-post>true</email-for-every-new-post>
  360. </group-membership>';
  361. $header['Content-Type'] = 'text/xml';
  362. $returnData = new stdClass;
  363. $returnData->code = 200;
  364. $returnData->body = $this->sampleString;
  365. $this->client->expects($this->once())
  366. ->method('put', $xml, $header)
  367. ->with($path)
  368. ->will($this->returnValue($returnData));
  369. $this->assertThat(
  370. $this->object->changeSettings($group_id, $show_logo, $digest_frequency, $announcements, $allow_messages, $new_post),
  371. $this->equalTo($returnData)
  372. );
  373. }
  374. /**
  375. * Tests the changeSettings method - failure
  376. *
  377. * @return void
  378. *
  379. * @expectedException DomainException
  380. * @since 13.1
  381. */
  382. public function testChangeSettingsFailure()
  383. {
  384. $group_id = '12345';
  385. $show_logo = true;
  386. $digest_frequency = 'daily';
  387. $announcements = true;
  388. $allow_messages = true;
  389. $new_post = true;
  390. $path = '/v1/people/~/group-memberships/' . $group_id;
  391. $xml = '<group-membership>
  392. <show-group-logo-in-profile>true</show-group-logo-in-profile>
  393. <email-digest-frequency>
  394. <code>daily</code>
  395. </email-digest-frequency>
  396. <email-announcements-from-managers>true</email-announcements-from-managers>
  397. <allow-messages-from-members>true</allow-messages-from-members>
  398. <email-for-every-new-post>true</email-for-every-new-post>
  399. </group-membership>';
  400. $header['Content-Type'] = 'text/xml';
  401. $returnData = new stdClass;
  402. $returnData->code = 403;
  403. $returnData->body = 'Throttle limit for calls to this resource is reached.';
  404. $this->client->expects($this->once())
  405. ->method('put', $xml, $header)
  406. ->with($path)
  407. ->will($this->returnValue($returnData));
  408. $this->object->changeSettings($group_id, $show_logo, $digest_frequency, $announcements, $allow_messages, $new_post);
  409. }
  410. /**
  411. * Tests the joinGroup method
  412. *
  413. * @return void
  414. *
  415. * @since 13.1
  416. */
  417. public function testJoinGroup()
  418. {
  419. $group_id = '12345';
  420. $show_logo = true;
  421. $digest_frequency = 'daily';
  422. $announcements = true;
  423. $allow_messages = true;
  424. $new_post = true;
  425. $path = '/v1/people/~/group-memberships';
  426. $xml = '<group-membership>
  427. <group>
  428. <id>' . $group_id . '</id>
  429. </group>
  430. <show-group-logo-in-profile>true</show-group-logo-in-profile>
  431. <email-digest-frequency>
  432. <code>daily</code>
  433. </email-digest-frequency>
  434. <email-announcements-from-managers>true</email-announcements-from-managers>
  435. <allow-messages-from-members>true</allow-messages-from-members>
  436. <email-for-every-new-post>false</email-for-every-new-post>
  437. <membership-state>
  438. <code>member</code>
  439. </membership-state>
  440. </group-membership>';
  441. $header['Content-Type'] = 'text/xml';
  442. $returnData = new stdClass;
  443. $returnData->code = 201;
  444. $returnData->body = $this->sampleString;
  445. $this->client->expects($this->once())
  446. ->method('post', $xml, $header)
  447. ->with($path)
  448. ->will($this->returnValue($returnData));
  449. $this->assertThat(
  450. $this->object->joinGroup($group_id, $show_logo, $digest_frequency, $announcements, $allow_messages, $new_post),
  451. $this->equalTo($returnData)
  452. );
  453. }
  454. /**
  455. * Tests the joinGroup method - failure
  456. *
  457. * @return void
  458. *
  459. * @expectedException DomainException
  460. * @since 13.1
  461. */
  462. public function testJoinGroupFailure()
  463. {
  464. $group_id = '12345';
  465. $show_logo = true;
  466. $digest_frequency = 'daily';
  467. $announcements = true;
  468. $allow_messages = true;
  469. $new_post = true;
  470. $path = '/v1/people/~/group-memberships';
  471. $xml = '<group-membership>
  472. <group>
  473. <id>' . $group_id . '</id>
  474. </group>
  475. <show-group-logo-in-profile>true</show-group-logo-in-profile>
  476. <email-digest-frequency>
  477. <code>daily</code>
  478. </email-digest-frequency>
  479. <email-announcements-from-managers>true</email-announcements-from-managers>
  480. <allow-messages-from-members>true</allow-messages-from-members>
  481. <email-for-every-new-post>false</email-for-every-new-post>
  482. <membership-state>
  483. <code>member</code>
  484. </membership-state>
  485. </group-membership>';
  486. $header['Content-Type'] = 'text/xml';
  487. $returnData = new stdClass;
  488. $returnData->code = 403;
  489. $returnData->body = 'Throttle limit for calls to this resource is reached.';
  490. $this->client->expects($this->once())
  491. ->method('post', $xml, $header)
  492. ->with($path)
  493. ->will($this->returnValue($returnData));
  494. $this->object->joinGroup($group_id, $show_logo, $digest_frequency, $announcements, $allow_messages, $new_post);
  495. }
  496. /**
  497. * Tests the leaveGroup method
  498. *
  499. * @return void
  500. *
  501. * @since 13.1
  502. */
  503. public function testLeaveGroup()
  504. {
  505. $group_id = '12345';
  506. $path = '/v1/people/~/group-memberships/' . $group_id;
  507. $returnData = new stdClass;
  508. $returnData->code = 204;
  509. $returnData->body = $this->sampleString;
  510. $this->client->expects($this->once())
  511. ->method('delete')
  512. ->with($path)
  513. ->will($this->returnValue($returnData));
  514. $this->assertThat(
  515. $this->object->leaveGroup($group_id),
  516. $this->equalTo($returnData)
  517. );
  518. }
  519. /**
  520. * Tests the leaveGroup method - failure
  521. *
  522. * @return void
  523. *
  524. * @expectedException DomainException
  525. * @since 13.1
  526. */
  527. public function testLeaveGroupFailure()
  528. {
  529. $group_id = '12345';
  530. $path = '/v1/people/~/group-memberships/' . $group_id;
  531. $returnData = new stdClass;
  532. $returnData->code = 401;
  533. $returnData->body = 'unauthorized';
  534. $this->client->expects($this->once())
  535. ->method('delete')
  536. ->with($path)
  537. ->will($this->returnValue($returnData));
  538. $this->object->leaveGroup($group_id);
  539. }
  540. /**
  541. * Tests the getDiscussions method
  542. *
  543. * @return void
  544. *
  545. * @since 13.1
  546. */
  547. public function testGetDiscussions()
  548. {
  549. $id = '12345';
  550. $fields = '(creation-timestamp,title,summary,creator:(first-name,last-name),likes,attachment:(content-url,title),relation-to-viewer)';
  551. $start = 1;
  552. $count = 10;
  553. $order = 'recency';
  554. $category = 'discussion';
  555. $modified_since = '1302727083000';
  556. // Set request parameters.
  557. $data['format'] = 'json';
  558. $data['start'] = $start;
  559. $data['count'] = $count;
  560. $data['order'] = $order;
  561. $data['category'] = $category;
  562. $data['modified-since'] = $modified_since;
  563. $path = '/v1/groups/' . $id . '/posts';
  564. $path .= ':' . $fields;
  565. $returnData = new stdClass;
  566. $returnData->code = 200;
  567. $returnData->body = $this->sampleString;
  568. $path = $this->oauth->toUrl($path, $data);
  569. $this->client->expects($this->once())
  570. ->method('get')
  571. ->with($path)
  572. ->will($this->returnValue($returnData));
  573. $this->assertThat(
  574. $this->object->getDiscussions($id, $fields, $start, $count, $order, $category, $modified_since),
  575. $this->equalTo(json_decode($this->sampleString))
  576. );
  577. }
  578. /**
  579. * Tests the getDiscussions method - failure
  580. *
  581. * @return void
  582. *
  583. * @expectedException DomainException
  584. * @since 13.1
  585. */
  586. public function testGetDiscussionsFailure()
  587. {
  588. $id = '12345';
  589. $fields = '(creation-timestamp,title,summary,creator:(first-name,last-name),likes,attachment:(content-url,title),relation-to-viewer)';
  590. $start = 1;
  591. $count = 10;
  592. $order = 'recency';
  593. $category = 'discussion';
  594. $modified_since = '1302727083000';
  595. // Set request parameters.
  596. $data['format'] = 'json';
  597. $data['start'] = $start;
  598. $data['count'] = $count;
  599. $data['order'] = $order;
  600. $data['category'] = $category;
  601. $data['modified-since'] = $modified_since;
  602. $path = '/v1/groups/' . $id . '/posts';
  603. $path .= ':' . $fields;
  604. $returnData = new stdClass;
  605. $returnData->code = 401;
  606. $returnData->body = $this->errorString;
  607. $path = $this->oauth->toUrl($path, $data);
  608. $this->client->expects($this->once())
  609. ->method('get')
  610. ->with($path)
  611. ->will($this->returnValue($returnData));
  612. $this->object->getDiscussions($id, $fields, $start, $count, $order, $category, $modified_since);
  613. }
  614. /**
  615. * Tests the getUserPosts method
  616. *
  617. * @param string $person_id The unique identifier for a user.
  618. *
  619. * @return void
  620. *
  621. * @dataProvider seedId
  622. * @since 13.1
  623. */
  624. public function testGetUserPosts($person_id)
  625. {
  626. $group_id = '12345';
  627. $role = 'creator';
  628. $fields = '(creation-timestamp,title,summary,creator:(first-name,last-name),likes,attachment:(content-url,title),relation-to-viewer)';
  629. $start = 1;
  630. $count = 10;
  631. $order = 'recency';
  632. $category = 'discussion';
  633. $modified_since = '1302727083000';
  634. // Set request parameters.
  635. $data['format'] = 'json';
  636. $data['role'] = $role;
  637. $data['start'] = $start;
  638. $data['count'] = $count;
  639. $data['order'] = $order;
  640. $data['category'] = $category;
  641. $data['modified-since'] = $modified_since;
  642. if ($person_id)
  643. {
  644. $path = '/v1/people/' . $person_id . '/group-memberships/' . $group_id . '/posts';
  645. }
  646. else
  647. {
  648. $path = '/v1/people/~/group-memberships/' . $group_id . '/posts';
  649. }
  650. $path .= ':' . $fields;
  651. $returnData = new stdClass;
  652. $returnData->code = 200;
  653. $returnData->body = $this->sampleString;
  654. $path = $this->oauth->toUrl($path, $data);
  655. $this->client->expects($this->once())
  656. ->method('get')
  657. ->with($path)
  658. ->will($this->returnValue($returnData));
  659. $this->assertThat(
  660. $this->object->getUserPosts($group_id, $role, $person_id, $fields, $start, $count, $order, $category, $modified_since),
  661. $this->equalTo(json_decode($this->sampleString))
  662. );
  663. }
  664. /**
  665. * Tests the getUserPosts method - failure
  666. *
  667. * @return void
  668. *
  669. * @expectedException DomainException
  670. * @since 13.1
  671. */
  672. public function testGetUserPostsFailure()
  673. {
  674. $group_id = '12345';
  675. $role = 'creator';
  676. $person_id = '123345456';
  677. $fields = '(creation-timestamp,title,summary,creator:(first-name,last-name),likes,attachment:(content-url,title),relation-to-viewer)';
  678. $start = 1;
  679. $count = 10;
  680. $order = 'recency';
  681. $category = 'discussion';
  682. $modified_since = '1302727083000';
  683. // Set request parameters.
  684. $data['format'] = 'json';
  685. $data['role'] = $role;
  686. $data['start'] = $start;
  687. $data['count'] = $count;
  688. $data['order'] = $order;
  689. $data['category'] = $category;
  690. $data['modified-since'] = $modified_since;
  691. $path = '/v1/people/' . $person_id . '/group-memberships/' . $group_id . '/posts';
  692. $path .= ':' . $fields;
  693. $returnData = new stdClass;
  694. $returnData->code = 401;
  695. $returnData->body = $this->errorString;
  696. $path = $this->oauth->toUrl($path, $data);
  697. $this->client->expects($this->once())
  698. ->method('get')
  699. ->with($path)
  700. ->will($this->returnValue($returnData));
  701. $this->object->getUserPosts($group_id, $role, $person_id, $fields, $start, $count, $order, $category, $modified_since);
  702. }
  703. /**
  704. * Tests the getPost method
  705. *
  706. * @return void
  707. *
  708. * @since 13.1
  709. */
  710. public function testGetPost()
  711. {
  712. $post_id = 'g-12345';
  713. $fields = '(id,type,category,creator,title,relation-to-viewer:(is-following,is-liked),likes,comments,site-group-post-url)';
  714. // Set request parameters.
  715. $data['format'] = 'json';
  716. $path = '/v1/posts/' . $post_id;
  717. $path .= ':' . $fields;
  718. $returnData = new stdClass;
  719. $returnData->code = 200;
  720. $returnData->body = $this->sampleString;
  721. $path = $this->oauth->toUrl($path, $data);
  722. $this->client->expects($this->once())
  723. ->method('get')
  724. ->with($path)
  725. ->will($this->returnValue($returnData));
  726. $this->assertThat(
  727. $this->object->getPost($post_id, $fields),
  728. $this->equalTo(json_decode($this->sampleString))
  729. );
  730. }
  731. /**
  732. * Tests the getPost method - failure
  733. *
  734. * @return void
  735. *
  736. * @expectedException DomainException
  737. * @since 13.1
  738. */
  739. public function testGetPostFailure()
  740. {
  741. $post_id = 'g-12345';
  742. $fields = '(id,type,category,creator,title,relation-to-viewer:(is-following,is-liked),likes,comments,site-group-post-url)';
  743. // Set request parameters.
  744. $data['format'] = 'json';
  745. $path = '/v1/posts/' . $post_id;
  746. $path .= ':' . $fields;
  747. $returnData = new stdClass;
  748. $returnData->code = 401;
  749. $returnData->body = $this->errorString;
  750. $path = $this->oauth->toUrl($path, $data);
  751. $this->client->expects($this->once())
  752. ->method('get')
  753. ->with($path)
  754. ->will($this->returnValue($returnData));
  755. $this->object->getPost($post_id, $fields);
  756. }
  757. /**
  758. * Tests the getPostComments method
  759. *
  760. * @return void
  761. *
  762. * @since 13.1
  763. */
  764. public function testGetPostComments()
  765. {
  766. $post_id = 'g-12345';
  767. $fields = '(creator:(first-name,last-name,picture-url),creation-timestamp,text))';
  768. $start = 1;
  769. $count = 5;
  770. // Set request parameters.
  771. $data['format'] = 'json';
  772. $data['start'] = $start;
  773. $data['count'] = $count;
  774. $path = '/v1/posts/' . $post_id . '/comments';
  775. $path .= ':' . $fields;
  776. $returnData = new stdClass;
  777. $returnData->code = 200;
  778. $returnData->body = $this->sampleString;
  779. $path = $this->oauth->toUrl($path, $data);
  780. $this->client->expects($this->once())
  781. ->method('get')
  782. ->with($path)
  783. ->will($this->returnValue($returnData));
  784. $this->assertThat(
  785. $this->object->getPostComments($post_id, $fields, $start, $count),
  786. $this->equalTo(json_decode($this->sampleString))
  787. );
  788. }
  789. /**
  790. * Tests the getPostComments method - failure
  791. *
  792. * @return void
  793. *
  794. * @expectedException DomainException
  795. * @since 13.1
  796. */
  797. public function testGetPostCommentsFailure()
  798. {
  799. $post_id = 'g-12345';
  800. $fields = '(creator:(first-name,last-name,picture-url),creation-timestamp,text))';
  801. $start = 1;
  802. $count = 5;
  803. // Set request parameters.
  804. $data['format'] = 'json';
  805. $data['start'] = $start;
  806. $data['count'] = $count;
  807. $path = '/v1/posts/' . $post_id . '/comments';
  808. $path .= ':' . $fields;
  809. $returnData = new stdClass;
  810. $returnData->code = 401;
  811. $returnData->body = $this->errorString;
  812. $path = $this->oauth->toUrl($path, $data);
  813. $this->client->expects($this->once())
  814. ->method('get')
  815. ->with($path)
  816. ->will($this->returnValue($returnData));
  817. $this->object->getPostComments($post_id, $fields, $start, $count);
  818. }
  819. /**
  820. * Tests the createPost method
  821. *
  822. * @return void
  823. *
  824. * @since 13.1
  825. */
  826. public function testCreatePost()
  827. {
  828. $group_id = '12345';
  829. $title = 'post title';
  830. $summary = 'post summary';
  831. $path = '/v1/groups/' . $group_id . '/posts';
  832. $xml = '<post><title>' . $title . '</title><summary>' . $summary . '</summary></post>';
  833. $header['Content-Type'] = 'text/xml';
  834. $returnData = new stdClass;
  835. $returnData->code = 201;
  836. $returnData->body = $this->sampleString;
  837. $returnData->headers = array('Location' => 'https://api.linkedin.com/v1/posts/g_12334_234512');
  838. $this->client->expects($this->once())
  839. ->method('post', $xml, $header)
  840. ->with($path)
  841. ->will($this->returnValue($returnData));
  842. $this->assertThat(
  843. $this->object->createPost($group_id, $title, $summary),
  844. $this->equalTo('g_12334_234512')
  845. );
  846. }
  847. /**
  848. * Tests the createPost method - failure
  849. *
  850. * @return void
  851. *
  852. * @expectedException DomainException
  853. * @since 13.1
  854. */
  855. public function testCreatePostFailure()
  856. {
  857. $group_id = '12345';
  858. $title = 'post title';
  859. $summary = 'post summary';
  860. $path = '/v1/groups/' . $group_id . '/posts';
  861. $xml = '<post><title>' . $title . '</title><summary>' . $summary . '</summary></post>';
  862. $header['Content-Type'] = 'text/xml';
  863. $returnData = new stdClass;
  864. $returnData->code = 401;
  865. $returnData->body = $this->errorString;
  866. $this->client->expects($this->once())
  867. ->method('post', $xml, $header)
  868. ->with($path)
  869. ->will($this->returnValue($returnData));
  870. $this->object->createPost($group_id, $title, $summary);
  871. }
  872. /**
  873. * Tests the _likeUnlike method
  874. *
  875. * @return void
  876. *
  877. * @since 13.1
  878. */
  879. public function test_likeUnlike()
  880. {
  881. // Method tested via requesting classes
  882. $this->markTestSkipped('This method is tested via requesting classes.');
  883. }
  884. /**
  885. * Tests the likePost method
  886. *
  887. * @return void
  888. *
  889. * @since 13.1
  890. */
  891. public function testLikePost()
  892. {
  893. $post_id = 'g_12345';
  894. $path = '/v1/posts/' . $post_id . '/relation-to-viewer/is-liked';
  895. $xml = '<is-liked>true</is-liked>';
  896. $header['Content-Type'] = 'text/xml';
  897. $returnData = new stdClass;
  898. $returnData->code = 204;
  899. $returnData->body = $this->sampleString;
  900. $this->client->expects($this->once())
  901. ->method('put', $xml, $header)
  902. ->with($path)
  903. ->will($this->returnValue($returnData));
  904. $this->assertThat(
  905. $this->object->likePost($post_id),
  906. $this->equalTo($returnData)
  907. );
  908. }
  909. /**
  910. * Tests the likePost method - failure
  911. *
  912. * @return void
  913. *
  914. * @expectedException DomainException
  915. * @since 13.1
  916. */
  917. public function testLikePostFailure()
  918. {
  919. $post_id = 'g_12345';
  920. $path = '/v1/posts/' . $post_id . '/relation-to-viewer/is-liked';
  921. $xml = '<is-liked>true</is-liked>';
  922. $header['Content-Type'] = 'text/xml';
  923. $returnData = new stdClass;
  924. $returnData->code = 401;
  925. $returnData->body = $this->errorString;
  926. $this->client->expects($this->once())
  927. ->method('put', $xml, $header)
  928. ->with($path)
  929. ->will($this->returnValue($returnData));
  930. $this->object->likePost($post_id);
  931. }
  932. /**
  933. * Tests the unlikePost method
  934. *
  935. * @return void
  936. *
  937. * @since 13.1
  938. */
  939. public function testUnlikePost()
  940. {
  941. $post_id = 'g_12345';
  942. $path = '/v1/posts/' . $post_id . '/relation-to-viewer/is-liked';
  943. $xml = '<is-liked>false</is-liked>';
  944. $header['Content-Type'] = 'text/xml';
  945. $returnData = new stdClass;
  946. $returnData->code = 204;
  947. $returnData->body = $this->sampleString;
  948. $this->client->expects($this->once())
  949. ->method('put', $xml, $header)
  950. ->with($path)
  951. ->will($this->returnValue($returnData));
  952. $this->assertThat(
  953. $this->object->unlikePost($post_id),
  954. $this->equalTo($returnData)
  955. );
  956. }
  957. /**
  958. * Tests the _followUnfollow method
  959. *
  960. * @return void
  961. *
  962. * @since 13.1
  963. */
  964. public function test_followUnfollow()
  965. {
  966. // Method tested via requesting classes
  967. $this->markTestSkipped('This method is tested via requesting classes.');
  968. }
  969. /**
  970. * Tests the followPost method
  971. *
  972. * @return void
  973. *
  974. * @since 13.1
  975. */
  976. public function testFollowPost()
  977. {
  978. $post_id = 'g_12345';
  979. $path = '/v1/posts/' . $post_id . '/relation-to-viewer/is-following';
  980. $xml = '<is-following>true</is-following>';
  981. $header['Content-Type'] = 'text/xml';
  982. $returnData = new stdClass;
  983. $returnData->code = 204;
  984. $returnData->body = $this->sampleString;
  985. $this->client->expects($this->once())
  986. ->method('put', $xml, $header)
  987. ->with($path)
  988. ->will($this->returnValue($returnData));
  989. $this->assertThat(
  990. $this->object->followPost($post_id),
  991. $this->equalTo($returnData)
  992. );
  993. }
  994. /**
  995. * Tests the followPost method - failure
  996. *
  997. * @return void
  998. *
  999. * @expectedException DomainException
  1000. * @since 13.1
  1001. */
  1002. public function testFollowPostFailure()
  1003. {
  1004. $post_id = 'g_12345';
  1005. $path = '/v1/posts/' . $post_id . '/relation-to-viewer/is-following';
  1006. $xml = '<is-following>true</is-following>';
  1007. $header['Content-Type'] = 'text/xml';
  1008. $returnData = new stdClass;
  1009. $returnData->code = 401;
  1010. $returnData->body = $this->errorString;
  1011. $this->client->expects($this->once())
  1012. ->method('put', $xml, $header)
  1013. ->with($path)
  1014. ->will($this->returnValue($returnData));
  1015. $this->object->followPost($post_id);
  1016. }
  1017. /**
  1018. * Tests the unfollowPost method
  1019. *
  1020. * @return void
  1021. *
  1022. * @since 13.1
  1023. */
  1024. public function testUnfollowPost()
  1025. {
  1026. $post_id = 'g_12345';
  1027. $path = '/v1/posts/' . $post_id . '/relation-to-viewer/is-following';
  1028. $xml = '<is-following>false</is-following>';
  1029. $header['Content-Type'] = 'text/xml';
  1030. $returnData = new stdClass;
  1031. $returnData->code = 204;
  1032. $returnData->body = $this->sampleString;
  1033. $this->client->expects($this->once())
  1034. ->method('put', $xml, $header)
  1035. ->with($path)
  1036. ->will($this->returnValue($returnData));
  1037. $this->assertThat(
  1038. $this->object->unfollowPost($post_id),
  1039. $this->equalTo($returnData)
  1040. );
  1041. }
  1042. /**
  1043. * Tests the flagPost method
  1044. *
  1045. * @return void
  1046. *
  1047. * @since 13.1
  1048. */
  1049. public function testFalgPost()
  1050. {
  1051. $flag = 'promotion';
  1052. $post_id = 'g_12345';
  1053. $path = '/v1/posts/' . $post_id . '/category/code';
  1054. $xml = '<code>' . $flag . '</code>';
  1055. $header['Content-Type'] = 'text/xml';
  1056. $returnData = new stdClass;
  1057. $returnData->code = 204;
  1058. $returnData->body = $this->sampleString;
  1059. $this->client->expects($this->once())
  1060. ->method('put', $xml, $header)
  1061. ->with($path)
  1062. ->will($this->returnValue($returnData));
  1063. $this->assertThat(
  1064. $this->object->flagPost($post_id, $flag),
  1065. $this->equalTo($returnData)
  1066. );
  1067. }
  1068. /**
  1069. * Tests the flagPost method - failure
  1070. *
  1071. * @return void
  1072. *
  1073. * @expectedException DomainException
  1074. * @since 13.1
  1075. */
  1076. public function testFalgPostFailure()
  1077. {
  1078. $flag = 'promotion';
  1079. $post_id = 'g_12345';
  1080. $path = '/v1/posts/' . $post_id . '/category/code';
  1081. $xml = '<code>' . $flag . '</code>';
  1082. $header['Content-Type'] = 'text/xml';
  1083. $returnData = new stdClass;
  1084. $returnData->code = 401;
  1085. $returnData->body = $this->errorString;
  1086. $this->client->expects($this->once())
  1087. ->method('put', $xml, $header)
  1088. ->with($path)
  1089. ->will($this->returnValue($returnData));
  1090. $this->object->flagPost($post_id, $flag);
  1091. }
  1092. /**
  1093. * Tests the deletePost method
  1094. *
  1095. * @return void
  1096. *
  1097. * @since 13.1
  1098. */
  1099. public function testDeletePost()
  1100. {
  1101. $post_id = 'g_12345';
  1102. $path = '/v1/posts/' . $post_id;
  1103. $returnData = new stdClass;
  1104. $returnData->code = 204;
  1105. $returnData->body = $this->sampleString;
  1106. $this->client->expects($this->once())
  1107. ->method('delete')
  1108. ->with($path)
  1109. ->will($this->returnValue($returnData));
  1110. $this->assertThat(
  1111. $this->object->deletePost($post_id),
  1112. $this->equalTo($returnData)
  1113. );
  1114. }
  1115. /**
  1116. * Tests the deletePost method - failure
  1117. *
  1118. * @return void
  1119. *
  1120. * @expectedException DomainException
  1121. * @since 13.1
  1122. */
  1123. public function testDeletePostFailure()
  1124. {
  1125. $post_id = 'g_12345';
  1126. $path = '/v1/posts/' . $post_id;
  1127. $returnData = new stdClass;
  1128. $returnData->code = 401;
  1129. $returnData->body = $this->errorString;
  1130. $this->client->expects($this->once())
  1131. ->method('delete')
  1132. ->with($path)
  1133. ->will($this->returnValue($returnData));
  1134. $this->object->deletePost($post_id);
  1135. }
  1136. /**
  1137. * Tests the getComment method
  1138. *
  1139. * @return void
  1140. *
  1141. * @since 13.1
  1142. */
  1143. public function testGetComment()
  1144. {
  1145. $comment_id = 'g-12345';
  1146. $fields = '(id,text,creator,creation-timestamp,relation-to-viewer)';
  1147. // Set request parameters.
  1148. $data['format'] = 'json';
  1149. $path = '/v1/comments/' . $comment_id;
  1150. $path .= ':' . $fields;
  1151. $returnData = new stdClass;
  1152. $returnData->code = 200;
  1153. $returnData->body = $this->sampleString;
  1154. $path = $this->oauth->toUrl($path, $data);
  1155. $this->client->expects($this->once())
  1156. ->method('get')
  1157. ->with($path)
  1158. ->will($this->returnValue($returnData));
  1159. $this->assertThat(
  1160. $this->object->getComment($comment_id, $fields),
  1161. $this->equalTo(json_decode($this->sampleString))
  1162. );
  1163. }
  1164. /**
  1165. * Tests the getComment method - failure
  1166. *
  1167. * @return void
  1168. *
  1169. * @expectedException DomainException
  1170. * @since 13.1
  1171. */
  1172. public function testGetCommentFailure()
  1173. {
  1174. $comment_id = 'g-12345';
  1175. $fields = '(id,text,creator,creation-timestamp,relation-to-viewer)';
  1176. // Set request parameters.
  1177. $data['format'] = 'json';
  1178. $path = '/v1/comments/' . $comment_id;
  1179. $path .= ':' . $fields;
  1180. $returnData = new stdClass;
  1181. $returnData->code = 401;
  1182. $returnData->body = $this->errorString;
  1183. $path = $this->oauth->toUrl($path, $data);
  1184. $this->client->expects($this->once())
  1185. ->method('get')
  1186. ->with($path)
  1187. ->will($this->returnValue($returnData));
  1188. $this->object->getComment($comment_id, $fields);
  1189. }
  1190. /**
  1191. * Tests the addComment method
  1192. *
  1193. * @return void
  1194. *
  1195. * @since 13.1
  1196. */
  1197. public function testAddComment()
  1198. {
  1199. $post_id = 'g_12345';
  1200. $comment = 'some comment';
  1201. $path = '/v1/posts/' . $post_id . '/comments';
  1202. $xml = '<comment><text>' . $comment . '</text></comment>';
  1203. $header['Content-Type'] = 'text/xml';
  1204. $returnData = new stdClass;
  1205. $returnData->code = 201;
  1206. $returnData->body = $this->sampleString;
  1207. $returnData->headers = array('Location' => 'https://api.linkedin.com/v1/comments/g_12334_234512');
  1208. $this->client->expects($this->once())
  1209. ->method('post', $xml, $header)
  1210. ->with($path)
  1211. ->will($this->returnValue($returnData));
  1212. $this->assertThat(
  1213. $this->object->addComment($post_id, $comment),
  1214. $this->equalTo('g_12334_234512')
  1215. );
  1216. }
  1217. /**
  1218. * Tests the addComment method - failure
  1219. *
  1220. * @return void
  1221. *
  1222. * @expectedException DomainException
  1223. * @since 13.1
  1224. */
  1225. public function testAddCommentFailure()
  1226. {
  1227. $post_id = 'g_12345';
  1228. $comment = 'some comment';
  1229. $path = '/v1/posts/' . $post_id . '/comments';
  1230. $xml = '<comment><text>' . $comment . '</text></comment>';
  1231. $header['Content-Type'] = 'text/xml';
  1232. $returnData = new stdClass;
  1233. $returnData->code = 401;
  1234. $returnData->body = $this->errorString;
  1235. $this->client->expects($this->once())
  1236. ->method('post', $xml, $header)
  1237. ->with($path)
  1238. ->will($this->returnValue($returnData));
  1239. $this->object->addComment($post_id, $comment);
  1240. }
  1241. /**
  1242. * Tests the deleteComment method
  1243. *
  1244. * @return void
  1245. *
  1246. * @since 13.1
  1247. */
  1248. public function testDeleteComment()
  1249. {
  1250. $comment_id = 'g_12345';
  1251. $path = '/v1/comments/' . $comment_id;
  1252. $returnData = new stdClass;
  1253. $returnData->code = 204;
  1254. $returnData->body = $this->sampleString;
  1255. $this->client->expects($this->once())
  1256. ->method('delete')
  1257. ->with($path)
  1258. ->will($this->returnValue($returnData));
  1259. $this->assertThat(
  1260. $this->object->deleteComment($comment_id),
  1261. $this->equalTo($returnData)
  1262. );
  1263. }
  1264. /**
  1265. * Tests the deleteComment method - failure
  1266. *
  1267. * @return void
  1268. *
  1269. * @expectedException DomainException
  1270. * @since 13.1
  1271. */
  1272. public function testDeleteCommentFailure()
  1273. {
  1274. $comment_id = 'g_12345';
  1275. $path = '/v1/comments/' . $comment_id;
  1276. $returnData = new stdClass;
  1277. $returnData->code = 401;
  1278. $returnData->body = $this->errorString;
  1279. $this->client->expects($this->once())
  1280. ->method('delete')
  1281. ->with($path)
  1282. ->will($this->returnValue($returnData));
  1283. $this->object->deleteComment($comment_id);
  1284. }
  1285. /**
  1286. * Tests the getSuggested method
  1287. *
  1288. * @param string $person_id The unique identifier for a user.
  1289. *
  1290. * @return void
  1291. *
  1292. * @dataProvider seedId
  1293. * @since 13.1
  1294. */
  1295. public function testGetSuggested($person_id)
  1296. {
  1297. $fields = '(id,name,is-open-to-non-members)';
  1298. // Set request parameters.
  1299. $data['format'] = 'json';
  1300. // Set the API base
  1301. $path = '/v1/people/';
  1302. if ($person_id)
  1303. {
  1304. $path .= $person_id . '/suggestions/groups';
  1305. }
  1306. else
  1307. {
  1308. $path .= '~/suggestions/groups';
  1309. }
  1310. $path .= ':' . $fields;
  1311. $returnData = new stdClass;
  1312. $returnData->code = 200;
  1313. $returnData->body = $this->sampleString;
  1314. $path = $this->oauth->toUrl($path, $data);
  1315. $this->client->expects($this->once())
  1316. ->method('get')
  1317. ->with($path)
  1318. ->will($this->returnValue($returnData));
  1319. $this->assertThat(
  1320. $this->object->getSuggested($person_id, $fields),
  1321. $this->equalTo(json_decode($this->sampleString))
  1322. );
  1323. }
  1324. /**
  1325. * Tests the getSuggested method - failure
  1326. *
  1327. * @param string $person_id The unique identifier for a user.
  1328. *
  1329. * @return void
  1330. *
  1331. * @dataProvider seedId
  1332. * @expectedException DomainException
  1333. * @since 13.1
  1334. */
  1335. public function testGetSuggestedFailure($person_id)
  1336. {
  1337. $fields = '(id,name,is-open-to-non-members)';
  1338. // Set request parameters.
  1339. $data['format'] = 'json';
  1340. // Set the API base
  1341. $path = '/v1/people/';
  1342. if ($person_id)
  1343. {
  1344. $path .= $person_id . '/suggestions/groups';
  1345. }
  1346. else
  1347. {
  1348. $path .= '~/suggestions/groups';
  1349. }
  1350. $path .= ':' . $fields;
  1351. $returnData = new stdClass;
  1352. $returnData->code = 401;
  1353. $returnData->body = $this->errorString;
  1354. $path = $this->oauth->toUrl($path, $data);
  1355. $this->client->expects($this->once())
  1356. ->method('get')
  1357. ->with($path)
  1358. ->will($this->returnValue($returnData));
  1359. $this->object->getSuggested($person_id, $fields);
  1360. }
  1361. /**
  1362. * Tests the deleteSuggestion method
  1363. *
  1364. * @param string $person_id The unique identifier for a user.
  1365. *
  1366. * @return void
  1367. *
  1368. * @dataProvider seedId
  1369. * @since 13.1
  1370. */
  1371. public function testDeleteSuggestion($person_id)
  1372. {
  1373. $suggestion_id = '12345';
  1374. // Set the API base
  1375. $path = '/v1/people/';
  1376. if ($person_id)
  1377. {
  1378. $path .= $person_id . '/suggestions/groups/' . $suggestion_id;
  1379. }
  1380. else
  1381. {
  1382. $path .= '~/suggestions/groups/' . $suggestion_id;
  1383. }
  1384. $returnData = new stdClass;
  1385. $returnData->code = 204;
  1386. $returnData->body = $this->sampleString;
  1387. $this->client->expects($this->once())
  1388. ->method('delete')
  1389. ->with($path)
  1390. ->will($this->returnValue($returnData));
  1391. $this->assertThat(
  1392. $this->object->deleteSuggestion($suggestion_id, $person_id),
  1393. $this->equalTo($returnData)
  1394. );
  1395. }
  1396. /**
  1397. * Tests the deleteSuggestion method - failure
  1398. *
  1399. * @param string $person_id The unique identifier for a user.
  1400. *
  1401. * @return void
  1402. *
  1403. * @dataProvider seedId
  1404. * @expectedException DomainException
  1405. * @since 13.1
  1406. */
  1407. public function testDeleteSuggestionFailure($person_id)
  1408. {
  1409. $suggestion_id = '12345';
  1410. // Set the API base
  1411. $path = '/v1/people/';
  1412. if ($person_id)
  1413. {
  1414. $path .= $person_id . '/suggestions/groups/' . $suggestion_id;
  1415. }
  1416. else
  1417. {
  1418. $path .= '~/suggestions/groups/' . $suggestion_id;
  1419. }
  1420. $returnData = new stdClass;
  1421. $returnData->code = 401;
  1422. $returnData->body = $this->errorString;
  1423. $this->client->expects($this->once())
  1424. ->method('delete')
  1425. ->with($path)
  1426. ->will($this->returnValue($returnData));
  1427. $this->object->deleteSuggestion($suggestion_id, $person_id);
  1428. }
  1429. }