Browse Source

adds new "source-format" property to indicate how XRay found the data

* mf2+html
* mf2+json
* feed+json
* xml
* instagram/facebook/github/xkcd
pull/78/head
Aaron Parecki 6 years ago
parent
commit
7621bca4a6
No known key found for this signature in database GPG Key ID: 276C2817346D6056
23 changed files with 201 additions and 43 deletions
  1. +12
    -3
      README.md
  2. +2
    -0
      controllers/Parse.php
  3. +2
    -0
      lib/XRay.php
  4. +2
    -1
      lib/XRay/Formats/Facebook.php
  5. +2
    -1
      lib/XRay/Formats/GitHub.php
  6. +1
    -0
      lib/XRay/Formats/HTML.php
  7. +2
    -1
      lib/XRay/Formats/Hackernews.php
  8. +6
    -3
      lib/XRay/Formats/Instagram.php
  9. +1
    -0
      lib/XRay/Formats/JSONFeed.php
  10. +1
    -1
      lib/XRay/Formats/Mf2.php
  11. +2
    -1
      lib/XRay/Formats/Mf2Feed.php
  12. +1
    -0
      lib/XRay/Formats/Twitter.php
  13. +2
    -1
      lib/XRay/Formats/XKCD.php
  14. +1
    -0
      lib/XRay/Formats/XML.php
  15. +9
    -3
      lib/XRay/Parser.php
  16. +1
    -0
      tests/AuthorTest.php
  17. +6
    -0
      tests/FacebookTest.php
  18. +42
    -24
      tests/FeedTest.php
  19. +15
    -0
      tests/GitHubTest.php
  20. +6
    -0
      tests/HackernewsTest.php
  21. +29
    -0
      tests/InstagramTest.php
  22. +47
    -4
      tests/ParseTest.php
  23. +9
    -0
      tests/TwitterTest.php

+ 12
- 3
README.md View File

