PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Joomla/Linkedin/Tests/GroupsTest.php

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