You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

586 lines
26 KiB

8 years ago
  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. class ParseTest extends PHPUnit_Framework_TestCase {
  5. private $http;
  6. public function setUp() {
  7. $this->client = new Parse();
  8. $this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
  9. $this->client->mc = null;
  10. }
  11. private function parse($params) {
  12. $request = new Request($params);
  13. $response = new Response();
  14. return $this->client->parse($request, $response);
  15. }
  16. public function testMissingURL() {
  17. $response = $this->parse([]);
  18. $body = $response->getContent();
  19. $this->assertEquals(400, $response->getStatusCode());
  20. $data = json_decode($body);
  21. $this->assertObjectHasAttribute('error', $data);
  22. $this->assertEquals('missing_url', $data->error);
  23. }
  24. public function testInvalidURL() {
  25. $url = 'ftp://example.com/foo';
  26. $response = $this->parse(['url' => $url]);
  27. $body = $response->getContent();
  28. $this->assertEquals(400, $response->getStatusCode());
  29. $data = json_decode($body);
  30. $this->assertObjectHasAttribute('error', $data);
  31. $this->assertEquals('invalid_url', $data->error);
  32. }
  33. public function testTargetNotFound() {
  34. $url = 'http://source.example.com/basictest';
  35. $response = $this->parse(['url' => $url, 'target' => 'http://example.net']);
  36. $body = $response->getContent();
  37. $this->assertEquals(200, $response->getStatusCode());
  38. $data = json_decode($body);
  39. $this->assertObjectHasAttribute('error', $data);
  40. $this->assertEquals('no_link_found', $data->error);
  41. $this->assertEquals('200', $data->code);
  42. $this->assertEquals($url, $data->url);
  43. }
  44. public function testTargetFound() {
  45. $url = 'http://source.example.com/basictest';
  46. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com']);
  47. $body = $response->getContent();
  48. $this->assertEquals(200, $response->getStatusCode());
  49. $data = json_decode($body);
  50. $this->assertObjectNotHasAttribute('error', $data);
  51. }
  52. public function testHTMLContent() {
  53. $url = 'http://source.example.com/html-content';
  54. $response = $this->parse(['url' => $url]);
  55. $body = $response->getContent();
  56. $this->assertEquals(200, $response->getStatusCode());
  57. $data = json_decode($body);
  58. $this->assertObjectNotHasAttribute('name', $data->data);
  59. $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
  60. $this->assertEquals('This page has a link to <a href="http://target.example.com">target.example.com</a> and some <b>formatted text</b>.', $data->data->content->html);
  61. }
  62. public function testFindTargetLinkIsImage() {
  63. $url = 'http://source.example.com/link-is-img';
  64. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/photo.jpg']);
  65. $body = $response->getContent();
  66. $this->assertEquals(200, $response->getStatusCode());
  67. $data = json_decode($body);
  68. $this->assertObjectNotHasAttribute('name', $data->data);
  69. $this->assertEquals('This page has an img tag with the target URL.', $data->data->content->text);
  70. }
  71. public function testFindTargetLinkIsVideo() {
  72. $url = 'http://source.example.com/link-is-video';
  73. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/movie.mp4']);
  74. $body = $response->getContent();
  75. $this->assertEquals(200, $response->getStatusCode());
  76. $data = json_decode($body);
  77. $this->assertObjectNotHasAttribute('name', $data->data);
  78. $this->assertEquals('This page has a video tag with the target URL.', $data->data->content->text);
  79. }
  80. public function testFindTargetLinkIsAudio() {
  81. $url = 'http://source.example.com/link-is-audio';
  82. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/media.mp3']);
  83. $body = $response->getContent();
  84. $this->assertEquals(200, $response->getStatusCode());
  85. $data = json_decode($body);
  86. $this->assertObjectNotHasAttribute('name', $data->data);
  87. $this->assertEquals('This page has an audio tag with the target URL.', $data->data->content->text);
  88. }
  89. public function testTextContent() {
  90. $url = 'http://source.example.com/text-content';
  91. $response = $this->parse(['url' => $url]);
  92. $body = $response->getContent();
  93. $this->assertEquals(200, $response->getStatusCode());
  94. $data = json_decode($body);
  95. $this->assertObjectNotHasAttribute('name', $data->data);
  96. $this->assertEquals('This page has a link to target.example.com and some formatted text but is in a p-content element so is plaintext.', $data->data->content->text);
  97. }
  98. public function testContentWithPrefixedName() {
  99. $url = 'http://source.example.com/content-with-prefixed-name';
  100. $response = $this->parse(['url' => $url]);
  101. $body = $response->getContent();
  102. $this->assertEquals(200, $response->getStatusCode());
  103. $data = json_decode($body);
  104. $this->assertObjectNotHasAttribute('name', $data->data);
  105. $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
  106. $this->assertEquals('This page has a link to <a href="http://target.example.com">target.example.com</a> and some <b>formatted text</b>.', $data->data->content->html);
  107. }
  108. public function testContentWithDistinctName() {
  109. $url = 'http://source.example.com/content-with-distinct-name';
  110. $response = $this->parse(['url' => $url]);
  111. $body = $response->getContent();
  112. $this->assertEquals(200, $response->getStatusCode());
  113. $data = json_decode($body);
  114. $this->assertEquals('Hello World', $data->data->name);
  115. $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
  116. $this->assertEquals('This page has a link to <a href="http://target.example.com">target.example.com</a> and some <b>formatted text</b>.', $data->data->content->html);
  117. }
  118. public function testNameWithNoContent() {
  119. $url = 'http://source.example.com/name-no-content';
  120. $response = $this->parse(['url' => $url]);
  121. $body = $response->getContent();
  122. $this->assertEquals(200, $response->getStatusCode());
  123. $data = json_decode($body);
  124. $this->assertEquals('Hello World', $data->data->name);
  125. $this->assertObjectNotHasAttribute('content', $data->data);
  126. }
  127. public function testEntryWithDuplicateCategories() {
  128. $url = 'http://source.example.com/h-entry-duplicate-categories';
  129. $response = $this->parse(['url' => $url]);
  130. $body = $response->getContent();
  131. $this->assertEquals(200, $response->getStatusCode());
  132. $data = json_decode($body);
  133. $this->assertEquals(['indieweb'], $data->data->category);
  134. }
  135. public function testEntryStripHashtagWithDuplicateCategories() {
  136. $url = 'http://source.example.com/h-entry-strip-hashtag-from-categories';
  137. $response = $this->parse(['url' => $url]);
  138. $body = $response->getContent();
  139. $this->assertEquals(200, $response->getStatusCode());
  140. $data = json_decode($body);
  141. $this->assertContains('indieweb', $data->data->category);
  142. $this->assertContains('xray', $data->data->category);
  143. $this->assertEquals(2, count($data->data->category));
  144. }
  145. public function testNoHEntryMarkup() {
  146. $url = 'http://source.example.com/no-h-entry';
  147. $response = $this->parse(['url' => $url]);
  148. $body = $response->getContent();
  149. $this->assertEquals(200, $response->getStatusCode());
  150. $data = json_decode($body);
  151. $this->assertEquals('unknown', $data->data->type);
  152. }
  153. public function testReplyIsURL() {
  154. $url = 'http://source.example.com/reply-is-url';
  155. $response = $this->parse(['url' => $url]);
  156. $body = $response->getContent();
  157. $this->assertEquals(200, $response->getStatusCode());
  158. $data = json_decode($body, true);
  159. $this->assertEquals('entry', $data['data']['type']);
  160. $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
  161. }
  162. public function testReplyIsHCite() {
  163. $url = 'http://source.example.com/reply-is-h-cite';
  164. $response = $this->parse(['url' => $url]);
  165. $body = $response->getContent();
  166. $this->assertEquals(200, $response->getStatusCode());
  167. $data = json_decode($body, true);
  168. $this->assertEquals('entry', $data['data']['type']);
  169. $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
  170. $this->assertArrayHasKey('http://example.com/100', $data['data']['refs']);
  171. $this->assertEquals('Example Post', $data['data']['refs']['http://example.com/100']['name']);
  172. $this->assertEquals('http://example.com/100', $data['data']['refs']['http://example.com/100']['url']);
  173. }
  174. public function testPersonTagIsURL() {
  175. $url = 'http://source.example.com/person-tag-is-url';
  176. $response = $this->parse(['url' => $url]);
  177. $body = $response->getContent();
  178. $this->assertEquals(200, $response->getStatusCode());
  179. $data = json_decode($body, true);
  180. $this->assertEquals('entry', $data['data']['type']);
  181. $this->assertEquals('http://alice.example.com/', $data['data']['category'][0]);
  182. }
  183. public function testPersonTagIsHCard() {
  184. $url = 'http://source.example.com/person-tag-is-h-card';
  185. $response = $this->parse(['url' => $url]);
  186. $body = $response->getContent();
  187. $this->assertEquals(200, $response->getStatusCode());
  188. $data = json_decode($body, true);
  189. $this->assertEquals('entry', $data['data']['type']);
  190. $this->assertEquals('http://alice.example.com/', $data['data']['category'][0]);
  191. $this->assertArrayHasKey('http://alice.example.com/', $data['data']['refs']);
  192. $this->assertEquals('card', $data['data']['refs']['http://alice.example.com/']['type']);
  193. $this->assertEquals('http://alice.example.com/', $data['data']['refs']['http://alice.example.com/']['url']);
  194. $this->assertEquals('Alice', $data['data']['refs']['http://alice.example.com/']['name']);
  195. }
  196. public function testSyndicationIsURL() {
  197. $url = 'http://source.example.com/has-syndication';
  198. $response = $this->parse(['url' => $url]);
  199. $body = $response->getContent();
  200. $this->assertEquals(200, $response->getStatusCode());
  201. $data = json_decode($body, true);
  202. $this->assertEquals('entry', $data['data']['type']);
  203. $this->assertEquals('http://syndicated.example/', $data['data']['syndication'][0]);
  204. }
  205. public function testHEntryNoContent() {
  206. $url = 'http://source.example.com/h-entry-no-content';
  207. $response = $this->parse(['url' => $url]);
  208. $body = $response->getContent();
  209. $this->assertEquals(200, $response->getStatusCode());
  210. $data = json_decode($body);
  211. $this->assertObjectNotHasAttribute('content', $data->data);
  212. $this->assertEquals('This is a Post', $data->data->name);
  213. }
  214. public function testHEntryIsNotFirstObject() {
  215. $url = 'http://source.example.com/h-entry-is-not-first';
  216. $response = $this->parse(['url' => $url]);
  217. $body = $response->getContent();
  218. $this->assertEquals(200, $response->getStatusCode());
  219. $data = json_decode($body, true);
  220. $this->assertEquals('entry', $data['data']['type']);
  221. $this->assertEquals('Hello World', $data['data']['content']['text']);
  222. }
  223. public function testHEntryRSVP() {
  224. $url = 'http://source.example.com/h-entry-rsvp';
  225. $response = $this->parse(['url' => $url]);
  226. $body = $response->getContent();
  227. $this->assertEquals(200, $response->getStatusCode());
  228. $data = json_decode($body, true);
  229. $this->assertEquals('entry', $data['data']['type']);
  230. $this->assertEquals('I\'ll be there!', $data['data']['name']);
  231. $this->assertEquals('yes', $data['data']['rsvp']);
  232. }
  233. public function testMultipleHEntryOnPermalink() {
  234. $url = 'http://source.example.com/multiple-h-entry-on-permalink';
  235. $response = $this->parse(['url' => $url]);
  236. $body = $response->getContent();
  237. $this->assertEquals(200, $response->getStatusCode());
  238. $data = json_decode($body, true);
  239. $this->assertEquals('entry', $data['data']['type']);
  240. $this->assertEquals('Primary Post', $data['data']['name']);
  241. }
  242. public function testHEntryWithHCardSibling() {
  243. $url = 'http://source.example.com/h-entry-with-h-card-sibling';
  244. $response = $this->parse(['url' => $url]);
  245. $body = $response->getContent();
  246. $this->assertEquals(200, $response->getStatusCode());
  247. $data = json_decode($body, true);
  248. $this->assertEquals('entry', $data['data']['type']);
  249. $this->assertEquals('Hello World', $data['data']['content']['text']);
  250. }
  251. public function testHEntryRedirectWithHCardSibling() {
  252. $url = 'http://source.example.com/h-entry-redirect-with-h-card-sibling';
  253. $response = $this->parse(['url' => $url]);
  254. $body = $response->getContent();
  255. $this->assertEquals(200, $response->getStatusCode());
  256. $data = json_decode($body, true);
  257. $this->assertEquals('entry', $data['data']['type']);
  258. $this->assertEquals('Hello World', $data['data']['content']['text']);
  259. }
  260. public function testSingleHEntryHasNoPermalink() {
  261. $url = 'http://source.example.com/single-h-entry-has-no-permalink';
  262. $response = $this->parse(['url' => $url]);
  263. $body = $response->getContent();
  264. $this->assertEquals(200, $response->getStatusCode());
  265. $data = json_decode($body, true);
  266. $this->assertEquals('entry', $data['data']['type']);
  267. $this->assertEquals('Hello World', $data['data']['content']['text']);
  268. }
  269. public function testBridgyExampleWithNoMatchingURL() {
  270. $url = 'http://source.example.com/bridgy-example';
  271. $response = $this->parse(['url' => $url]);
  272. $body = $response->getContent();
  273. $this->assertEquals(200, $response->getStatusCode());
  274. $data = json_decode($body, true);
  275. $this->assertEquals('entry', $data['data']['type']);
  276. }
  277. public function testEventWithHTMLDescription() {
  278. $url = 'http://source.example.com/h-event';
  279. $response = $this->parse(['url' => $url]);
  280. $body = $response->getContent();
  281. $this->assertEquals(200, $response->getStatusCode());
  282. $data = json_decode($body, true);
  283. $this->assertEquals('event', $data['data']['type']);
  284. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  285. $this->assertEquals($url, $data['data']['url']);
  286. $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
  287. $this->assertEquals('2016-03-09T19:30', $data['data']['end']);
  288. $this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['description']['text']);
  289. $this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['description']['text']);
  290. $this->assertStringStartsWith("<p>Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...</p>", $data['data']['description']['html']);
  291. $this->assertStringEndsWith('<p>See the <a href="http://tantek.com/2013/332/b1/homebrew-website-club-newsletter">Homebrew Website Club Newsletter Volume 1 Issue 1</a> for a description of the first meeting.</p>', $data['data']['description']['html']);
  292. }
  293. public function testEventWithTextDescription() {
  294. $url = 'http://source.example.com/h-event-text-description';
  295. $response = $this->parse(['url' => $url]);
  296. $body = $response->getContent();
  297. $this->assertEquals(200, $response->getStatusCode());
  298. $data = json_decode($body, true);
  299. $this->assertEquals('event', $data['data']['type']);
  300. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  301. $this->assertEquals($url, $data['data']['url']);
  302. $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
  303. $this->assertEquals('2016-03-09T19:30', $data['data']['end']);
  304. $this->assertStringStartsWith("Are you building your own website? Indie reader? Personal publishing web app? Or some other digital magic-cloud proxy? If so, come on by and join a gathering of people with likeminded interests. Bring your friends that want to start a personal web site. Exchange information, swap ideas, talk shop, help work on a project...", $data['data']['description']['text']);
  305. $this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['description']['text']);
  306. $this->assertArrayNotHasKey('html', $data['data']['description']);
  307. }
  308. public function testEventWithHCardLocation() {
  309. $url = 'http://source.example.com/h-event-with-h-card-location';
  310. $response = $this->parse(['url' => $url]);
  311. $body = $response->getContent();
  312. $this->assertEquals(200, $response->getStatusCode());
  313. $data = json_decode($body, true);
  314. $this->assertEquals('event', $data['data']['type']);
  315. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  316. $this->assertEquals($url, $data['data']['url']);
  317. $this->assertEquals('2016-02-09T18:30', $data['data']['start']);
  318. $this->assertEquals('2016-02-09T19:30', $data['data']['end']);
  319. $this->assertArrayHasKey('http://source.example.com/venue', $data['data']['refs']);
  320. $this->assertEquals('card', $data['data']['refs']['http://source.example.com/venue']['type']);
  321. $this->assertEquals('http://source.example.com/venue', $data['data']['refs']['http://source.example.com/venue']['url']);
  322. $this->assertEquals('Venue', $data['data']['refs']['http://source.example.com/venue']['name']);
  323. }
  324. public function testMf2ReviewOfProduct() {
  325. $url = 'http://source.example.com/h-review-of-product';
  326. $response = $this->parse(['url' => $url]);
  327. $body = $response->getContent();
  328. $this->assertEquals(200, $response->getStatusCode());
  329. $data = json_decode($body, true);
  330. $this->assertEquals('review', $data['data']['type']);
  331. $this->assertEquals('Review', $data['data']['name']);
  332. $this->assertEquals('Not great', $data['data']['summary']);
  333. $this->assertEquals('3', $data['data']['rating']);
  334. $this->assertEquals('5', $data['data']['best']);
  335. $this->assertEquals('This is the full text of the review', $data['data']['content']['text']);
  336. $this->assertContains('red', $data['data']['category']);
  337. $this->assertContains('blue', $data['data']['category']);
  338. $this->assertContains('http://product.example.com/', $data['data']['item']);
  339. $this->assertArrayHasKey('http://product.example.com/', $data['data']['refs']);
  340. $this->assertEquals('product', $data['data']['refs']['http://product.example.com/']['type']);
  341. $this->assertEquals('The Reviewed Product', $data['data']['refs']['http://product.example.com/']['name']);
  342. $this->assertEquals('http://product.example.com/', $data['data']['refs']['http://product.example.com/']['url']);
  343. }
  344. public function testMf2ReviewOfHCard() {
  345. $url = 'http://source.example.com/h-review-of-h-card';
  346. $response = $this->parse(['url' => $url]);
  347. $body = $response->getContent();
  348. $this->assertEquals(200, $response->getStatusCode());
  349. $data = json_decode($body, true);
  350. $this->assertEquals('review', $data['data']['type']);
  351. $this->assertEquals('Review', $data['data']['name']);
  352. $this->assertEquals('Not great', $data['data']['summary']);
  353. $this->assertEquals('3', $data['data']['rating']);
  354. $this->assertEquals('5', $data['data']['best']);
  355. $this->assertEquals('This is the full text of the review', $data['data']['content']['text']);
  356. $this->assertContains('http://business.example.com/', $data['data']['item']);
  357. $this->assertArrayHasKey('http://business.example.com/', $data['data']['refs']);
  358. $this->assertEquals('card', $data['data']['refs']['http://business.example.com/']['type']);
  359. $this->assertEquals('The Reviewed Business', $data['data']['refs']['http://business.example.com/']['name']);
  360. $this->assertEquals('http://business.example.com/', $data['data']['refs']['http://business.example.com/']['url']);
  361. }
  362. public function testMf1Review() {
  363. $url = 'http://source.example.com/hReview';
  364. $response = $this->parse(['url' => $url]);
  365. $body = $response->getContent();
  366. $this->assertEquals(200, $response->getStatusCode());
  367. $data = json_decode($body, true);
  368. $this->assertEquals('review', $data['data']['type']);
  369. $this->assertEquals('Not great', $data['data']['summary']);
  370. $this->assertEquals('3', $data['data']['rating']);
  371. $this->assertEquals('5', $data['data']['best']);
  372. $this->assertEquals('This is the full text of the review', $data['data']['content']['text']);
  373. $this->assertContains('http://product.example.com/', $data['data']['item']);
  374. $this->assertArrayHasKey('http://product.example.com/', $data['data']['refs']);
  375. $this->assertEquals('item', $data['data']['refs']['http://product.example.com/']['type']);
  376. $this->assertEquals('The Reviewed Product', $data['data']['refs']['http://product.example.com/']['name']);
  377. $this->assertEquals('http://product.example.com/', $data['data']['refs']['http://product.example.com/']['url']);
  378. }
  379. public function testMf2Recipe() {
  380. $url = 'http://source.example.com/h-recipe';
  381. $response = $this->parse(['url' => $url]);
  382. $body = $response->getContent();
  383. $this->assertEquals(200, $response->getStatusCode());
  384. $data = json_decode($body, true);
  385. $this->assertEquals('recipe', $data['data']['type']);
  386. $this->assertEquals('Cookie Recipe', $data['data']['name']);
  387. $this->assertEquals('12 Cookies', $data['data']['yield']);
  388. $this->assertEquals('PT30M', $data['data']['duration']);
  389. $this->assertEquals('The best chocolate chip cookie recipe', $data['data']['summary']);
  390. $this->assertContains('3 cups flour', $data['data']['ingredient']);
  391. $this->assertContains('chocolate chips', $data['data']['ingredient']);
  392. }
  393. public function testEntryIsAnInvitee() {
  394. $url = 'http://source.example.com/bridgy-invitee';
  395. $response = $this->parse(['url' => $url]);
  396. $body = $response->getContent();
  397. $this->assertEquals(200, $response->getStatusCode());
  398. $data = json_decode($body, true);
  399. $this->assertEquals('entry', $data['data']['type']);
  400. $this->assertEquals('https://www.facebook.com/555707837940351#tantek', $data['data']['url']);
  401. $this->assertContains('https://www.facebook.com/tantek.celik', $data['data']['invitee']);
  402. $this->assertArrayHasKey('https://www.facebook.com/tantek.celik', $data['data']['refs']);
  403. $this->assertEquals('Tantek Çelik', $data['data']['refs']['https://www.facebook.com/tantek.celik']['name']);
  404. }
  405. public function testEntryAtFragmentID() {
  406. $url = 'http://source.example.com/fragment-id#comment-1000';
  407. $response = $this->parse(['url' => $url]);
  408. $body = $response->getContent();
  409. $this->assertEquals(200, $response->getStatusCode());
  410. $data = json_decode($body, true);
  411. $this->assertEquals('entry', $data['data']['type']);
  412. $this->assertEquals('Comment text', $data['data']['content']['text']);
  413. $this->assertEquals('http://source.example.com/fragment-id#comment-1000', $data['data']['url']);
  414. $this->assertTrue($data['info']['found_fragment']);
  415. }
  416. public function testEntryAtNonExistentFragmentID() {
  417. $url = 'http://source.example.com/fragment-id#comment-404';
  418. $response = $this->parse(['url' => $url]);
  419. $body = $response->getContent();
  420. $this->assertEquals(200, $response->getStatusCode());
  421. $data = json_decode($body, true);
  422. $this->assertEquals('entry', $data['data']['type']);
  423. $this->assertEquals('http://source.example.com/fragment-id', $data['data']['url']);
  424. $this->assertFalse($data['info']['found_fragment']);
  425. }
  426. public function testCheckin() {
  427. $url = 'http://source.example.com/checkin';
  428. $response = $this->parse(['url' => $url]);
  429. $body = $response->getContent();
  430. $this->assertEquals(200, $response->getStatusCode());
  431. $data = json_decode($body, true);
  432. $this->assertEquals('entry', $data['data']['type']);
  433. $venue = $data['data']['checkin'];
  434. $this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']);
  435. $this->assertEquals('DreamHost', $venue['name']);
  436. $this->assertEquals('45.518716', $venue['latitude']);
  437. $this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']);
  438. $this->assertEquals('https://aaronparecki.com/2017/06/07/12/photo.jpg', $data['data']['photo'][0]);
  439. $this->assertEquals('2017-06-07T17:14:40-07:00', $data['data']['published']);
  440. $this->assertArrayNotHasKey('name', $data['data']);
  441. }
  442. public function testCheckinURLOnly() {
  443. $url = 'http://source.example.com/checkin-url';
  444. $response = $this->parse(['url' => $url]);
  445. $body = $response->getContent();
  446. $this->assertEquals(200, $response->getStatusCode());
  447. $data = json_decode($body, true);
  448. $this->assertEquals('entry', $data['data']['type']);
  449. $venue = $data['data']['checkin'];
  450. $this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']);
  451. $this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']);
  452. $this->assertEquals('https://aaronparecki.com/2017/06/07/12/photo.jpg', $data['data']['photo'][0]);
  453. $this->assertEquals('2017-06-07T17:14:40-07:00', $data['data']['published']);
  454. $this->assertArrayNotHasKey('name', $data['data']);
  455. }
  456. public function testXKCD() {
  457. $url = 'http://xkcd.com/1810/';
  458. $response = $this->parse(['url' => $url]);
  459. $body = $response->getContent();
  460. $this->assertEquals(200, $response->getStatusCode());
  461. $data = json_decode($body, true);
  462. $this->assertEquals('entry', $data['data']['type']);
  463. $this->assertEquals('http://xkcd.com/1810/', $data['data']['url']);
  464. $this->assertEquals('Chat Systems', $data['data']['name']);
  465. $this->assertContains('http://imgs.xkcd.com/comics/chat_systems_2x.png', $data['data']['photo']);
  466. }
  467. public function testEntryHasMultipleURLs() {
  468. $url = 'http://source.example.com/multiple-urls';
  469. $response = $this->parse(['url' => $url]);
  470. $body = $response->getContent();
  471. $this->assertEquals(200, $response->getStatusCode());
  472. $data = json_decode($body, true);
  473. // Should prioritize the URL on the same domain
  474. $this->assertEquals($url, $data['data']['url']);
  475. }
  476. public function testEntryHasMultipleURLsOffDomain() {
  477. $url = 'http://source.example.com/multiple-urls-off-domain';
  478. $response = $this->parse(['url' => $url]);
  479. $body = $response->getContent();
  480. $this->assertEquals(200, $response->getStatusCode());
  481. $data = json_decode($body, true);
  482. // Neither URL is on the same domain, so should use the first
  483. $this->assertEquals('http://one.example.com/test', $data['data']['url']);
  484. }
  485. }