@ -97,7 +97,8 @@ $parsed = Array
)
[url] => https://aaronparecki.com/
[code] => 200
[code] => 200,
[source-format] => mf2+html
)
```
@ -131,6 +132,8 @@ Array
)
[url] => http://example.com/entry
[source-format] => mf2+json
)
```
@ -363,7 +366,8 @@ Possible errors are listed below:
}
},
"url":"https://aaronparecki.com/2017/03/01/14/hwc",
"code":200
"code":200,
"source-format":"mf2+html"
}
```
@ -420,7 +424,12 @@ Other properties are returned in the response at the same level as the `data` pr
* `url` - The effective URL that the document was retrieved from. This will be the final URL after following any redirects.
* `code` - The HTTP response code returned by the URL. Typically this will be 200, but if the URL returned an alternate HTTP code that also included an h-entry (such as a 410 deleted notice with a stub h-entry), you can use this to find out that the original URL was actually deleted.
* `source-format` - Indicates the format of the source URL that was used to generate the parsed result. Possible values are:
* `mf2+html`
* `mf2+json`
* `feed+json`
* `xml`
* `instagram`/`facebook`/`github`/`xkcd`
#### Feeds

+ 2
- 0
controllers/Parse.php View File

@ -126,6 +126,8 @@ class Parse {
$data['info'] = $parsed['info'];
if($request->get('include_original') && isset($parsed['original']))
$data['original'] = $parsed['original'];
if(isset($parsed['source-format']))
$data['source-format'] = $parsed['source-format'];
return $this->respond($response, 200, $data);
}

+ 2
- 0
lib/XRay.php View File

@ -40,6 +40,7 @@ class XRay {
unset($result['original']);
$result['url'] = $url;
$result['code'] = isset($result['code']) ? $result['code'] : $code;
$result['source-format'] = isset($result['source-format']) ? $result['source-format'] : null;
return $result;
}
@ -49,6 +50,7 @@ class XRay {
if(!isset($opts['include_original']) || !$opts['include_original'])
unset($result['original']);
$result['url'] = $url;
$result['source-format'] = isset($result['source-format']) ? $result['source-format'] : null;
return $result;
}

+ 2
- 1
lib/XRay/Formats/Facebook.php View File

@ -68,7 +68,8 @@ class Facebook extends Format {
return [
'data' => $event,
'original' => $fbObject
'original' => $fbObject,
'source-format' => 'facebook',
];
}
}

+ 2
- 1
lib/XRay/Formats/GitHub.php View File

@ -166,7 +166,8 @@ class GitHub extends Format {
return [
'data' => $entry,
'original' => $json
'original' => $json,
'source-format' => 'github',
];
}

+ 1
- 0
lib/XRay/Formats/HTML.php View File

@ -105,6 +105,7 @@ class HTML extends Format {
}
$result['original'] = $html;
$result['url'] = $url; // this will be the effective URL after following redirects
$result['source-format'] = 'mf2+html';
}
}
return $result;

+ 2
- 1
lib/XRay/Formats/Hackernews.php View File

@ -83,7 +83,8 @@ class Hackernews extends Format {
return [
'data' => $entry,
'original' => $json
'original' => $json,
'source-format' => 'hackernews',
];
}

+ 6
- 3
lib/XRay/Formats/Instagram.php View File

@ -34,7 +34,8 @@ class Instagram extends Format {
$card = self::_buildHCardFromInstagramProfile($profileData);
return [
'data' => $card
'data' => $card,
'source-format' => 'instagram',
];
}
@ -61,7 +62,8 @@ class Instagram extends Format {
'data' => [
'type' => 'feed',
'items' => $items,
]
],
'source-format' => 'instagram',
];
}
@ -206,7 +208,8 @@ class Instagram extends Format {
'photo' => $photoData,
'profiles' => $profiles,
'locations' => $locations
])
]),
'source-format' => 'instagram',
];
}

+ 1
- 0
lib/XRay/Formats/JSONFeed.php View File

@ -16,6 +16,7 @@ class JSONFeed extends Format {
'type' => 'unknown',
],
'url' => $url,
'source-format' => 'feed+json',
];
if($feed) {

+ 1
- 1
lib/XRay/Formats/Mf2.php View File

@ -448,7 +448,7 @@ class Mf2 extends Format {
$data['post-type'] = \p3k\XRay\PostType::discover($data);
$response = [
'data' => $data
'data' => $data,
];
if(count($refs)) {

+ 2
- 1
lib/XRay/Formats/Mf2Feed.php View File

@ -67,7 +67,8 @@ trait Mf2Feed {
}
return [
'data' => $data
'data' => $data,
'source-format' => 'mf2+html',
];
}

+ 1
- 0
lib/XRay/Formats/Twitter.php View File

@ -175,6 +175,7 @@ class Twitter extends Format {
return [
'data' => $entry,
'original' => $tweet,
'source-format' => 'twitter',
];
}

+ 2
- 1
lib/XRay/Formats/XKCD.php View File

@ -60,7 +60,8 @@ class XKCD extends Format {
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
$response = [
'data' => $entry
'data' => $entry,
'source-format' => 'xkcd',
];
return $response;

+ 1
- 0
lib/XRay/Formats/XML.php View File

@ -18,6 +18,7 @@ class XML extends Format {
'type' => 'unknown',
],
'url' => $url,
'source-format' => 'xml',
];
try {

+ 9
- 3
lib/XRay/Parser.php View File

@ -44,7 +44,9 @@ class Parser {
// Check if an mf2 JSON object was passed in
if(is_array($body) && isset($body['items'][0]['type']) && isset($body['items'][0]['properties'])) {
return Formats\Mf2::parse($body, $url, $this->http, $opts);
$data = Formats\Mf2::parse($body, $url, $this->http, $opts);
$data['source-format'] = 'mf2+json';
return $data;
}
if(substr($body, 0, 5) == '<?xml') {
@ -57,12 +59,16 @@ class Parser {
return Formats\JSONFeed::parse($feeddata, $url);
} elseif($feeddata && isset($feeddata['items'][0]['type']) && isset($feeddata['items'][0]['properties'])) {
// Check if an mf2 JSON object was passed in
return Formats\Mf2::parse($feeddata, $url, $this->http, $opts);
$data = Formats\Mf2::parse($feeddata, $url, $this->http, $opts);
$data['source-format'] = 'mf2+json';
return $data;
}
}
// No special parsers matched, parse for Microformats now
return Formats\HTML::parse($this->http, $body, $url, $opts);
$data = Formats\HTML::parse($this->http, $body, $url, $opts);
$data['source-format'] = 'mf2+html';
return $data;
}
}

+ 1
- 0
tests/AuthorTest.php View File

@ -26,6 +26,7 @@ class AuthorTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEmpty($data->data->author->url);
$this->assertEquals('Author Name', $data->data->author->name);
$this->assertEmpty($data->data->author->photo);

+ 6
- 0
tests/FacebookTest.php View File

@ -31,6 +31,9 @@ class FacebookTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertArrayHasKey('code', $data);
$this->assertEquals('facebook', $data['source-format']);
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('IndieWeb Summit', $data['data']['name']);
@ -58,6 +61,9 @@ class FacebookTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertArrayHasKey('code', $data);
$this->assertEquals('facebook', $data['source-format']);
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']);

+ 42
- 24
tests/FeedTest.php View File

@ -24,8 +24,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
@ -42,8 +43,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
@ -65,8 +67,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
// This test should find the h-entry rather than the h-card, because expect=feed
$this->assertEquals('entry', $data->items[0]->type);
@ -80,8 +83,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
@ -96,8 +100,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
@ -116,8 +121,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
@ -132,8 +138,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
@ -153,8 +160,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name);
@ -174,8 +182,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('mf2+html', $result->{'source-format'});
$data = $result->data;
$this->assertEquals('card', $data->type);
$this->assertEquals('Author Name', $data->name);
}
@ -186,7 +195,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('feed+json', $result->{'source-format'});
$data = $result->data;
$this->assertEquals(10, count($data->items));
for($i=0; $i<8; $i++) {
@ -217,7 +228,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('xml', $result->{'source-format'});
$data = $result->data;
$this->assertEquals(8, count($data->items));
for($i=0; $i<8; $i++) {
@ -246,7 +259,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('xml', $result->{'source-format'});
$data = $result->data;
$this->assertEquals(10, count($data->items));
for($i=0; $i<10; $i++) {
@ -276,7 +291,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('xml', $result->{'source-format'});
$data = $result->data;
$this->assertEquals(12, count($data->items));
for($i=0; $i<12; $i++) {
@ -309,8 +326,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$result = json_decode($body);
$this->assertEquals('xml', $result->{'source-format'});
$data = $result->data;
$this->assertEquals(12, count($data->items));
$this->assertEquals('Marshall Kirkpatrick', $data->items[11]->author->name);

+ 15
- 0
tests/GitHubTest.php View File

@ -27,6 +27,9 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('github', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('https://github.com/idno/Known', $data['data']['in-reply-to'][0]);
@ -47,6 +50,9 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('github', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('https://github.com/aaronpk/XRay/issues', $data['data']['in-reply-to'][0]);
@ -68,6 +74,9 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('github', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertContains('silo', $data['data']['category']);
}
@ -80,6 +89,9 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('github', $data['source-format']);
$this->assertEquals('repo', $data['data']['type']);
$this->assertArrayNotHasKey('post-type', $data['data']);
$this->assertEquals('2016-02-19T16:53:20Z', $data['data']['published']);
@ -98,6 +110,9 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('github', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('https://github.com/aaronpk/XRay/issues/25', $data['data']['in-reply-to'][0]);

+ 6
- 0
tests/HackernewsTest.php View File

@ -26,6 +26,9 @@ class HackernewsTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('hackernews', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('article', $data['data']['post-type']);
$this->assertEquals('2017-06-08T19:32:12+00:00', $data['data']['published']);
@ -50,6 +53,9 @@ What projects or companies are you working on to combat filter bubbles, walled g
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('hackernews', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('2017-06-08T20:23:20+00:00', $data['data']['published']);

+ 29
- 0
tests/InstagramTest.php View File

@ -27,6 +27,8 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertEquals('2017-01-05T23:31:32+00:00', $data['data']['published']);
@ -49,6 +51,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertSame([
@ -88,6 +93,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('video', $data['data']['post-type']);
$this->assertContains('100daysofmusic', $data['data']['category']);
@ -110,6 +118,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals(2, count($data['data']['category']));
$this->assertContains('http://www.kmikeym.com/', $data['data']['category']);
$this->assertArrayHasKey('http://www.kmikeym.com/', $data['data']['refs']);
@ -125,6 +136,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals(1, count($data['data']['location']));
$this->assertContains('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['location']);
$this->assertArrayHasKey('https://www.instagram.com/explore/locations/109284789535230/', $data['data']['refs']);
@ -145,6 +159,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals(2, count($data['data']['photo']));
$this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/406101ff9601ab78147e121b65ce3eea/5B5BC738/t51.2885-15/e35/21827424_134752690591737_8093088291252862976_n.jpg', $data['data']['photo'][0]);
$this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/03ddc8c03c8708439dae29663b8c2305/5B5EDE4D/t51.2885-15/e35/21909774_347707439021016_5237540582556958720_n.jpg', $data['data']['photo'][1]);
@ -161,6 +178,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals('photo', $data['data']['post-type']); // we discard videos in this case right now
$this->assertEquals(3, count($data['data']['photo']));
$this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/b0f6cd9dc4d5c3371efe9f412a0d7f0b/5B6BC5B8/t51.2885-15/e35/21878922_686481254874005_8468823712617988096_n.jpg', $data['data']['photo'][0]);
@ -178,6 +198,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertSame([
'type' => 'card',
'name' => 'Aaron Parecki',
@ -195,6 +218,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertSame([
'type' => 'card',
'name' => 'pk_spam',
@ -212,6 +238,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('instagram', $data['source-format']);
$this->assertEquals('feed', $data['data']['type']);
$this->assertEquals(12, count($data['data']['items']));
$this->assertEquals('https://www.instagram.com/p/Be0lBpGDncI/', $data['data']['items'][0]['url']);

+ 47
- 4
tests/ParseTest.php View File

@ -87,6 +87,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
]);
$xray = new \p3k\XRay();
$parsed = $xray->process(false, $mf2JSON);
$this->assertEquals('mf2+json', $parsed['source-format']);
$item = $parsed['data'];
$this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
@ -107,6 +108,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
]);
$xray = new \p3k\XRay();
$parsed = $xray->process(false, $mf2JSON);
$this->assertEquals('mf2+json', $parsed['source-format']);
$item = $parsed['data'];
$this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
@ -127,6 +129,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
]);
$xray = new \p3k\XRay();
$parsed = $xray->process(false, $mf2JSON);
$this->assertEquals('mf2+json', $parsed['source-format']);
$item = $parsed['data'];
$this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
@ -147,6 +150,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
]);
$xray = new \p3k\XRay();
$parsed = $xray->process(false, $mf2JSON);
$this->assertEquals('mf2+json', $parsed['source-format']);
$item = $parsed['data'];
$this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
@ -167,6 +171,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
]);
$xray = new \p3k\XRay();
$parsed = $xray->process(false, $mf2JSON);
$this->assertEquals('mf2+json', $parsed['source-format']);
$item = $parsed['data'];
$this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
@ -180,6 +185,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('photo', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('name', $data->data);
$this->assertEquals('This page has an img tag with the target URL.', $data->data->content->text);
@ -192,6 +198,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('video', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('name', $data->data);
$this->assertEquals('This page has a video tag with the target URL.', $data->data->content->text);
@ -204,6 +211,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('audio', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('name', $data->data);
$this->assertEquals('This page has an audio tag with the target URL.', $data->data->content->text);
@ -216,6 +224,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertObjectNotHasAttribute('name', $data->data);
$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);
}
@ -227,6 +236,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('article', $data->data->{'post-type'});
$this->assertEquals('Post Title', $data->data->name);
$this->assertEquals('This is a blog post.', $data->data->content->text);
@ -240,6 +250,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertObjectNotHasAttribute('name', $data->data);
$this->assertEquals('note', $data->data->{'post-type'});
$this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
@ -253,6 +264,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('Hello World', $data->data->name);
$this->assertEquals('article', $data->data->{'post-type'});
$this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
@ -266,6 +278,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('Hello World', $data->data->name);
$this->assertEquals('article', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('content', $data->data);
@ -278,6 +291,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals(['indieweb'], $data->data->category);
}
@ -288,6 +302,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertContains('indieweb', $data->data->category);
$this->assertContains('xray', $data->data->category);
$this->assertEquals(2, count($data->data->category));
@ -300,6 +315,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('unknown', $data->data->type);
}
@ -310,6 +326,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
}
@ -321,6 +338,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
@ -336,6 +354,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('http://alice.example.com/', $data['data']['category'][0]);
}
@ -347,6 +366,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('http://alice.example.com/', $data['data']['category'][0]);
$this->assertArrayHasKey('http://alice.example.com/', $data['data']['refs']);
@ -362,6 +382,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('http://syndicated.example/', $data['data']['syndication'][0]);
}
@ -373,6 +394,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertObjectNotHasAttribute('content', $data->data);
$this->assertEquals('This is a Post', $data->data->name);
}
@ -384,6 +406,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
}
@ -395,6 +418,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('rsvp', $data['data']['post-type']);
$this->assertEquals('I\'ll be there!', $data['data']['content']['text']);
@ -408,6 +432,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Primary Post', $data['data']['name']);
}
@ -419,6 +444,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
}
@ -430,6 +456,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
}
@ -441,6 +468,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
}
@ -452,6 +480,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
}
@ -463,6 +492,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']);
@ -482,6 +512,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']);
@ -500,7 +531,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']);
@ -520,7 +551,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('review', $data['data']['type']);
$this->assertEquals('review', $data['data']['post-type']);
$this->assertEquals('Review', $data['data']['name']);
@ -544,7 +575,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('review', $data['data']['type']);
$this->assertEquals('review', $data['data']['post-type']);
$this->assertEquals('Review', $data['data']['name']);
@ -566,7 +597,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('review', $data['data']['type']);
$this->assertEquals('review', $data['data']['post-type']);
$this->assertEquals('Not great', $data['data']['name']);
@ -588,6 +619,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('recipe', $data['data']['type']);
$this->assertEquals('recipe', $data['data']['post-type']);
$this->assertEquals('Cookie Recipe', $data['data']['name']);
@ -606,6 +638,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('https://www.facebook.com/555707837940351#tantek', $data['data']['url']);
$this->assertContains('https://www.facebook.com/tantek.celik', $data['data']['invitee']);
@ -620,6 +653,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('Comment text', $data['data']['content']['text']);
@ -634,6 +668,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('http://source.example.com/fragment-id', $data['data']['url']);
$this->assertFalse($data['info']['found_fragment']);
@ -647,6 +682,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$venue = $data['data']['checkin'];
$this->assertEquals('checkin', $data['data']['post-type']);
@ -667,6 +703,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('checkin', $data['data']['post-type']);
$venue = $data['data']['checkin'];
@ -684,6 +721,8 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals(200, $data['code']);
$this->assertEquals('xkcd', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertEquals('http://xkcd.com/1810/', $data['data']['url']);
@ -728,6 +767,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+json', $data['source-format']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
$this->assertEquals('http://example.com/photo.jpg', $data['data']['photo'][0]);
@ -747,6 +787,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+json', $data['source-format']);
$this->assertEquals('Hello World', $data['data']['content']['text']);
$this->assertEquals('<b>Hello</b> <i>World</i>', $data['data']['content']['html']);
$this->assertEquals('http://example.com/photo.jpg', $data['data']['photo'][0]);
@ -759,6 +800,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('mf2+html', $data['source-format']);
$this->assertEquals('app', $data['data']['type']);
$this->assertEquals('http://source.example.com/images/quill.png', $data['data']['logo']);
$this->assertEquals('Quill', $data['data']['name']);
@ -774,6 +816,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('mf2+html', $data->{'source-format'});
$this->assertEquals('app', $data->data->type);
$this->assertEquals('http://source.example.com/images/quill.png', $data->data->logo);
$this->assertEquals('Quill', $data->data->name);

+ 9
- 0
tests/TwitterTest.php View File

@ -31,6 +31,8 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('twitter', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('aaronpk dev', $data['data']['author']['name']);
$this->assertEquals('pkdev', $data['data']['author']['nickname']);
@ -54,6 +56,8 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals(null, $data['code']); // no code is expected if we pass in the body
$this->assertEquals('twitter', $data['source-format']);
$this->assertEquals('https://twitter.com/pkdev/status/818913630569664512', $data['url']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('note', $data['data']['post-type']);
@ -77,6 +81,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('twitter', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('Here 🎉 have an emoji', $data['data']['content']['text']);
}
@ -158,6 +163,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('twitter', $data['source-format']);
$this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('repost', $data['data']['post-type']);
$this->assertArrayNotHasKey('content', $data['data']);
@ -212,6 +218,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
list($url, $json) = $this->loadTweet('streaming-tweet-with-link');
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('twitter', $data['source-format']);
$this->assertEquals('what happens if i include a link like https://kmikeym.com', $data['data']['content']['text']);
$this->assertEquals('what happens if i include a link like <a href="https://kmikeym.com">https://kmikeym.com</a>', $data['data']['content']['html']);
}
@ -269,6 +276,7 @@ Woke up this morning feeling compelled to run to Corona… http://tantek.com/201
list($url, $json) = $this->loadTweet('streaming-tweet-reply');
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('twitter', $data['source-format']);
$this->assertEquals('https://twitter.com/anomalily/status/967024586423386112', $data['data']['in-reply-to'][0]);
}
@ -276,6 +284,7 @@ Woke up this morning feeling compelled to run to Corona… http://tantek.com/201
list($url, $json) = $this->loadTweet('967046438822674432');
$data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('twitter', $data['source-format']);
$this->assertEquals('https://twitter.com/anomalily/status/967024586423386112', $data['data']['in-reply-to'][0]);
}

Loading…
Cancel
Save