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.

1102 lines
48 KiB

5 years ago
5 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 testTargetNotFoundInXML() {
  53. $url = 'http://feed.example.com/atom';
  54. $response = $this->parse(['url' => $url, 'target' => 'http://example.net']);
  55. $body = $response->getContent();
  56. $this->assertEquals(200, $response->getStatusCode());
  57. $data = json_decode($body);
  58. $this->assertObjectHasAttribute('error', $data);
  59. $this->assertEquals('no_link_found', $data->error);
  60. $this->assertEquals('200', $data->code);
  61. $this->assertEquals($url, $data->url);
  62. }
  63. public function testHTMLContent() {
  64. $url = 'http://source.example.com/html-content';
  65. $response = $this->parse(['url' => $url]);
  66. $body = $response->getContent();
  67. $this->assertEquals(200, $response->getStatusCode());
  68. $data = json_decode($body);
  69. $this->assertObjectNotHasAttribute('name', $data->data);
  70. $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
  71. $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);
  72. }
  73. public function testContentFromJSONOnlyPlaintext() {
  74. $mf2JSON = json_encode([
  75. 'items' => [[
  76. 'type' => ['h-entry'],
  77. 'properties' => [
  78. 'content' => [
  79. 'plaintext'
  80. ]
  81. ]
  82. ]]
  83. ]);
  84. $xray = new \p3k\XRay();
  85. $parsed = $xray->process(false, $mf2JSON);
  86. $this->assertEquals('mf2+json', $parsed['source-format']);
  87. $item = $parsed['data'];
  88. $this->assertEquals('entry', $item['type']);
  89. $this->assertEquals('note', $item['post-type']);
  90. $this->assertEquals('plaintext', $item['content']['text']);
  91. $this->assertArrayNotHasKey('html', $item['content']);
  92. }
  93. public function testHTMLContentFromJSONNoPlaintext() {
  94. $mf2JSON = json_encode([
  95. 'items' => [[
  96. 'type' => ['h-entry'],
  97. 'properties' => [
  98. 'content' => [[
  99. 'html' => '<b>bold</b> <i>italic</i> text'
  100. ]]
  101. ]
  102. ]]
  103. ]);
  104. $xray = new \p3k\XRay();
  105. $parsed = $xray->process(false, $mf2JSON);
  106. $this->assertEquals('mf2+json', $parsed['source-format']);
  107. $item = $parsed['data'];
  108. $this->assertEquals('entry', $item['type']);
  109. $this->assertEquals('note', $item['post-type']);
  110. $this->assertEquals('bold italic text', $item['content']['text']);
  111. $this->assertEquals('<b>bold</b> <i>italic</i> text', $item['content']['html']);
  112. }
  113. public function testHTMLContentFromJSONEmptyTags() {
  114. $mf2JSON = json_encode([
  115. 'items' => [[
  116. 'type' => ['h-entry'],
  117. 'properties' => [
  118. 'content' => [[
  119. 'html' => '<b></b><i></i>'
  120. ]]
  121. ]
  122. ]]
  123. ]);
  124. $xray = new \p3k\XRay();
  125. $parsed = $xray->process(false, $mf2JSON);
  126. $this->assertEquals('mf2+json', $parsed['source-format']);
  127. $item = $parsed['data'];
  128. $this->assertEquals('entry', $item['type']);
  129. $this->assertEquals('note', $item['post-type']);
  130. $this->assertArrayNotHasKey('content', $item);
  131. }
  132. public function testHTMLContentFromJSONContentMismatch() {
  133. $mf2JSON = json_encode([
  134. 'items' => [[
  135. 'type' => ['h-entry'],
  136. 'properties' => [
  137. 'content' => [[
  138. 'value' => 'foo',
  139. 'html' => '<b>bar</b>'
  140. ]]
  141. ]
  142. ]]
  143. ]);
  144. $xray = new \p3k\XRay();
  145. $parsed = $xray->process(false, $mf2JSON);
  146. $this->assertEquals('mf2+json', $parsed['source-format']);
  147. $item = $parsed['data'];
  148. $this->assertEquals('entry', $item['type']);
  149. $this->assertEquals('note', $item['post-type']);
  150. $this->assertEquals('bar', $item['content']['text']);
  151. $this->assertEquals('<b>bar</b>', $item['content']['html']);
  152. }
  153. public function testHTMLContentFromJSONNoHTML() {
  154. $mf2JSON = json_encode([
  155. 'items' => [[
  156. 'type' => ['h-entry'],
  157. 'properties' => [
  158. 'content' => [[
  159. 'value' => 'foo',
  160. ]]
  161. ]
  162. ]]
  163. ]);
  164. $xray = new \p3k\XRay();
  165. $parsed = $xray->process(false, $mf2JSON);
  166. $this->assertEquals('mf2+json', $parsed['source-format']);
  167. $item = $parsed['data'];
  168. $this->assertEquals('entry', $item['type']);
  169. $this->assertEquals('note', $item['post-type']);
  170. $this->assertArrayNotHasKey('content', $item);
  171. }
  172. public function testFindTargetLinkIsImage() {
  173. $url = 'http://source.example.com/link-is-img';
  174. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/photo.jpg']);
  175. $body = $response->getContent();
  176. $this->assertEquals(200, $response->getStatusCode());
  177. $data = json_decode($body);
  178. $this->assertEquals('mf2+html', $data->{'source-format'});
  179. $this->assertEquals('photo', $data->data->{'post-type'});
  180. $this->assertObjectNotHasAttribute('name', $data->data);
  181. $this->assertEquals('This page has an img tag with the target URL.', $data->data->content->text);
  182. }
  183. public function testFindTargetLinkIsVideo() {
  184. $url = 'http://source.example.com/link-is-video';
  185. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/movie.mp4']);
  186. $body = $response->getContent();
  187. $this->assertEquals(200, $response->getStatusCode());
  188. $data = json_decode($body);
  189. $this->assertEquals('mf2+html', $data->{'source-format'});
  190. $this->assertEquals('video', $data->data->{'post-type'});
  191. $this->assertObjectNotHasAttribute('name', $data->data);
  192. $this->assertEquals('This page has a video tag with the target URL.', $data->data->content->text);
  193. }
  194. public function testFindTargetLinkIsAudio() {
  195. $url = 'http://source.example.com/link-is-audio';
  196. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com/media.mp3']);
  197. $body = $response->getContent();
  198. $this->assertEquals(200, $response->getStatusCode());
  199. $data = json_decode($body);
  200. $this->assertEquals('mf2+html', $data->{'source-format'});
  201. $this->assertEquals('audio', $data->data->{'post-type'});
  202. $this->assertObjectNotHasAttribute('name', $data->data);
  203. $this->assertEquals('This page has an audio tag with the target URL.', $data->data->content->text);
  204. }
  205. public function testFindTargetLinkInFeed() {
  206. $url = 'http://feed.example.com/jsonfeed';
  207. $response = $this->parse(['url' => $url, 'target' => 'http://www.manton.org/2017/11/5993.html']);
  208. $body = $response->getContent();
  209. $this->assertEquals(200, $response->getStatusCode());
  210. $data = json_decode($body);
  211. $this->assertObjectNotHasAttribute('error', $data);
  212. }
  213. public function testFindTargetLinkInHTMLInFeed() {
  214. $url = 'http://feed.example.com/jsonfeed';
  215. $response = $this->parse(['url' => $url, 'target' => 'http://www.manton.org/2016/11/todays-social-networks-are-broken.html']);
  216. $body = $response->getContent();
  217. $this->assertEquals(200, $response->getStatusCode());
  218. $data = json_decode($body);
  219. $this->assertObjectNotHasAttribute('error', $data);
  220. }
  221. public function testNotFindTargetLinkInHTMLInFeed() {
  222. $url = 'http://feed.example.com/jsonfeed';
  223. $response = $this->parse(['url' => $url, 'target' => 'http://example.com/']);
  224. $body = $response->getContent();
  225. $this->assertEquals(200, $response->getStatusCode());
  226. $data = json_decode($body);
  227. $this->assertObjectHasAttribute('error', $data);
  228. $this->assertEquals('no_link_found', $data->error);
  229. }
  230. public function testFindRelativeTargetLink() {
  231. $url = 'http://source.example.com/multiple-urls';
  232. $response = $this->parse(['url' => $url, 'target' => 'http://source.example.com/photo.jpg']);
  233. $body = $response->getContent();
  234. $this->assertEquals(200, $response->getStatusCode());
  235. $data = json_decode($body);
  236. $this->assertObjectNotHasAttribute('error', $data);
  237. }
  238. public function testTextContent() {
  239. $url = 'http://source.example.com/text-content';
  240. $response = $this->parse(['url' => $url]);
  241. $body = $response->getContent();
  242. $this->assertEquals(200, $response->getStatusCode());
  243. $data = json_decode($body);
  244. $this->assertEquals('mf2+html', $data->{'source-format'});
  245. $this->assertObjectNotHasAttribute('name', $data->data);
  246. $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);
  247. }
  248. public function testArticleWithFeaturedImage() {
  249. $url = 'http://source.example.com/article-with-featured-image';
  250. $response = $this->parse(['url' => $url]);
  251. $body = $response->getContent();
  252. $this->assertEquals(200, $response->getStatusCode());
  253. $data = json_decode($body);
  254. $this->assertEquals('mf2+html', $data->{'source-format'});
  255. $this->assertEquals('article', $data->data->{'post-type'});
  256. $this->assertEquals('Post Title', $data->data->name);
  257. $this->assertEquals('This is a blog post.', $data->data->content->text);
  258. $this->assertEquals('http://source.example.com/featured.jpg', $data->data->featured);
  259. }
  260. public function testContentWithPrefixedName() {
  261. $url = 'http://source.example.com/content-with-prefixed-name';
  262. $response = $this->parse(['url' => $url]);
  263. $body = $response->getContent();
  264. $this->assertEquals(200, $response->getStatusCode());
  265. $data = json_decode($body);
  266. $this->assertEquals('mf2+html', $data->{'source-format'});
  267. $this->assertObjectNotHasAttribute('name', $data->data);
  268. $this->assertEquals('note', $data->data->{'post-type'});
  269. $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
  270. $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);
  271. }
  272. public function testContentWithDistinctName() {
  273. $url = 'http://source.example.com/content-with-distinct-name';
  274. $response = $this->parse(['url' => $url]);
  275. $body = $response->getContent();
  276. $this->assertEquals(200, $response->getStatusCode());
  277. $data = json_decode($body);
  278. $this->assertEquals('mf2+html', $data->{'source-format'});
  279. $this->assertEquals('Hello World', $data->data->name);
  280. $this->assertEquals('article', $data->data->{'post-type'});
  281. $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
  282. $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);
  283. }
  284. public function testNameWithNoContent() {
  285. $url = 'http://source.example.com/name-no-content';
  286. $response = $this->parse(['url' => $url]);
  287. $body = $response->getContent();
  288. $this->assertEquals(200, $response->getStatusCode());
  289. $data = json_decode($body);
  290. $this->assertEquals('mf2+html', $data->{'source-format'});
  291. $this->assertEquals('Hello World', $data->data->name);
  292. $this->assertEquals('article', $data->data->{'post-type'});
  293. $this->assertObjectNotHasAttribute('content', $data->data);
  294. }
  295. public function testEntryWithDuplicateCategories() {
  296. $url = 'http://source.example.com/h-entry-duplicate-categories';
  297. $response = $this->parse(['url' => $url]);
  298. $body = $response->getContent();
  299. $this->assertEquals(200, $response->getStatusCode());
  300. $data = json_decode($body);
  301. $this->assertEquals('mf2+html', $data->{'source-format'});
  302. $this->assertEquals(['indieweb'], $data->data->category);
  303. }
  304. public function testEntryStripHashtagWithDuplicateCategories() {
  305. $url = 'http://source.example.com/h-entry-strip-hashtag-from-categories';
  306. $response = $this->parse(['url' => $url]);
  307. $body = $response->getContent();
  308. $this->assertEquals(200, $response->getStatusCode());
  309. $data = json_decode($body);
  310. $this->assertEquals('mf2+html', $data->{'source-format'});
  311. $this->assertContains('indieweb', $data->data->category);
  312. $this->assertContains('xray', $data->data->category);
  313. $this->assertEquals(2, count($data->data->category));
  314. }
  315. public function testNoHEntryMarkup() {
  316. $url = 'http://source.example.com/no-h-entry';
  317. $response = $this->parse(['url' => $url]);
  318. $body = $response->getContent();
  319. $this->assertEquals(200, $response->getStatusCode());
  320. $data = json_decode($body);
  321. $this->assertEquals('unknown', $data->data->type);
  322. $this->assertObjectNotHasAttribute('html', $data);
  323. }
  324. public function testFindTargetInNoParsedResult() {
  325. $url = 'http://source.example.com/no-h-entry';
  326. $response = $this->parse(['url' => $url, 'target' => 'http://target.example.com']);
  327. $body = $response->getContent();
  328. $this->assertEquals(200, $response->getStatusCode());
  329. $data = json_decode($body);
  330. $this->assertObjectNotHasAttribute('error', $data);
  331. $this->assertEquals('unknown', $data->data->type);
  332. }
  333. public function testReplyIsURL() {
  334. $url = 'http://source.example.com/reply-is-url';
  335. $response = $this->parse(['url' => $url]);
  336. $body = $response->getContent();
  337. $this->assertEquals(200, $response->getStatusCode());
  338. $data = json_decode($body, true);
  339. $this->assertEquals('mf2+html', $data['source-format']);
  340. $this->assertEquals('entry', $data['data']['type']);
  341. $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
  342. }
  343. public function testReplyIsHCite() {
  344. $url = 'http://source.example.com/reply-is-h-cite';
  345. $response = $this->parse(['url' => $url]);
  346. $body = $response->getContent();
  347. $this->assertEquals(200, $response->getStatusCode());
  348. $data = json_decode($body, true);
  349. $this->assertEquals('mf2+html', $data['source-format']);
  350. $this->assertEquals('entry', $data['data']['type']);
  351. $this->assertEquals('reply', $data['data']['post-type']);
  352. $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
  353. $this->assertArrayHasKey('http://example.com/100', $data['data']['refs']);
  354. $this->assertEquals('Example Post', $data['data']['refs']['http://example.com/100']['name']);
  355. $this->assertEquals('http://example.com/100', $data['data']['refs']['http://example.com/100']['url']);
  356. }
  357. public function testPersonTagIsURL() {
  358. $url = 'http://source.example.com/person-tag-is-url';
  359. $response = $this->parse(['url' => $url]);
  360. $body = $response->getContent();
  361. $this->assertEquals(200, $response->getStatusCode());
  362. $data = json_decode($body, true);
  363. $this->assertEquals('mf2+html', $data['source-format']);
  364. $this->assertEquals('entry', $data['data']['type']);
  365. $this->assertEquals('http://alice.example.com/', $data['data']['category'][0]);
  366. }
  367. public function testPersonTagIsHCard() {
  368. $url = 'http://source.example.com/person-tag-is-h-card';
  369. $response = $this->parse(['url' => $url]);
  370. $body = $response->getContent();
  371. $this->assertEquals(200, $response->getStatusCode());
  372. $data = json_decode($body, true);
  373. $this->assertEquals('mf2+html', $data['source-format']);
  374. $this->assertEquals('entry', $data['data']['type']);
  375. $this->assertEquals('http://alice.example.com/', $data['data']['category'][0]);
  376. $this->assertArrayHasKey('http://alice.example.com/', $data['data']['refs']);
  377. $this->assertEquals('card', $data['data']['refs']['http://alice.example.com/']['type']);
  378. $this->assertEquals('http://alice.example.com/', $data['data']['refs']['http://alice.example.com/']['url']);
  379. $this->assertEquals('Alice', $data['data']['refs']['http://alice.example.com/']['name']);
  380. }
  381. public function testSyndicationIsURL() {
  382. $url = 'http://source.example.com/has-syndication';
  383. $response = $this->parse(['url' => $url]);
  384. $body = $response->getContent();
  385. $this->assertEquals(200, $response->getStatusCode());
  386. $data = json_decode($body, true);
  387. $this->assertEquals('mf2+html', $data['source-format']);
  388. $this->assertEquals('entry', $data['data']['type']);
  389. $this->assertEquals('http://syndicated.example/', $data['data']['syndication'][0]);
  390. }
  391. public function testHEntryNoContent() {
  392. $url = 'http://source.example.com/h-entry-no-content';
  393. $response = $this->parse(['url' => $url]);
  394. $body = $response->getContent();
  395. $this->assertEquals(200, $response->getStatusCode());
  396. $data = json_decode($body);
  397. $this->assertEquals('mf2+html', $data->{'source-format'});
  398. $this->assertObjectNotHasAttribute('content', $data->data);
  399. $this->assertEquals('This is a Post', $data->data->name);
  400. }
  401. public function testHEntryIsNotFirstObject() {
  402. $url = 'http://source.example.com/h-entry-is-not-first';
  403. $response = $this->parse(['url' => $url]);
  404. $body = $response->getContent();
  405. $this->assertEquals(200, $response->getStatusCode());
  406. $data = json_decode($body, true);
  407. $this->assertEquals('mf2+html', $data['source-format']);
  408. $this->assertEquals('entry', $data['data']['type']);
  409. $this->assertEquals('Hello World', $data['data']['content']['text']);
  410. }
  411. public function testHEntryRSVP() {
  412. $url = 'http://source.example.com/h-entry-rsvp';
  413. $response = $this->parse(['url' => $url]);
  414. $body = $response->getContent();
  415. $this->assertEquals(200, $response->getStatusCode());
  416. $data = json_decode($body, true);
  417. $this->assertEquals('mf2+html', $data['source-format']);
  418. $this->assertEquals('entry', $data['data']['type']);
  419. $this->assertEquals('rsvp', $data['data']['post-type']);
  420. $this->assertEquals('I\'ll be there!', $data['data']['content']['text']);
  421. $this->assertEquals('yes', $data['data']['rsvp']);
  422. }
  423. public function testMultipleHEntryOnPermalink() {
  424. $url = 'http://source.example.com/multiple-h-entry-on-permalink';
  425. $response = $this->parse(['url' => $url]);
  426. $body = $response->getContent();
  427. $this->assertEquals(200, $response->getStatusCode());
  428. $data = json_decode($body, true);
  429. $this->assertEquals('mf2+html', $data['source-format']);
  430. $this->assertEquals('entry', $data['data']['type']);
  431. $this->assertEquals('Primary Post', $data['data']['name']);
  432. }
  433. public function testHEntryWithHCardBeforeIt() {
  434. $url = 'http://source.example.com/h-entry-with-h-card-before-it';
  435. $response = $this->parse(['url' => $url]);
  436. $body = $response->getContent();
  437. $this->assertEquals(200, $response->getStatusCode());
  438. $data = json_decode($body, true);
  439. $this->assertEquals('mf2+html', $data['source-format']);
  440. $this->assertEquals('entry', $data['data']['type']);
  441. $this->assertEquals('Hello World', $data['data']['content']['text']);
  442. }
  443. public function testHEntryWithHCardSibling() {
  444. $url = 'http://source.example.com/h-entry-with-h-card-sibling';
  445. $response = $this->parse(['url' => $url]);
  446. $body = $response->getContent();
  447. $this->assertEquals(200, $response->getStatusCode());
  448. $data = json_decode($body, true);
  449. $this->assertEquals('mf2+html', $data['source-format']);
  450. $this->assertEquals('entry', $data['data']['type']);
  451. $this->assertEquals('Hello World', $data['data']['content']['text']);
  452. }
  453. public function testHEntryWithTwoHCardsBeforeIt() {
  454. $url = 'http://source.example.com/h-entry-with-two-h-cards-before-it';
  455. $response = $this->parse(['url' => $url]);
  456. $body = $response->getContent();
  457. $this->assertEquals(200, $response->getStatusCode());
  458. $data = json_decode($body, true);
  459. $this->assertEquals('mf2+html', $data['source-format']);
  460. $this->assertEquals('entry', $data['data']['type']);
  461. $this->assertEquals('Hello World', $data['data']['content']['text']);
  462. }
  463. public function testHEntryRedirectWithHCardSibling() {
  464. $url = 'http://source.example.com/h-entry-redirect-with-h-card-sibling';
  465. $response = $this->parse(['url' => $url]);
  466. $body = $response->getContent();
  467. $this->assertEquals(200, $response->getStatusCode());
  468. $data = json_decode($body, true);
  469. $this->assertEquals('mf2+html', $data['source-format']);
  470. $this->assertEquals('entry', $data['data']['type']);
  471. $this->assertEquals('Hello World', $data['data']['content']['text']);
  472. }
  473. public function testSingleHEntryHasNoPermalink() {
  474. $url = 'http://source.example.com/single-h-entry-has-no-permalink';
  475. $response = $this->parse(['url' => $url]);
  476. $body = $response->getContent();
  477. $this->assertEquals(200, $response->getStatusCode());
  478. $data = json_decode($body, true);
  479. $this->assertEquals('mf2+html', $data['source-format']);
  480. $this->assertEquals('entry', $data['data']['type']);
  481. $this->assertEquals('Hello World', $data['data']['content']['text']);
  482. }
  483. public function testBridgyExampleWithNoMatchingURL() {
  484. $url = 'http://source.example.com/bridgy-example';
  485. $response = $this->parse(['url' => $url]);
  486. $body = $response->getContent();
  487. $this->assertEquals(200, $response->getStatusCode());
  488. $data = json_decode($body, true);
  489. $this->assertEquals('mf2+html', $data['source-format']);
  490. $this->assertEquals('entry', $data['data']['type']);
  491. }
  492. public function testEventWithHTMLDescription() {
  493. $url = 'http://source.example.com/h-event';
  494. $response = $this->parse(['url' => $url]);
  495. $body = $response->getContent();
  496. $this->assertEquals(200, $response->getStatusCode());
  497. $data = json_decode($body, true);
  498. $this->assertEquals('mf2+html', $data['source-format']);
  499. $this->assertEquals('event', $data['data']['type']);
  500. $this->assertEquals('event', $data['data']['post-type']);
  501. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  502. $this->assertEquals($url, $data['data']['url']);
  503. $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
  504. $this->assertEquals('2016-03-09T19:30', $data['data']['end']);
  505. $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']['content']['text']);
  506. $this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['content']['text']);
  507. $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']['content']['html']);
  508. $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']['content']['html']);
  509. }
  510. public function testEventWithTextDescription() {
  511. $url = 'http://source.example.com/h-event-text-description';
  512. $response = $this->parse(['url' => $url]);
  513. $body = $response->getContent();
  514. $this->assertEquals(200, $response->getStatusCode());
  515. $data = json_decode($body, true);
  516. $this->assertEquals('mf2+html', $data['source-format']);
  517. $this->assertEquals('event', $data['data']['type']);
  518. $this->assertEquals('event', $data['data']['post-type']);
  519. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  520. $this->assertEquals($url, $data['data']['url']);
  521. $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
  522. $this->assertEquals('2016-03-09T19:30', $data['data']['end']);
  523. $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']['content']['text']);
  524. $this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['content']['text']);
  525. $this->assertArrayNotHasKey('html', $data['data']['content']);
  526. }
  527. public function testEventWithTextContent() {
  528. $url = 'http://source.example.com/h-event-text-content';
  529. $response = $this->parse(['url' => $url]);
  530. $body = $response->getContent();
  531. $this->assertEquals(200, $response->getStatusCode());
  532. $data = json_decode($body, true);
  533. $this->assertEquals('mf2+html', $data['source-format']);
  534. $this->assertEquals('event', $data['data']['type']);
  535. $this->assertEquals('event', $data['data']['post-type']);
  536. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  537. $this->assertEquals($url, $data['data']['url']);
  538. $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
  539. $this->assertEquals('2016-03-09T19:30', $data['data']['end']);
  540. $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']['content']['text']);
  541. $this->assertStringEndsWith("See the Homebrew Website Club Newsletter Volume 1 Issue 1 for a description of the first meeting.", $data['data']['content']['text']);
  542. $this->assertArrayNotHasKey('html', $data['data']['content']);
  543. $this->assertEquals('card', $data['data']['author']['type']);
  544. $this->assertEquals('Event Author', $data['data']['author']['name']);
  545. $this->assertEquals('http://source.example.com/', $data['data']['author']['url']);
  546. }
  547. public function testEventWithHCardLocation() {
  548. $url = 'http://source.example.com/h-event-with-h-card-location';
  549. $response = $this->parse(['url' => $url]);
  550. $body = $response->getContent();
  551. $this->assertEquals(200, $response->getStatusCode());
  552. $data = json_decode($body, true);
  553. $this->assertEquals('mf2+html', $data['source-format']);
  554. $this->assertEquals('event', $data['data']['type']);
  555. $this->assertEquals('event', $data['data']['post-type']);
  556. $this->assertEquals('Homebrew Website Club', $data['data']['name']);
  557. $this->assertEquals($url, $data['data']['url']);
  558. $this->assertEquals('2016-02-09T18:30', $data['data']['start']);
  559. $this->assertEquals('2016-02-09T19:30', $data['data']['end']);
  560. $this->assertArrayHasKey('http://source.example.com/venue', $data['data']['refs']);
  561. $this->assertEquals('card', $data['data']['refs']['http://source.example.com/venue']['type']);
  562. $this->assertEquals('http://source.example.com/venue', $data['data']['refs']['http://source.example.com/venue']['url']);
  563. $this->assertEquals('Venue', $data['data']['refs']['http://source.example.com/venue']['name']);
  564. }
  565. public function testEventWithFeaturedImage() {
  566. $url = 'http://source.example.com/h-event-featured';
  567. $response = $this->parse(['url' => $url]);
  568. $body = $response->getContent();
  569. $this->assertEquals(200, $response->getStatusCode());
  570. $data = json_decode($body, true);
  571. $this->assertEquals('mf2+html', $data['source-format']);
  572. $this->assertEquals('event', $data['data']['type']);
  573. $this->assertEquals('http://source.example.com/featured.jpg', $data['data']['featured']);
  574. }
  575. public function testMf2ReviewOfProduct() {
  576. $url = 'http://source.example.com/h-review-of-product';
  577. $response = $this->parse(['url' => $url]);
  578. $body = $response->getContent();
  579. $this->assertEquals(200, $response->getStatusCode());
  580. $data = json_decode($body, true);
  581. $this->assertEquals('mf2+html', $data['source-format']);
  582. $this->assertEquals('review', $data['data']['type']);
  583. $this->assertEquals('review', $data['data']['post-type']);
  584. $this->assertEquals('Review', $data['data']['name']);
  585. $this->assertEquals('Not great', $data['data']['summary']);
  586. $this->assertEquals('3', $data['data']['rating']);
  587. $this->assertEquals('5', $data['data']['best']);
  588. $this->assertEquals('This is the full text of the review', $data['data']['content']['text']);
  589. $this->assertContains('red', $data['data']['category']);
  590. $this->assertContains('blue', $data['data']['category']);
  591. $this->assertContains('http://product.example.com/', $data['data']['item']);
  592. $this->assertArrayHasKey('http://product.example.com/', $data['data']['refs']);
  593. $this->assertEquals('product', $data['data']['refs']['http://product.example.com/']['type']);
  594. $this->assertEquals('The Reviewed Product', $data['data']['refs']['http://product.example.com/']['name']);
  595. $this->assertEquals('http://product.example.com/', $data['data']['refs']['http://product.example.com/']['url']);
  596. }
  597. public function testMf2ReviewOfHCard() {
  598. $url = 'http://source.example.com/h-review-of-h-card';
  599. $response = $this->parse(['url' => $url]);
  600. $body = $response->getContent();
  601. $this->assertEquals(200, $response->getStatusCode());
  602. $data = json_decode($body, true);
  603. $this->assertEquals('mf2+html', $data['source-format']);
  604. $this->assertEquals('review', $data['data']['type']);
  605. $this->assertEquals('review', $data['data']['post-type']);
  606. $this->assertEquals('Review', $data['data']['name']);
  607. $this->assertEquals('Not great', $data['data']['summary']);
  608. $this->assertEquals('3', $data['data']['rating']);
  609. $this->assertEquals('5', $data['data']['best']);
  610. $this->assertEquals('This is the full text of the review', $data['data']['content']['text']);
  611. $this->assertContains('http://business.example.com/', $data['data']['item']);
  612. $this->assertArrayHasKey('http://business.example.com/', $data['data']['refs']);
  613. $this->assertEquals('card', $data['data']['refs']['http://business.example.com/']['type']);
  614. $this->assertEquals('The Reviewed Business', $data['data']['refs']['http://business.example.com/']['name']);
  615. $this->assertEquals('http://business.example.com/', $data['data']['refs']['http://business.example.com/']['url']);
  616. }
  617. public function testMf1Review() {
  618. $url = 'http://source.example.com/hReview';
  619. $response = $this->parse(['url' => $url]);
  620. $body = $response->getContent();
  621. $this->assertEquals(200, $response->getStatusCode());
  622. $data = json_decode($body, true);
  623. $this->assertEquals('mf2+html', $data['source-format']);
  624. $this->assertEquals('review', $data['data']['type']);
  625. $this->assertEquals('review', $data['data']['post-type']);
  626. $this->assertEquals('Not great', $data['data']['name']);
  627. $this->assertEquals('3', $data['data']['rating']);
  628. $this->assertEquals('5', $data['data']['best']);
  629. $this->assertEquals('This is the full text of the review', $data['data']['content']['text']);
  630. $this->assertContains('http://product.example.com/', $data['data']['item']);
  631. $this->assertArrayHasKey('http://product.example.com/', $data['data']['refs']);
  632. $this->assertEquals('item', $data['data']['refs']['http://product.example.com/']['type']);
  633. $this->assertEquals('The Reviewed Product', $data['data']['refs']['http://product.example.com/']['name']);
  634. $this->assertEquals('http://product.example.com/', $data['data']['refs']['http://product.example.com/']['url']);
  635. }
  636. public function testMf2Recipe() {
  637. $url = 'http://source.example.com/h-recipe';
  638. $response = $this->parse(['url' => $url]);
  639. $body = $response->getContent();
  640. $this->assertEquals(200, $response->getStatusCode());
  641. $data = json_decode($body, true);
  642. $this->assertEquals('mf2+html', $data['source-format']);
  643. $this->assertEquals('recipe', $data['data']['type']);
  644. $this->assertEquals('recipe', $data['data']['post-type']);
  645. $this->assertEquals('Cookie Recipe', $data['data']['name']);
  646. $this->assertEquals('12 Cookies', $data['data']['yield']);
  647. $this->assertEquals('PT30M', $data['data']['duration']);
  648. $this->assertEquals('The best chocolate chip cookie recipe', $data['data']['summary']);
  649. $this->assertContains('3 cups flour', $data['data']['ingredient']);
  650. $this->assertContains('chocolate chips', $data['data']['ingredient']);
  651. }
  652. public function testEntryIsAnInvitee() {
  653. $url = 'http://source.example.com/bridgy-invitee';
  654. $response = $this->parse(['url' => $url]);
  655. $body = $response->getContent();
  656. $this->assertEquals(200, $response->getStatusCode());
  657. $data = json_decode($body, true);
  658. $this->assertEquals('mf2+html', $data['source-format']);
  659. $this->assertEquals('entry', $data['data']['type']);
  660. $this->assertEquals('https://www.facebook.com/555707837940351#tantek', $data['data']['url']);
  661. $this->assertContains('https://www.facebook.com/tantek.celik', $data['data']['invitee']);
  662. $this->assertArrayHasKey('https://www.facebook.com/tantek.celik', $data['data']['refs']);
  663. $this->assertEquals('Tantek Çelik', $data['data']['refs']['https://www.facebook.com/tantek.celik']['name']);
  664. }
  665. public function testEntryAtFragmentID() {
  666. $url = 'http://source.example.com/fragment-id#comment-1000';
  667. $response = $this->parse(['url' => $url]);
  668. $body = $response->getContent();
  669. $this->assertEquals(200, $response->getStatusCode());
  670. $data = json_decode($body, true);
  671. $this->assertEquals('mf2+html', $data['source-format']);
  672. $this->assertEquals('entry', $data['data']['type']);
  673. $this->assertEquals('note', $data['data']['post-type']);
  674. $this->assertEquals('Comment text', $data['data']['content']['text']);
  675. $this->assertEquals('http://source.example.com/fragment-id#comment-1000', $data['data']['url']);
  676. $this->assertTrue($data['info']['found_fragment']);
  677. }
  678. public function testEntryAtNonExistentFragmentID() {
  679. $url = 'http://source.example.com/fragment-id#comment-404';
  680. $response = $this->parse(['url' => $url]);
  681. $body = $response->getContent();
  682. $this->assertEquals(200, $response->getStatusCode());
  683. $data = json_decode($body, true);
  684. $this->assertEquals('mf2+html', $data['source-format']);
  685. $this->assertEquals('entry', $data['data']['type']);
  686. $this->assertEquals('http://source.example.com/fragment-id', $data['data']['url']);
  687. $this->assertFalse($data['info']['found_fragment']);
  688. }
  689. public function testCheckin() {
  690. $url = 'http://source.example.com/checkin';
  691. $response = $this->parse(['url' => $url]);
  692. $body = $response->getContent();
  693. $this->assertEquals(200, $response->getStatusCode());
  694. $data = json_decode($body, true);
  695. $this->assertEquals('mf2+html', $data['source-format']);
  696. $this->assertEquals('entry', $data['data']['type']);
  697. $venue = $data['data']['checkin'];
  698. $this->assertEquals('checkin', $data['data']['post-type']);
  699. $this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']);
  700. $this->assertEquals('DreamHost', $venue['name']);
  701. $this->assertEquals('45.518716', $venue['latitude']);
  702. $this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']);
  703. $this->assertEquals('https://aaronparecki.com/2017/06/07/12/photo.jpg', $data['data']['photo'][0]);
  704. $this->assertEquals('2017-06-07T17:14:40-07:00', $data['data']['published']);
  705. $this->assertArrayNotHasKey('name', $data['data']);
  706. }
  707. public function testCheckinURLOnly() {
  708. $url = 'http://source.example.com/checkin-url';
  709. $response = $this->parse(['url' => $url]);
  710. $body = $response->getContent();
  711. $this->assertEquals(200, $response->getStatusCode());
  712. $data = json_decode($body, true);
  713. $this->assertEquals('mf2+html', $data['source-format']);
  714. $this->assertEquals('entry', $data['data']['type']);
  715. $this->assertEquals('checkin', $data['data']['post-type']);
  716. $venue = $data['data']['checkin'];
  717. $this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']);
  718. $this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']);
  719. $this->assertEquals('https://aaronparecki.com/2017/06/07/12/photo.jpg', $data['data']['photo'][0]);
  720. $this->assertEquals('2017-06-07T17:14:40-07:00', $data['data']['published']);
  721. $this->assertArrayNotHasKey('name', $data['data']);
  722. }
  723. public function testXKCD() {
  724. $url = 'http://xkcd.com/1810/';
  725. $response = $this->parse(['url' => $url]);
  726. $body = $response->getContent();
  727. $this->assertEquals(200, $response->getStatusCode());
  728. $data = json_decode($body, true);
  729. $this->assertEquals(200, $data['code']);
  730. $this->assertEquals('xkcd', $data['source-format']);
  731. $this->assertEquals('entry', $data['data']['type']);
  732. $this->assertEquals('photo', $data['data']['post-type']);
  733. $this->assertEquals('http://xkcd.com/1810/', $data['data']['url']);
  734. $this->assertEquals('Chat Systems', $data['data']['name']);
  735. $this->assertContains('http://imgs.xkcd.com/comics/chat_systems_2x.png', $data['data']['photo']);
  736. }
  737. public function testEntryHasMultipleURLs() {
  738. $url = 'http://source.example.com/multiple-urls';
  739. $response = $this->parse(['url' => $url]);
  740. $body = $response->getContent();
  741. $this->assertEquals(200, $response->getStatusCode());
  742. $data = json_decode($body, true);
  743. // Should prioritize the URL on the same domain
  744. $this->assertEquals($url, $data['data']['url']);
  745. }
  746. public function testEntryHasMultipleURLsOffDomain() {
  747. $url = 'http://source.example.com/multiple-urls-off-domain';
  748. $response = $this->parse(['url' => $url]);
  749. $body = $response->getContent();
  750. $this->assertEquals(200, $response->getStatusCode());
  751. $data = json_decode($body, true);
  752. // Neither URL is on the same domain, so should use the first
  753. $this->assertEquals('http://one.example.com/test', $data['data']['url']);
  754. }
  755. public function testInputIsParsedMf2() {
  756. $html = '<div class="h-entry"><p class="p-content p-name">Hello World</p><img src="/photo.jpg"></p></div>';
  757. $mf2 = Mf2\parse($html, 'http://example.com/entry');
  758. $url = 'http://example.com/entry';
  759. $response = $this->parse([
  760. 'url' => $url,
  761. 'body' => json_encode($mf2)
  762. ]);
  763. $body = $response->getContent();
  764. $this->assertEquals(200, $response->getStatusCode());
  765. $data = json_decode($body, true);
  766. $this->assertEquals('mf2+json', $data['source-format']);
  767. $this->assertEquals('Hello World', $data['data']['content']['text']);
  768. $this->assertEquals('http://example.com/photo.jpg', $data['data']['photo'][0]);
  769. }
  770. public function testInputIsParsedMf2WithHTML() {
  771. $html = '<div class="h-entry"><p class="e-content p-name"><b>Hello</b> <i>World</i></p><img src="/photo.jpg"></p></div>';
  772. $mf2 = Mf2\parse($html, 'http://example.com/entry');
  773. $url = 'http://example.com/entry';
  774. $response = $this->parse([
  775. 'url' => $url,
  776. 'body' => json_encode($mf2)
  777. ]);
  778. $body = $response->getContent();
  779. $this->assertEquals(200, $response->getStatusCode());
  780. $data = json_decode($body, true);
  781. $this->assertEquals('mf2+json', $data['source-format']);
  782. $this->assertEquals('Hello World', $data['data']['content']['text']);
  783. $this->assertEquals('<b>Hello</b> <i>World</i>', $data['data']['content']['html']);
  784. $this->assertEquals('http://example.com/photo.jpg', $data['data']['photo'][0]);
  785. }
  786. public function testHApp() {
  787. $url = 'http://source.example.com/h-app';
  788. $response = $this->parse(['url' => $url]);
  789. $body = $response->getContent();
  790. $this->assertEquals(200, $response->getStatusCode());
  791. $data = json_decode($body, true);
  792. $this->assertEquals('mf2+html', $data['source-format']);
  793. $this->assertEquals('app', $data['data']['type']);
  794. $this->assertEquals('http://source.example.com/images/quill.png', $data['data']['logo']);
  795. $this->assertEquals('Quill', $data['data']['name']);
  796. $this->assertEquals($url, $data['data']['url']);
  797. $this->assertEquals(['http://source.example.com/redirect1','http://source.example.com/redirect2'], $data['data']['redirect-uri']);
  798. $this->assertArrayNotHasKey('photo', $data['data']);
  799. }
  800. public function testHXApp() {
  801. $url = 'http://source.example.com/h-x-app';
  802. $response = $this->parse(['url' => $url]);
  803. $body = $response->getContent();
  804. $this->assertEquals(200, $response->getStatusCode());
  805. $data = json_decode($body);
  806. $this->assertEquals('mf2+html', $data->{'source-format'});
  807. $this->assertEquals('app', $data->data->type);
  808. $this->assertEquals('http://source.example.com/images/quill.png', $data->data->logo);
  809. $this->assertEquals('Quill', $data->data->name);
  810. $this->assertEquals($url, $data->data->url);
  811. $this->assertObjectNotHasAttribute('photo', $data->data);
  812. }
  813. public function testDuplicateReplyURLValues() {
  814. $url = 'http://source.example.com/duplicate-in-reply-to-urls';
  815. $response = $this->parse(['url' => $url]);
  816. $body = $response->getContent();
  817. $this->assertEquals(200, $response->getStatusCode());
  818. $data = json_decode($body, true);
  819. $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
  820. $this->assertEquals(1, count($data['data']['in-reply-to']));
  821. }
  822. public function testDuplicateLikeOfURLValues() {
  823. $url = 'http://source.example.com/duplicate-like-of-urls';
  824. $response = $this->parse(['url' => $url]);
  825. $body = $response->getContent();
  826. $this->assertEquals(200, $response->getStatusCode());
  827. $data = json_decode($body, true);
  828. $this->assertEquals('http://example.com/100', $data['data']['like-of'][0]);
  829. $this->assertEquals(1, count($data['data']['like-of']));
  830. }
  831. public function testQuotationOf() {
  832. $url = 'http://source.example.com/quotation-of';
  833. $response = $this->parse(['url' => $url]);
  834. $body = $response->getContent();
  835. $this->assertEquals(200, $response->getStatusCode());
  836. $data = json_decode($body, true);
  837. $this->assertEquals('I’m so making this into a t-shirt', $data['data']['content']['text']);
  838. $this->assertEquals('https://twitter.com/gitlost/status/1015005409726357504', $data['data']['quotation-of']);
  839. $this->assertArrayHasKey('https://twitter.com/gitlost/status/1015005409726357504', $data['data']['refs']);
  840. $q = $data['data']['refs']['https://twitter.com/gitlost/status/1015005409726357504'];
  841. $this->assertEquals("Still can't git fer shit", $q['content']['text']);
  842. $this->assertEquals('2018-07-05T22:52:02+00:00', $q['published']);
  843. }
  844. public function testHTML5Markup() {
  845. $url = 'http://source.example.com/html5-tags';
  846. $response = $this->parse(['url' => $url]);
  847. $body = $response->getContent();
  848. $this->assertEquals(200, $response->getStatusCode());
  849. $data = json_decode($body, true);
  850. $this->assertEquals('Hello World', $data['data']['name']);
  851. $this->assertEquals('The content of the blog post', $data['data']['content']['text']);
  852. }
  853. public function testRelAlternateToMf2JSON() {
  854. $url = 'http://source.example.com/rel-alternate-mf2-json';
  855. $response = $this->parse(['url' => $url]);
  856. $body = $response->getContent();
  857. $this->assertEquals(200, $response->getStatusCode());
  858. $data = json_decode($body, true);
  859. $this->assertEquals('mf2+json', $data['source-format']);
  860. $this->assertEquals('http://source.example.com/rel-alternate-mf2-json.json', $data['parsed-url']);
  861. $this->assertEquals('Pretty great to see a new self-hosted IndieAuth server! Congrats @nilshauk, and great project name! https://twitter.com/nilshauk/status/1017485223716630528', $data['data']['content']['text']);
  862. }
  863. public function testRelAlternateToNotFoundURL() {
  864. $url = 'http://source.example.com/rel-alternate-not-found';
  865. $response = $this->parse(['url' => $url]);
  866. $body = $response->getContent();
  867. $this->assertEquals(200, $response->getStatusCode());
  868. $data = json_decode($body, true);
  869. $this->assertEquals('mf2+html', $data['source-format']);
  870. $this->assertArrayNotHasKey('parsed-url', $data);
  871. $this->assertEquals('Test content with a rel alternate link to a 404 page', $data['data']['content']['text']);
  872. }
  873. public function testRelAlternatePrioritizesJSON() {
  874. $url = 'http://source.example.com/rel-alternate-priority';
  875. $response = $this->parse(['url' => $url]);
  876. $body = $response->getContent();
  877. $this->assertEquals(200, $response->getStatusCode());
  878. $data = json_decode($body, true);
  879. $this->assertEquals('mf2+json', $data['source-format']);
  880. $this->assertEquals('http://source.example.com/rel-alternate-priority.json', $data['parsed-url']);
  881. $this->assertEquals('This should be the content from XRay', $data['data']['content']['text']);
  882. }
  883. public function testRelAlternatePrioritizesMf2OverAS2() {
  884. $url = 'http://source.example.com/rel-alternate-priority-mf2-as2';
  885. $response = $this->parse(['url' => $url]);
  886. $body = $response->getContent();
  887. $this->assertEquals(200, $response->getStatusCode());
  888. $data = json_decode($body, true);
  889. $this->assertEquals('mf2+json', $data['source-format']);
  890. $this->assertEquals('http://source.example.com/rel-alternate-priority.json', $data['parsed-url']);
  891. $this->assertEquals('This should be the content from XRay', $data['data']['content']['text']);
  892. }
  893. public function testRelAlternateFallsBackOnInvalidJSON() {
  894. $url = 'http://source.example.com/rel-alternate-fallback';
  895. $response = $this->parse(['url' => $url]);
  896. $body = $response->getContent();
  897. $this->assertEquals(200, $response->getStatusCode());
  898. $data = json_decode($body, true);
  899. $this->assertEquals('mf2+html', $data['source-format']);
  900. $this->assertArrayNotHasKey('parsed-url', $data);
  901. $this->assertEquals('XRay should use this content since the JSON in the rel-alternate is invalid', $data['data']['content']['text']);
  902. }
  903. public function testMultipleContentTypeHeaders() {
  904. $url = 'http://source.example.com/multiple-content-type';
  905. $response = $this->parse(['url' => $url]);
  906. $body = $response->getContent();
  907. $this->assertEquals(200, $response->getStatusCode());
  908. $data = json_decode($body, true);
  909. $this->assertEquals('mf2+html', $data['source-format']);
  910. }
  911. public function testFollowOf() {
  912. $url = 'http://source.example.com/bridgy-follow';
  913. $response = $this->parse(['url' => $url]);
  914. $body = $response->getContent();
  915. $this->assertEquals(200, $response->getStatusCode());
  916. $data = json_decode($body, true);
  917. $this->assertEquals('https://realize.be/', $data['data']['follow-of']);
  918. $this->assertEquals('follow', $data['data']['post-type']);
  919. }
  920. public function testFollowOfHCard() {
  921. $url = 'http://source.example.com/follow-of-h-card';
  922. $response = $this->parse(['url' => $url]);
  923. $body = $response->getContent();
  924. $this->assertEquals(200, $response->getStatusCode());
  925. $data = json_decode($body, true);
  926. $this->assertEquals('https://realize.be/', $data['data']['follow-of']);
  927. $this->assertEquals('follow', $data['data']['post-type']);
  928. }
  929. }