PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/src/Joomla/Linkedin/Tests/StreamTest.php

https://github.com/piotr-cz/joomla-framework
PHP | 997 lines | 557 code | 179 blank | 261 comment | 10 complexity | 008c5e0a8d24d51b29c416723d53b621 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\Stream;
  8. use \DomainException;
  9. use \stdClass;
  10. require_once __DIR__ . '/case/LinkedinTestCase.php';
  11. /**
  12. * Test class for Stream.
  13. *
  14. * @since 1.0
  15. */
  16. class StreamTest 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 Stream($this->options, $this->client, $this->oauth);
  28. }
  29. /**
  30. * Provides test data for request format detection.
  31. *
  32. * @return array
  33. *
  34. * @since 1.0
  35. */
  36. public function seedShare()
  37. {
  38. // Company comment, title, url, image, description
  39. return array(
  40. array('some comment', 'title example', 'www.example.com', 'www.image-example.com', 'description text'),
  41. array(null, 'title example', null, 'www.image-example.com', 'description text')
  42. );
  43. }
  44. /**
  45. * Tests the share method
  46. *
  47. * @param string $comment Text of member's comment.
  48. * @param string $title Title of shared document.
  49. * @param string $url URL for shared content.
  50. * @param string $image URL for image of shared content.
  51. * @param string $description Description of shared content.
  52. *
  53. * @return void
  54. *
  55. * @dataProvider seedShare
  56. * @since 1.0
  57. */
  58. public function testShare($comment, $title, $url, $image, $description)
  59. {
  60. $visibility = 'anyone';
  61. $twitter = true;
  62. $path = '/v1/people/~/shares?twitter-post=true';
  63. // Build xml.
  64. $xml = '<share>
  65. <visibility>
  66. <code>' . $visibility . '</code>
  67. </visibility>';
  68. // Check if comment specified.
  69. if ($comment)
  70. {
  71. $xml .= '<comment>' . $comment . '</comment>';
  72. }
  73. // Check if title and url are specified.
  74. if ($title && $url)
  75. {
  76. $xml .= '<content>
  77. <title>' . $title . '</title>
  78. <submitted-url>' . $url . '</submitted-url>
  79. <submitted-image-url>' . $image . '</submitted-image-url>
  80. <description>' . $description . '</description>
  81. </content>';
  82. }
  83. elseif (!$comment)
  84. {
  85. $this->setExpectedException('RuntimeException');
  86. $this->object->share($visibility, $comment, $title, $url, $image, $description, $twitter);
  87. }
  88. $xml .= '</share>';
  89. $header['Content-Type'] = 'text/xml';
  90. $returnData = new stdClass;
  91. $returnData->code = 201;
  92. $returnData->body = $this->sampleString;
  93. $this->client->expects($this->once())
  94. ->method('post', $xml, $header)
  95. ->with($path)
  96. ->will($this->returnValue($returnData));
  97. $this->assertThat(
  98. $this->object->share($visibility, $comment, $title, $url, $image, $description, $twitter),
  99. $this->equalTo($returnData)
  100. );
  101. }
  102. /**
  103. * Tests the share method - failure
  104. *
  105. * @return void
  106. *
  107. * @expectedException DomainException
  108. * @since 1.0
  109. */
  110. public function testShareFailure()
  111. {
  112. $comment = 'some comment';
  113. $visibility = 'anyone';
  114. $path = '/v1/people/~/shares';
  115. // Build xml.
  116. $xml = '<share>
  117. <visibility>
  118. <code>' . $visibility . '</code>
  119. </visibility>
  120. <comment>' . $comment . '</comment>
  121. </share>';
  122. $header['Content-Type'] = 'text/xml';
  123. $returnData = new stdClass;
  124. $returnData->code = 401;
  125. $returnData->body = $this->errorString;
  126. $this->client->expects($this->once())
  127. ->method('post', $xml, $header)
  128. ->with($path)
  129. ->will($this->returnValue($returnData));
  130. $this->object->share($visibility, $comment);
  131. }
  132. /**
  133. * Tests the reshare method
  134. *
  135. * @return void
  136. *
  137. * @since 1.0
  138. */
  139. public function testReshare()
  140. {
  141. $id = 's123435';
  142. $visibility = 'anyone';
  143. $comment = 'some comment';
  144. $twitter = true;
  145. $path = '/v1/people/~/shares?twitter-post=true';
  146. // Build xml.
  147. $xml = '<share>
  148. <visibility>
  149. <code>' . $visibility . '</code>
  150. </visibility>';
  151. // Check if comment specified.
  152. if ($comment)
  153. {
  154. $xml .= '<comment>' . $comment . '</comment>';
  155. }
  156. $xml .= ' <attribution>
  157. <share>
  158. <id>' . $id . '</id>
  159. </share>
  160. </attribution>
  161. </share>';
  162. $header['Content-Type'] = 'text/xml';
  163. $returnData = new stdClass;
  164. $returnData->code = 201;
  165. $returnData->body = $this->sampleString;
  166. $this->client->expects($this->once())
  167. ->method('post', $xml, $header)
  168. ->with($path)
  169. ->will($this->returnValue($returnData));
  170. $this->assertThat(
  171. $this->object->reshare($visibility, $id, $comment, $twitter),
  172. $this->equalTo($returnData)
  173. );
  174. }
  175. /**
  176. * Tests the reshare method - failure
  177. *
  178. * @return void
  179. *
  180. * @expectedException DomainException
  181. * @since 1.0
  182. */
  183. public function testReshareFailure()
  184. {
  185. $id = 's123435';
  186. $visibility = 'anyone';
  187. $comment = 'some comment';
  188. $twitter = true;
  189. $path = '/v1/people/~/shares?twitter-post=true';
  190. // Build xml.
  191. $xml = '<share>
  192. <visibility>
  193. <code>' . $visibility . '</code>
  194. </visibility>';
  195. // Check if comment specified.
  196. if ($comment)
  197. {
  198. $xml .= '<comment>' . $comment . '</comment>';
  199. }
  200. $xml .= ' <attribution>
  201. <share>
  202. <id>' . $id . '</id>
  203. </share>
  204. </attribution>
  205. </share>';
  206. $header['Content-Type'] = 'text/xml';
  207. $returnData = new stdClass;
  208. $returnData->code = 401;
  209. $returnData->body = $this->errorString;
  210. $this->client->expects($this->once())
  211. ->method('post', $xml, $header)
  212. ->with($path)
  213. ->will($this->returnValue($returnData));
  214. $this->object->reshare($visibility, $id, $comment, $twitter);
  215. }
  216. /**
  217. * Provides test data for request format detection.
  218. *
  219. * @return array
  220. *
  221. * @since 1.0
  222. */
  223. public function seedIdUrl()
  224. {
  225. // Member ID or url
  226. return array(
  227. array('lcnIwDU0S6', null),
  228. array(null, 'http://www.linkedin.com/in/dianaprajescu'),
  229. array(null, null)
  230. );
  231. }
  232. /**
  233. * Tests the getCurrentShare method
  234. *
  235. * @param string $id Member id of the profile you want.
  236. * @param string $url The public profile URL.
  237. *
  238. * @return void
  239. *
  240. * @dataProvider seedIdUrl
  241. * @since 1.0
  242. */
  243. public function testGetCurrentShare($id, $url)
  244. {
  245. // Set request parameters.
  246. $data['format'] = 'json';
  247. $path = '/v1/people/';
  248. if ($url)
  249. {
  250. $path .= 'url=' . $this->oauth->safeEncode($url);
  251. }
  252. if ($id)
  253. {
  254. $path .= 'id=' . $id;
  255. }
  256. elseif (!$url)
  257. {
  258. $path .= '~';
  259. }
  260. $path .= ':(current-share)';
  261. $returnData = new stdClass;
  262. $returnData->code = 200;
  263. $returnData->body = $this->sampleString;
  264. $path = $this->oauth->toUrl($path, $data);
  265. $this->client->expects($this->once())
  266. ->method('get')
  267. ->with($path)
  268. ->will($this->returnValue($returnData));
  269. $this->assertThat(
  270. $this->object->getCurrentShare($id, $url),
  271. $this->equalTo(json_decode($this->sampleString))
  272. );
  273. }
  274. /**
  275. * Tests the getCurrentShare method - failure
  276. *
  277. * @return void
  278. *
  279. * @expectedException DomainException
  280. * @since 1.0
  281. */
  282. public function testGetCurrentShareFailure()
  283. {
  284. // Set request parameters.
  285. $data['format'] = 'json';
  286. $path = '/v1/people/~:(current-share)';
  287. $returnData = new stdClass;
  288. $returnData->code = 401;
  289. $returnData->body = $this->errorString;
  290. $path = $this->oauth->toUrl($path, $data);
  291. $this->client->expects($this->once())
  292. ->method('get')
  293. ->with($path)
  294. ->will($this->returnValue($returnData));
  295. $this->object->getCurrentShare();
  296. }
  297. /**
  298. * Tests the getShareStream method
  299. *
  300. * @param string $id Member id of the profile you want.
  301. * @param string $url The public profile URL.
  302. *
  303. * @return void
  304. *
  305. * @dataProvider seedIdUrl
  306. * @since 1.0
  307. */
  308. public function testGetShareStream($id, $url)
  309. {
  310. // Set request parameters.
  311. $data['format'] = 'json';
  312. $data['type'] = 'SHAR';
  313. $data['scope'] = 'self';
  314. $path = '/v1/people/';
  315. if ($url)
  316. {
  317. $path .= 'url=' . $this->oauth->safeEncode($url);
  318. }
  319. if ($id)
  320. {
  321. $path .= $id;
  322. }
  323. elseif (!$url)
  324. {
  325. $path .= '~';
  326. }
  327. $path .= '/network';
  328. $returnData = new stdClass;
  329. $returnData->code = 200;
  330. $returnData->body = $this->sampleString;
  331. $path = $this->oauth->toUrl($path, $data);
  332. $this->client->expects($this->once())
  333. ->method('get')
  334. ->with($path)
  335. ->will($this->returnValue($returnData));
  336. $this->assertThat(
  337. $this->object->getShareStream($id, $url),
  338. $this->equalTo(json_decode($this->sampleString))
  339. );
  340. }
  341. /**
  342. * Tests the getShareStream method - failure
  343. *
  344. * @return void
  345. *
  346. * @expectedException DomainException
  347. * @since 1.0
  348. */
  349. public function testGetShareStreamFailure()
  350. {
  351. // Set request parameters.
  352. $data['format'] = 'json';
  353. $data['type'] = 'SHAR';
  354. $data['scope'] = 'self';
  355. $path = '/v1/people/~/network';
  356. $returnData = new stdClass;
  357. $returnData->code = 401;
  358. $returnData->body = $this->errorString;
  359. $path = $this->oauth->toUrl($path, $data);
  360. $this->client->expects($this->once())
  361. ->method('get')
  362. ->with($path)
  363. ->will($this->returnValue($returnData));
  364. $this->object->getShareStream();
  365. }
  366. /**
  367. * Provides test data for request format detection.
  368. *
  369. * @return array
  370. *
  371. * @since 1.0
  372. */
  373. public function seedId()
  374. {
  375. // Member ID or url
  376. return array(
  377. array('lcnIwDU0S6'),
  378. array(null)
  379. );
  380. }
  381. /**
  382. * Tests the getNetworkUpdates method
  383. *
  384. * @param string $id Member id.
  385. *
  386. * @return void
  387. *
  388. * @dataProvider seedId
  389. * @since 1.0
  390. */
  391. public function testGetNetworkUpdates($id)
  392. {
  393. $self = true;
  394. $type = array('PICT', 'STAT');
  395. $count = 50;
  396. $start = 1;
  397. $after = '123346574';
  398. $before = '123534663';
  399. $hidden = true;
  400. // Set request parameters.
  401. $data['format'] = 'json';
  402. $data['scope'] = 'self';
  403. $data['type'] = $type;
  404. $data['count'] = $count;
  405. $data['start'] = $start;
  406. $data['after'] = $after;
  407. $data['before'] = $before;
  408. $data['hidden'] = true;
  409. $path = '/v1/people/';
  410. if ($id)
  411. {
  412. $path .= $id;
  413. }
  414. else
  415. {
  416. $path .= '~';
  417. }
  418. $path .= '/network/updates';
  419. $returnData = new stdClass;
  420. $returnData->code = 200;
  421. $returnData->body = $this->sampleString;
  422. $path = $this->oauth->toUrl($path, $data);
  423. $this->client->expects($this->once())
  424. ->method('get')
  425. ->with($path)
  426. ->will($this->returnValue($returnData));
  427. $this->assertThat(
  428. $this->object->getNetworkUpdates($id, $self, $type, $count, $start, $after, $before, $hidden),
  429. $this->equalTo(json_decode($this->sampleString))
  430. );
  431. }
  432. /**
  433. * Tests the getNetworkUpdates method - failure
  434. *
  435. * @return void
  436. *
  437. * @expectedException DomainException
  438. * @since 1.0
  439. */
  440. public function testGetNetworkUpdatesFailure()
  441. {
  442. $self = true;
  443. $type = array('PICT', 'STAT');
  444. $count = 50;
  445. $start = 1;
  446. $after = '123346574';
  447. $before = '123534663';
  448. $hidden = true;
  449. // Set request parameters.
  450. $data['format'] = 'json';
  451. $data['scope'] = 'self';
  452. $data['type'] = $type;
  453. $data['count'] = $count;
  454. $data['start'] = $start;
  455. $data['after'] = $after;
  456. $data['before'] = $before;
  457. $data['hidden'] = true;
  458. $path = '/v1/people/~/network/updates';
  459. $returnData = new stdClass;
  460. $returnData->code = 401;
  461. $returnData->body = $this->errorString;
  462. $path = $this->oauth->toUrl($path, $data);
  463. $this->client->expects($this->once())
  464. ->method('get')
  465. ->with($path)
  466. ->will($this->returnValue($returnData));
  467. $this->object->getNetworkUpdates(null, $self, $type, $count, $start, $after, $before, $hidden);
  468. }
  469. /**
  470. * Tests the getNetworkStats method
  471. *
  472. * @return void
  473. *
  474. * @since 1.0
  475. */
  476. public function testGetNetworkStats()
  477. {
  478. // Set request parameters.
  479. $data['format'] = 'json';
  480. $path = '/v1/people/~/network/network-stats';
  481. $returnData = new stdClass;
  482. $returnData->code = 200;
  483. $returnData->body = $this->sampleString;
  484. $path = $this->oauth->toUrl($path, $data);
  485. $this->client->expects($this->once())
  486. ->method('get')
  487. ->with($path)
  488. ->will($this->returnValue($returnData));
  489. $this->assertThat(
  490. $this->object->getNetworkStats(),
  491. $this->equalTo(json_decode($this->sampleString))
  492. );
  493. }
  494. /**
  495. * Tests the getNetworkStats method - failure
  496. *
  497. * @return void
  498. *
  499. * @expectedException DomainException
  500. * @since 1.0
  501. */
  502. public function testGetNetworkStatsFailure()
  503. {
  504. // Set request parameters.
  505. $data['format'] = 'json';
  506. $path = '/v1/people/~/network/network-stats';
  507. $returnData = new stdClass;
  508. $returnData->code = 401;
  509. $returnData->body = $this->errorString;
  510. $path = $this->oauth->toUrl($path, $data);
  511. $this->client->expects($this->once())
  512. ->method('get')
  513. ->with($path)
  514. ->will($this->returnValue($returnData));
  515. $this->object->getNetworkStats();
  516. }
  517. /**
  518. * Tests the postNetworkUpdate method
  519. *
  520. * @return void
  521. *
  522. * @since 1.0
  523. */
  524. public function testPostNetworkUpdate()
  525. {
  526. $body = '&amp;lt;a href=&amp;quot;http://www.linkedin.com/profile?viewProfile=&amp;amp;key=3639896&amp;amp;authToken=JdAa&amp;amp;
  527. authType=name&amp;amp;trk=api*a119686*s128146*&amp;quot;&amp;gt;Kirsten Jones&amp;lt;/a&amp;gt; is reading about &amp;lt;
  528. a href=&amp;quot;http://www.tigers.com&amp;quot;&amp;gt;Tigers&amp;lt;/a&amp;gt;http://www.tigers.com&amp;gt;Tigers&amp;lt;/a&amp;gt;..';
  529. $path = '/v1/people/~/person-activities';
  530. // Build the xml.
  531. $xml = '<activity locale="en_US">
  532. <content-type>linkedin-html</content-type>
  533. <body>' . $body . '</body>
  534. </activity>';
  535. $header['Content-Type'] = 'text/xml';
  536. $returnData = new stdClass;
  537. $returnData->code = 201;
  538. $returnData->body = $this->sampleString;
  539. $this->client->expects($this->once())
  540. ->method('post', $xml, $header)
  541. ->with($path)
  542. ->will($this->returnValue($returnData));
  543. $this->assertThat(
  544. $this->object->postNetworkUpdate($body),
  545. $this->equalTo($returnData)
  546. );
  547. }
  548. /**
  549. * Tests the postNetworkUpdate method - failure
  550. *
  551. * @return void
  552. *
  553. * @expectedException DomainException
  554. * @since 1.0
  555. */
  556. public function testPostNetworkUpdateFailure()
  557. {
  558. $body = '&amp;lt;a href=&amp;quot;http://www.linkedin.com/profile?viewProfile=&amp;amp;key=3639896&amp;amp;authToken=JdAa&amp;amp;
  559. authType=name&amp;amp;trk=api*a119686*s128146*&amp;quot;&amp;gt;Kirsten Jones&amp;lt;/a&amp;gt; is reading about &amp;lt;
  560. a href=&amp;quot;http://www.tigers.com&amp;quot;&amp;gt;Tigers&amp;lt;/a&amp;gt;http://www.tigers.com&amp;gt;Tigers&amp;lt;/a&amp;gt;..';
  561. $path = '/v1/people/~/person-activities';
  562. // Build the xml.
  563. $xml = '<activity locale="en_US">
  564. <content-type>linkedin-html</content-type>
  565. <body>' . $body . '</body>
  566. </activity>';
  567. $header['Content-Type'] = 'text/xml';
  568. $returnData = new stdClass;
  569. $returnData->code = 401;
  570. $returnData->body = $this->errorString;
  571. $this->client->expects($this->once())
  572. ->method('post', $xml, $header)
  573. ->with($path)
  574. ->will($this->returnValue($returnData));
  575. $this->object->postNetworkUpdate($body);
  576. }
  577. /**
  578. * Tests the getComments method
  579. *
  580. * @return void
  581. *
  582. * @since 1.0
  583. */
  584. public function testGetComments()
  585. {
  586. $key = 'APPM-187317358-5635333363205165056-196773';
  587. // Set request parameters.
  588. $data['format'] = 'json';
  589. $path = '/v1/people/~/network/updates/key=' . $key . '/update-comments';
  590. $returnData = new stdClass;
  591. $returnData->code = 200;
  592. $returnData->body = $this->sampleString;
  593. $path = $this->oauth->toUrl($path, $data);
  594. $this->client->expects($this->once())
  595. ->method('get')
  596. ->with($path)
  597. ->will($this->returnValue($returnData));
  598. $this->assertThat(
  599. $this->object->getComments($key),
  600. $this->equalTo(json_decode($this->sampleString))
  601. );
  602. }
  603. /**
  604. * Tests the getComments method - failure
  605. *
  606. * @return void
  607. *
  608. * @expectedException DomainException
  609. * @since 1.0
  610. */
  611. public function testGetCommentsFailure()
  612. {
  613. $key = 'APPM-187317358-5635333363205165056-196773';
  614. // Set request parameters.
  615. $data['format'] = 'json';
  616. $path = '/v1/people/~/network/updates/key=' . $key . '/update-comments';
  617. $returnData = new stdClass;
  618. $returnData->code = 401;
  619. $returnData->body = $this->errorString;
  620. $path = $this->oauth->toUrl($path, $data);
  621. $this->client->expects($this->once())
  622. ->method('get')
  623. ->with($path)
  624. ->will($this->returnValue($returnData));
  625. $this->object->getComments($key);
  626. }
  627. /**
  628. * Tests the postComment method
  629. *
  630. * @return void
  631. *
  632. * @since 1.0
  633. */
  634. public function testPostComment()
  635. {
  636. $key = 'APPM-187317358-5635333363205165056-196773';
  637. $comment = 'Comment text';
  638. $path = '/v1/people/~/network/updates/key=' . $key . '/update-comments';
  639. // Build the xml.
  640. $xml = '<update-comment>
  641. <comment>' . $comment . '</comment>
  642. </update-comment>';
  643. $header['Content-Type'] = 'text/xml';
  644. $returnData = new stdClass;
  645. $returnData->code = 201;
  646. $returnData->body = $this->sampleString;
  647. $this->client->expects($this->once())
  648. ->method('post', $xml, $header)
  649. ->with($path)
  650. ->will($this->returnValue($returnData));
  651. $this->assertThat(
  652. $this->object->postComment($key, $comment),
  653. $this->equalTo($returnData)
  654. );
  655. }
  656. /**
  657. * Tests the postComment method - failure
  658. *
  659. * @return void
  660. *
  661. * @expectedException DomainException
  662. * @since 1.0
  663. */
  664. public function testPostCommentFailure()
  665. {
  666. $key = 'APPM-187317358-5635333363205165056-196773';
  667. $comment = 'Comment text';
  668. $path = '/v1/people/~/network/updates/key=' . $key . '/update-comments';
  669. // Build the xml.
  670. $xml = '<update-comment>
  671. <comment>' . $comment . '</comment>
  672. </update-comment>';
  673. $header['Content-Type'] = 'text/xml';
  674. $returnData = new stdClass;
  675. $returnData->code = 401;
  676. $returnData->body = $this->errorString;
  677. $this->client->expects($this->once())
  678. ->method('post', $xml, $header)
  679. ->with($path)
  680. ->will($this->returnValue($returnData));
  681. $this->object->postComment($key, $comment);
  682. }
  683. /**
  684. * Tests the geLikes method
  685. *
  686. * @return void
  687. *
  688. * @since 1.0
  689. */
  690. public function testGetLikes()
  691. {
  692. $key = 'APPM-187317358-5635333363205165056-196773';
  693. // Set request parameters.
  694. $data['format'] = 'json';
  695. $path = '/v1/people/~/network/updates/key=' . $key . '/likes';
  696. $returnData = new stdClass;
  697. $returnData->code = 200;
  698. $returnData->body = $this->sampleString;
  699. $path = $this->oauth->toUrl($path, $data);
  700. $this->client->expects($this->once())
  701. ->method('get')
  702. ->with($path)
  703. ->will($this->returnValue($returnData));
  704. $this->assertThat(
  705. $this->object->getLikes($key),
  706. $this->equalTo(json_decode($this->sampleString))
  707. );
  708. }
  709. /**
  710. * Tests the geLikes method - failure
  711. *
  712. * @return void
  713. *
  714. * @expectedException DomainException
  715. * @since 1.0
  716. */
  717. public function testGetLikesFailure()
  718. {
  719. $key = 'APPM-187317358-5635333363205165056-196773';
  720. // Set request parameters.
  721. $data['format'] = 'json';
  722. $path = '/v1/people/~/network/updates/key=' . $key . '/likes';
  723. $returnData = new stdClass;
  724. $returnData->code = 401;
  725. $returnData->body = $this->errorString;
  726. $path = $this->oauth->toUrl($path, $data);
  727. $this->client->expects($this->once())
  728. ->method('get')
  729. ->with($path)
  730. ->will($this->returnValue($returnData));
  731. $this->object->getLikes($key);
  732. }
  733. /**
  734. * Tests the _likeUnlike method
  735. *
  736. * @return void
  737. *
  738. * @since 1.0
  739. */
  740. public function test_likeUnlike()
  741. {
  742. // Method tested via requesting classes
  743. $this->markTestSkipped('This method is tested via requesting classes.');
  744. }
  745. /**
  746. * Tests the like method
  747. *
  748. * @return void
  749. *
  750. * @since 1.0
  751. */
  752. public function testLike()
  753. {
  754. $key = 'APPM-187317358-5635333363205165056-196773';
  755. $path = '/v1/people/~/network/updates/key=' . $key . '/is-liked';
  756. $xml = '<is-liked>true</is-liked>';
  757. $header['Content-Type'] = 'text/xml';
  758. $returnData = new stdClass;
  759. $returnData->code = 204;
  760. $returnData->body = $this->sampleString;
  761. $this->client->expects($this->once())
  762. ->method('put', $xml, $header)
  763. ->with($path)
  764. ->will($this->returnValue($returnData));
  765. $this->assertThat(
  766. $this->object->like($key),
  767. $this->equalTo($returnData)
  768. );
  769. }
  770. /**
  771. * Tests the like method - failure
  772. *
  773. * @return void
  774. *
  775. * @expectedException DomainException
  776. * @since 1.0
  777. */
  778. public function testLikeFailure()
  779. {
  780. $key = 'APPM-187317358-5635333363205165056-196773';
  781. $path = '/v1/people/~/network/updates/key=' . $key . '/is-liked';
  782. $xml = '<is-liked>true</is-liked>';
  783. $header['Content-Type'] = 'text/xml';
  784. $returnData = new stdClass;
  785. $returnData->code = 401;
  786. $returnData->body = $this->errorString;
  787. $this->client->expects($this->once())
  788. ->method('put', $xml, $header)
  789. ->with($path)
  790. ->will($this->returnValue($returnData));
  791. $this->object->like($key);
  792. }
  793. /**
  794. * Tests the unlike method
  795. *
  796. * @return void
  797. *
  798. * @since 1.0
  799. */
  800. public function testUnlike()
  801. {
  802. $key = 'APPM-187317358-5635333363205165056-196773';
  803. $path = '/v1/people/~/network/updates/key=' . $key . '/is-liked';
  804. $xml = '<is-liked>false</is-liked>';
  805. $header['Content-Type'] = 'text/xml';
  806. $returnData = new stdClass;
  807. $returnData->code = 204;
  808. $returnData->body = $this->sampleString;
  809. $this->client->expects($this->once())
  810. ->method('put', $xml, $header)
  811. ->with($path)
  812. ->will($this->returnValue($returnData));
  813. $this->assertThat(
  814. $this->object->unlike($key),
  815. $this->equalTo($returnData)
  816. );
  817. }
  818. }