Browse Source

implements post type discovery

returns a new property `post-type` next to `type`

closes #25
pull/78/head v1.5.0
Aaron Parecki 6 years ago
parent
commit
38d307de1c
No known key found for this signature in database GPG Key ID: 276C2817346D6056
18 changed files with 183 additions and 3 deletions
  1. +28
    -1
      README.md
  2. +2
    -0
      lib/XRay/Formats/Facebook.php
  3. +7
    -0
      lib/XRay/Formats/GitHub.php
  4. +2
    -0
      lib/XRay/Formats/Hackernews.php
  5. +2
    -0
      lib/XRay/Formats/Instagram.php
  6. +2
    -0
      lib/XRay/Formats/JSONFeed.php
  7. +9
    -1
      lib/XRay/Formats/Mf2.php
  8. +2
    -0
      lib/XRay/Formats/Twitter.php
  9. +3
    -1
      lib/XRay/Formats/XKCD.php
  10. +2
    -0
      lib/XRay/Formats/XML.php
  11. +66
    -0
      lib/XRay/PostType.php
  12. +2
    -0
      tests/FacebookTest.php
  13. +8
    -0
      tests/FeedTest.php
  14. +7
    -0
      tests/GitHubTest.php
  15. +2
    -0
      tests/HackernewsTest.php
  16. +4
    -0
      tests/InstagramTest.php
  17. +26
    -0
      tests/ParseTest.php
  18. +9
    -0
      tests/TwitterTest.php

+ 28
- 1
README.md View File

@ -28,6 +28,7 @@ Finally, XRay looks for Microformats on the page and will determine the content
* h-item * h-item
* h-feed * h-feed
## Library ## Library
XRay can be used as a library in your PHP project. The easiest way to install it and its dependencies is via composer. XRay can be used as a library in your PHP project. The easiest way to install it and its dependencies is via composer.
@ -116,6 +117,7 @@ Array
[data] => Array [data] => Array
( (
[type] => entry [type] => entry
[post-type] => photo
[photo] => Array [photo] => Array
( (
[0] => http://example.com/photo.jpg [0] => http://example.com/photo.jpg
@ -336,6 +338,7 @@ Possible errors are listed below:
{ {
"data":{ "data":{
"type":"entry", "type":"entry",
"post-type":"photo",
"published":"2017-03-01T19:00:33-08:00", "published":"2017-03-01T19:00:33-08:00",
"url":"https://aaronparecki.com/2017/03/01/14/hwc", "url":"https://aaronparecki.com/2017/03/01/14/hwc",
"category":[ "category":[
@ -368,6 +371,9 @@ Possible errors are listed below:
The primary object on the page is returned in the `data` property. This will indicate the type of object (e.g. `entry`), and will contain the vocabulary's properties that it was able to parse from the page. The primary object on the page is returned in the `data` property. This will indicate the type of object (e.g. `entry`), and will contain the vocabulary's properties that it was able to parse from the page.
* `type` - the Microformats 2 vocabulary found for the primary object on the page, without the `h-` prefix (e.g. `entry`, `event`)
* `post-type` - only for "posts" (e.g. not for `card`s) - the [Post Type](https://www.w3.org/TR/post-type-discovery/) of the post (e.g. (`note`, `photo`, `reply`))
If a property supports multiple values, it will always be returned as an array. The following properties support multiple values: If a property supports multiple values, it will always be returned as an array. The following properties support multiple values:
* `in-reply-to` * `in-reply-to`
@ -375,7 +381,7 @@ If a property supports multiple values, it will always be returned as an array.
* `repost-of` * `repost-of`
* `bookmark-of` * `bookmark-of`
* `syndication` * `syndication`
* `photo` (of entry, not of a card)
* `photo` (of an entry, not of a card)
* `video` * `video`
* `audio` * `audio`
* `category` * `category`
@ -386,6 +392,27 @@ The author will always be set in the entry if available. The service follows the
All URLs provided in the output are absolute URLs. If the source document contains a relative URL, it will be resolved first. All URLs provided in the output are absolute URLs. If the source document contains a relative URL, it will be resolved first.
#### Post Type Discovery
XRay runs the [Post Type Discovery](https://www.w3.org/TR/post-type-discovery/) algorithm and also includes a `post-type` property.
The following post types are returned, which are slightly expanded from what is currently documented by the Post Type Discovery spec.
* `event`
* `recipe`
* `review`
* `rsvp`
* `repost`
* `like`
* `reply`
* `bookmark`
* `checkin`
* `video`
* `audio`
* `photo`
* `article`
* `note`
#### Other Properties #### Other Properties

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

@ -64,6 +64,8 @@ class Facebook extends Format {
$event['location'] = $fbObject['place']['name']; $event['location'] = $fbObject['place']['name'];
} }
$event['post-type'] = \p3k\XRay\PostType::discover($event);
return [ return [
'data' => $event, 'data' => $event,
'original' => $fbObject 'original' => $fbObject

+ 7
- 0
lib/XRay/Formats/GitHub.php View File

@ -147,6 +147,10 @@ class GitHub extends Format {
if($parts['type'] == 'comment') { if($parts['type'] == 'comment') {
$entry['in-reply-to'] = ['https://github.com/'.$parts['org'].'/'.$parts['repo'].'/issues/'.$parts['issue']]; $entry['in-reply-to'] = ['https://github.com/'.$parts['org'].'/'.$parts['repo'].'/issues/'.$parts['issue']];
} elseif($parts['type'] == 'pull') {
$entry['in-reply-to'] = ['https://github.com/'.$parts['org'].'/'.$parts['repo']];
} elseif($parts['type'] == 'issue') {
$entry['in-reply-to'] = ['https://github.com/'.$parts['org'].'/'.$parts['repo'].'/issues'];
} }
if(!empty($data['labels'])) { if(!empty($data['labels'])) {
@ -157,6 +161,9 @@ class GitHub extends Format {
$entry['published'] = $data['created_at']; $entry['published'] = $data['created_at'];
if($entry['type'] != 'repo')
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
return [ return [
'data' => $entry, 'data' => $entry,
'original' => $json 'original' => $json

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

@ -79,6 +79,8 @@ class Hackernews extends Format {
$entry['in-reply-to'] = ['https://news.ycombinator.com/item?id='.$data['parent']]; $entry['in-reply-to'] = ['https://news.ycombinator.com/item?id='.$data['parent']];
} }
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
return [ return [
'data' => $entry, 'data' => $entry,
'original' => $json 'original' => $json

+ 2
- 0
lib/XRay/Formats/Instagram.php View File

@ -198,6 +198,8 @@ class Instagram extends Format {
$entry['refs'] = $refs; $entry['refs'] = $refs;
} }
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
return [ return [
'data' => $entry, 'data' => $entry,
'original' => json_encode([ 'original' => json_encode([

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

@ -99,6 +99,8 @@ class JSONFeed extends Format {
$entry['category'] = $item['tags']; $entry['category'] = $item['tags'];
} }
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
return $entry; return $entry;
} }
} }

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

@ -445,6 +445,8 @@ class Mf2 extends Format {
if($checkin = self::parseEmbeddedHCard('checkin', $item, $http)) if($checkin = self::parseEmbeddedHCard('checkin', $item, $http))
$data['checkin'] = $checkin; $data['checkin'] = $checkin;
$data['post-type'] = \p3k\XRay\PostType::discover($data);
$response = [ $response = [
'data' => $data 'data' => $data
]; ];
@ -479,6 +481,8 @@ class Mf2 extends Format {
if($author = self::findAuthor($mf2, $item, $http, $url)) if($author = self::findAuthor($mf2, $item, $http, $url))
$data['author'] = $author; $data['author'] = $author;
$data['post-type'] = \p3k\XRay\PostType::discover($data);
$response = [ $response = [
'data' => $data 'data' => $data
]; ];
@ -492,7 +496,7 @@ class Mf2 extends Format {
private static function parseAsHRecipe($mf2, $item, $http, $url) { private static function parseAsHRecipe($mf2, $item, $http, $url) {
$data = [ $data = [
'type' => 'recipe'
'type' => 'recipe',
]; ];
$refs = []; $refs = [];
@ -510,6 +514,8 @@ class Mf2 extends Format {
if($author = self::findAuthor($mf2, $item, $http, $url)) if($author = self::findAuthor($mf2, $item, $http, $url))
$data['author'] = $author; $data['author'] = $author;
$data['post-type'] = \p3k\XRay\PostType::discover($data);
$response = [ $response = [
'data' => $data 'data' => $data
]; ];
@ -619,6 +625,8 @@ class Mf2 extends Format {
$data['description'] = $description; $data['description'] = $description;
} }
$data['post-type'] = \p3k\XRay\PostType::discover($data);
$response = [ $response = [
'data' => $data 'data' => $data
]; ];

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

@ -170,6 +170,8 @@ class Twitter extends Format {
$entry['refs'] = $refs; $entry['refs'] = $refs;
} }
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
return [ return [
'data' => $entry, 'data' => $entry,
'original' => $tweet, 'original' => $tweet,

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

@ -36,7 +36,7 @@ class XKCD extends Format {
if(!$name) if(!$name)
return self::_unknown(); return self::_unknown();
$entry['name'] = $name->nodeValue; $entry['name'] = $name->nodeValue;
$photo = $xpath->query("//div[@id='comic']/img"); $photo = $xpath->query("//div[@id='comic']/img");
@ -57,6 +57,8 @@ class XKCD extends Format {
$entry['photo'] = [$src]; $entry['photo'] = [$src];
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
$response = [ $response = [
'data' => $entry 'data' => $entry
]; ];

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

@ -109,6 +109,8 @@ class XML extends Format {
$entry[$prop] = [$item->getEnclosureUrl()]; $entry[$prop] = [$item->getEnclosureUrl()];
} }
$entry['post-type'] = \p3k\XRay\PostType::discover($entry);
return $entry; return $entry;
} }

+ 66
- 0
lib/XRay/PostType.php View File

@ -0,0 +1,66 @@
<?php
namespace p3k\XRay;
class PostType {
// Takes an XRay format post and runs post-type-discovery, returning a single string
// https://www.w3.org/TR/post-type-discovery/
public static function discover($post) {
// A few of the post types are defined as the same as their microformats h-* types
if(in_array($post['type'], ['event','recipe','review']))
return $post['type'];
if(isset($post['rsvp']))
return 'rsvp';
if(isset($post['repost-of']))
return 'repost';
if(isset($post['like-of']))
return 'like';
if(isset($post['in-reply-to']))
return 'reply';
if(isset($post['bookmark-of']))
return 'bookmark';
if(isset($post['checkin']))
return 'checkin';
if(isset($post['video']))
return 'video';
if(isset($post['audio']))
return 'audio';
if(isset($post['photo']))
return 'photo';
$content = '';
if(isset($post['content']))
$content = $post['content']['text'];
elseif(isset($post['summary']))
$content = $post['summary'];
if(!isset($post['name']) || !trim($post['name']))
return 'note';
// Trim all leading/trailing whitespace
$name = trim($post['name']);
// Collapse all sequences of internal whitespace to a single space (0x20) character each
$name = preg_replace('/\s+/', ' ', $name);
$content = preg_replace('/\s+/', ' ', $content);
// If this processed "name" property value is NOT a prefix of the
// processed "content" property, then it is an article post.
if(strpos($content, $name) === false) {
return 'article';
}
return 'note';
}
}

+ 2
- 0
tests/FacebookTest.php View File

@ -32,6 +32,7 @@ class FacebookTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('event', $data['data']['type']); $this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('IndieWeb Summit', $data['data']['name']); $this->assertEquals('IndieWeb Summit', $data['data']['name']);
$this->assertEquals('2017-06-24T09:00:00-0700', $data['data']['start']); $this->assertEquals('2017-06-24T09:00:00-0700', $data['data']['start']);
$this->assertEquals('2017-06-25T18:00:00-0700', $data['data']['end']); $this->assertEquals('2017-06-25T18:00:00-0700', $data['data']['end']);
@ -58,6 +59,7 @@ class FacebookTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('event', $data['data']['type']); $this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals('Homebrew Website Club', $data['data']['name']);
$this->assertEquals('2015-04-22T19:00:00-0400', $data['data']['start']); $this->assertEquals('2015-04-22T19:00:00-0400', $data['data']['start']);
$this->assertContains('Are you building your own website? Indie reader?', $data['data']['summary']); $this->assertContains('Are you building your own website? Indie reader?', $data['data']['summary']);

+ 8
- 0
tests/FeedTest.php View File

@ -29,7 +29,9 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('feed', $data->type); $this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items)); $this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name); $this->assertEquals('One', $data->items[0]->name);
$this->assertEquals('article', $data->items[0]->{'post-type'});
$this->assertEquals('Two', $data->items[1]->name); $this->assertEquals('Two', $data->items[1]->name);
$this->assertEquals('article', $data->items[1]->{'post-type'});
$this->assertEquals('Three', $data->items[2]->name); $this->assertEquals('Three', $data->items[2]->name);
$this->assertEquals('Four', $data->items[3]->name); $this->assertEquals('Four', $data->items[3]->name);
} }
@ -45,6 +47,7 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('feed', $data->type); $this->assertEquals('feed', $data->type);
$this->assertEquals(4, count($data->items)); $this->assertEquals(4, count($data->items));
$this->assertEquals('One', $data->items[0]->name); $this->assertEquals('One', $data->items[0]->name);
$this->assertEquals('article', $data->items[0]->{'post-type'});
$this->assertEquals('Two', $data->items[1]->name); $this->assertEquals('Two', $data->items[1]->name);
$this->assertEquals('Three', $data->items[2]->name); $this->assertEquals('Three', $data->items[2]->name);
$this->assertEquals('Four', $data->items[3]->name); $this->assertEquals('Four', $data->items[3]->name);
@ -196,6 +199,8 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertNotEmpty($data->items[$i]->content->html); $this->assertNotEmpty($data->items[$i]->content->html);
$this->assertNotEmpty($data->items[$i]->content->text); $this->assertNotEmpty($data->items[$i]->content->text);
} }
$this->assertEquals('note', $data->items[0]->{'post-type'});
$this->assertEquals('article', $data->items[4]->{'post-type'});
$this->assertEquals('<p>Lots of good feedback on <a href="http://help.micro.blog/2017/wordpress-import/">the WordPress import</a>. Made a couple improvements this morning. Overall, pretty good.</p>', $data->items[9]->content->html); $this->assertEquals('<p>Lots of good feedback on <a href="http://help.micro.blog/2017/wordpress-import/">the WordPress import</a>. Made a couple improvements this morning. Overall, pretty good.</p>', $data->items[9]->content->html);
$this->assertEquals('Lots of good feedback on the WordPress import. Made a couple improvements this morning. Overall, pretty good.', $data->items[9]->content->text); $this->assertEquals('Lots of good feedback on the WordPress import. Made a couple improvements this morning. Overall, pretty good.', $data->items[9]->content->text);
@ -217,6 +222,7 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(8, count($data->items)); $this->assertEquals(8, count($data->items));
for($i=0; $i<8; $i++) { for($i=0; $i<8; $i++) {
$this->assertEquals('entry', $data->items[$i]->type); $this->assertEquals('entry', $data->items[$i]->type);
$this->assertEquals('note', $data->items[$i]->{'post-type'});
$this->assertEquals('Tantek', $data->items[$i]->author->name); $this->assertEquals('Tantek', $data->items[$i]->author->name);
$this->assertEquals('http://tantek.com/', $data->items[$i]->author->url); $this->assertEquals('http://tantek.com/', $data->items[$i]->author->url);
$this->assertNotEmpty($data->items[$i]->url); $this->assertNotEmpty($data->items[$i]->url);
@ -245,6 +251,7 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(10, count($data->items)); $this->assertEquals(10, count($data->items));
for($i=0; $i<10; $i++) { for($i=0; $i<10; $i++) {
$this->assertEquals('entry', $data->items[$i]->type); $this->assertEquals('entry', $data->items[$i]->type);
$this->assertEquals('note', $data->items[$i]->{'post-type'});
$this->assertEquals('Ryan Barrett', $data->items[$i]->author->name); $this->assertEquals('Ryan Barrett', $data->items[$i]->author->name);
$this->assertEquals('https://snarfed.org/', $data->items[$i]->author->url); $this->assertEquals('https://snarfed.org/', $data->items[$i]->author->url);
$this->assertNotEmpty($data->items[$i]->url); $this->assertNotEmpty($data->items[$i]->url);
@ -274,6 +281,7 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(12, count($data->items)); $this->assertEquals(12, count($data->items));
for($i=0; $i<12; $i++) { for($i=0; $i<12; $i++) {
$this->assertEquals('entry', $data->items[$i]->type); $this->assertEquals('entry', $data->items[$i]->type);
$this->assertEquals('audio', $data->items[$i]->{'post-type'});
$this->assertEquals('Aaron Parecki', $data->items[$i]->author->name); $this->assertEquals('Aaron Parecki', $data->items[$i]->author->name);
$this->assertEquals('https://percolator.today/', $data->items[$i]->author->url); $this->assertEquals('https://percolator.today/', $data->items[$i]->author->url);
$this->assertNotEmpty($data->items[$i]->url); $this->assertNotEmpty($data->items[$i]->url);

+ 7
- 0
tests/GitHubTest.php View File

@ -28,6 +28,8 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $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]);
$this->assertEquals('2017-04-10T17:44:57Z', $data['data']['published']); $this->assertEquals('2017-04-10T17:44:57Z', $data['data']['published']);
$this->assertEquals('aaronpk', $data['data']['author']['name']); $this->assertEquals('aaronpk', $data['data']['author']['name']);
$this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']); $this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']);
@ -46,6 +48,8 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $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]);
$this->assertEquals('2017-01-26T14:13:42Z', $data['data']['published']); $this->assertEquals('2017-01-26T14:13:42Z', $data['data']['published']);
$this->assertEquals('sebsel', $data['data']['author']['name']); $this->assertEquals('sebsel', $data['data']['author']['name']);
$this->assertEquals('https://github.com/sebsel', $data['data']['author']['url']); $this->assertEquals('https://github.com/sebsel', $data['data']['author']['url']);
@ -77,6 +81,7 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('repo', $data['data']['type']); $this->assertEquals('repo', $data['data']['type']);
$this->assertArrayNotHasKey('post-type', $data['data']);
$this->assertEquals('2016-02-19T16:53:20Z', $data['data']['published']); $this->assertEquals('2016-02-19T16:53:20Z', $data['data']['published']);
$this->assertEquals('aaronpk', $data['data']['author']['name']); $this->assertEquals('aaronpk', $data['data']['author']['name']);
$this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']); $this->assertEquals('https://github.com/aaronpk', $data['data']['author']['url']);
@ -94,6 +99,8 @@ class GitHubTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $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]);
$this->assertEquals('2017-01-26T16:24:37Z', $data['data']['published']); $this->assertEquals('2017-01-26T16:24:37Z', $data['data']['published']);
$this->assertEquals('sebsel', $data['data']['author']['name']); $this->assertEquals('sebsel', $data['data']['author']['name']);
$this->assertEquals('https://avatars3.githubusercontent.com/u/16517999?v=3', $data['data']['author']['photo']); $this->assertEquals('https://avatars3.githubusercontent.com/u/16517999?v=3', $data['data']['author']['photo']);

+ 2
- 0
tests/HackernewsTest.php View File

@ -27,6 +27,7 @@ class HackernewsTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $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']); $this->assertEquals('2017-06-08T19:32:12+00:00', $data['data']['published']);
$this->assertEquals('vkb', $data['data']['author']['name']); $this->assertEquals('vkb', $data['data']['author']['name']);
$this->assertEquals('https://news.ycombinator.com/user?id=vkb', $data['data']['author']['url']); $this->assertEquals('https://news.ycombinator.com/user?id=vkb', $data['data']['author']['url']);
@ -50,6 +51,7 @@ What projects or companies are you working on to combat filter bubbles, walled g
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $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']); $this->assertEquals('2017-06-08T20:23:20+00:00', $data['data']['published']);
$this->assertEquals('aaronpk', $data['data']['author']['name']); $this->assertEquals('aaronpk', $data['data']['author']['name']);
$this->assertEquals('https://news.ycombinator.com/user?id=aaronpk', $data['data']['author']['url']); $this->assertEquals('https://news.ycombinator.com/user?id=aaronpk', $data['data']['author']['url']);

+ 4
- 0
tests/InstagramTest.php View File

@ -28,6 +28,7 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $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']); $this->assertEquals('2017-01-05T23:31:32+00:00', $data['data']['published']);
$this->assertContains('planning', $data['data']['category']); $this->assertContains('planning', $data['data']['category']);
$this->assertContains('2017', $data['data']['category']); $this->assertContains('2017', $data['data']['category']);
@ -49,6 +50,7 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertSame([ $this->assertSame([
'type' => 'card', 'type' => 'card',
'name' => 'pk_spam', 'name' => 'pk_spam',
@ -87,6 +89,7 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('video', $data['data']['post-type']);
$this->assertContains('100daysofmusic', $data['data']['category']); $this->assertContains('100daysofmusic', $data['data']['category']);
$this->assertEquals('Day 18. Maple and Spruce #100daysofmusic #100daysproject #the100dayproject https://aaronparecki.com/2017/01/07/14/day18', $data['data']['content']['text']); $this->assertEquals('Day 18. Maple and Spruce #100daysofmusic #100daysproject #the100dayproject https://aaronparecki.com/2017/01/07/14/day18', $data['data']['content']['text']);
$this->assertEquals(1, count($data['data']['photo'])); $this->assertEquals(1, count($data['data']['photo']));
@ -158,6 +161,7 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('photo', $data['data']['post-type']); // we discard videos in this case right now
$this->assertEquals(3, count($data['data']['photo'])); $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]); $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]);
$this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/f8939cca504f97931fd4768b77d2c152/5ADB3CC9/t51.2885-15/e15/21910026_1507234999368159_6974261907783942144_n.jpg', $data['data']['photo'][1]); $this->assertEquals('https://instagram.fsea1-1.fna.fbcdn.net/vp/f8939cca504f97931fd4768b77d2c152/5ADB3CC9/t51.2885-15/e15/21910026_1507234999368159_6974261907783942144_n.jpg', $data['data']['photo'][1]);

+ 26
- 0
tests/ParseTest.php View File

@ -89,6 +89,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$parsed = $xray->process(false, $mf2JSON); $parsed = $xray->process(false, $mf2JSON);
$item = $parsed['data']; $item = $parsed['data'];
$this->assertEquals('entry', $item['type']); $this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
$this->assertEquals('plaintext', $item['content']['text']); $this->assertEquals('plaintext', $item['content']['text']);
$this->assertArrayNotHasKey('html', $item['content']); $this->assertArrayNotHasKey('html', $item['content']);
} }
@ -108,6 +109,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$parsed = $xray->process(false, $mf2JSON); $parsed = $xray->process(false, $mf2JSON);
$item = $parsed['data']; $item = $parsed['data'];
$this->assertEquals('entry', $item['type']); $this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
$this->assertEquals('bold italic text', $item['content']['text']); $this->assertEquals('bold italic text', $item['content']['text']);
$this->assertEquals('<b>bold</b> <i>italic</i> text', $item['content']['html']); $this->assertEquals('<b>bold</b> <i>italic</i> text', $item['content']['html']);
} }
@ -127,6 +129,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$parsed = $xray->process(false, $mf2JSON); $parsed = $xray->process(false, $mf2JSON);
$item = $parsed['data']; $item = $parsed['data'];
$this->assertEquals('entry', $item['type']); $this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
$this->assertArrayNotHasKey('content', $item); $this->assertArrayNotHasKey('content', $item);
} }
@ -146,6 +149,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$parsed = $xray->process(false, $mf2JSON); $parsed = $xray->process(false, $mf2JSON);
$item = $parsed['data']; $item = $parsed['data'];
$this->assertEquals('entry', $item['type']); $this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
$this->assertEquals('bar', $item['content']['text']); $this->assertEquals('bar', $item['content']['text']);
$this->assertEquals('<b>bar</b>', $item['content']['html']); $this->assertEquals('<b>bar</b>', $item['content']['html']);
} }
@ -165,6 +169,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$parsed = $xray->process(false, $mf2JSON); $parsed = $xray->process(false, $mf2JSON);
$item = $parsed['data']; $item = $parsed['data'];
$this->assertEquals('entry', $item['type']); $this->assertEquals('entry', $item['type']);
$this->assertEquals('note', $item['post-type']);
$this->assertArrayNotHasKey('content', $item); $this->assertArrayNotHasKey('content', $item);
} }
@ -175,6 +180,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent(); $body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body); $data = json_decode($body);
$this->assertEquals('photo', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('name', $data->data); $this->assertObjectNotHasAttribute('name', $data->data);
$this->assertEquals('This page has an img tag with the target URL.', $data->data->content->text); $this->assertEquals('This page has an img tag with the target URL.', $data->data->content->text);
} }
@ -186,6 +192,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent(); $body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body); $data = json_decode($body);
$this->assertEquals('video', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('name', $data->data); $this->assertObjectNotHasAttribute('name', $data->data);
$this->assertEquals('This page has a video tag with the target URL.', $data->data->content->text); $this->assertEquals('This page has a video tag with the target URL.', $data->data->content->text);
} }
@ -197,6 +204,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent(); $body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body); $data = json_decode($body);
$this->assertEquals('audio', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('name', $data->data); $this->assertObjectNotHasAttribute('name', $data->data);
$this->assertEquals('This page has an audio tag with the target URL.', $data->data->content->text); $this->assertEquals('This page has an audio tag with the target URL.', $data->data->content->text);
} }
@ -219,6 +227,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent(); $body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body); $data = json_decode($body);
$this->assertEquals('article', $data->data->{'post-type'});
$this->assertEquals('Post Title', $data->data->name); $this->assertEquals('Post Title', $data->data->name);
$this->assertEquals('This is a blog post.', $data->data->content->text); $this->assertEquals('This is a blog post.', $data->data->content->text);
$this->assertEquals('http://source.example.com/featured.jpg', $data->data->featured); $this->assertEquals('http://source.example.com/featured.jpg', $data->data->featured);
@ -232,6 +241,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body); $data = json_decode($body);
$this->assertObjectNotHasAttribute('name', $data->data); $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); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
$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); $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);
} }
@ -244,6 +254,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body); $data = json_decode($body);
$this->assertEquals('Hello World', $data->data->name); $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); $this->assertEquals('This page has a link to target.example.com and some formatted text.', $data->data->content->text);
$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); $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);
} }
@ -256,6 +267,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body); $data = json_decode($body);
$this->assertEquals('Hello World', $data->data->name); $this->assertEquals('Hello World', $data->data->name);
$this->assertEquals('article', $data->data->{'post-type'});
$this->assertObjectNotHasAttribute('content', $data->data); $this->assertObjectNotHasAttribute('content', $data->data);
} }
@ -310,6 +322,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $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]); $this->assertEquals('http://example.com/100', $data['data']['in-reply-to'][0]);
$this->assertArrayHasKey('http://example.com/100', $data['data']['refs']); $this->assertArrayHasKey('http://example.com/100', $data['data']['refs']);
$this->assertEquals('Example Post', $data['data']['refs']['http://example.com/100']['name']); $this->assertEquals('Example Post', $data['data']['refs']['http://example.com/100']['name']);
@ -383,6 +396,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('rsvp', $data['data']['post-type']);
$this->assertEquals('I\'ll be there!', $data['data']['content']['text']); $this->assertEquals('I\'ll be there!', $data['data']['content']['text']);
$this->assertEquals('yes', $data['data']['rsvp']); $this->assertEquals('yes', $data['data']['rsvp']);
} }
@ -448,7 +462,9 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$body = $response->getContent(); $body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('event', $data['data']['type']); $this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals('Homebrew Website Club', $data['data']['name']);
$this->assertEquals($url, $data['data']['url']); $this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2016-03-09T18:30', $data['data']['start']); $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
@ -467,6 +483,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('event', $data['data']['type']); $this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals('Homebrew Website Club', $data['data']['name']);
$this->assertEquals($url, $data['data']['url']); $this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2016-03-09T18:30', $data['data']['start']); $this->assertEquals('2016-03-09T18:30', $data['data']['start']);
@ -485,6 +502,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('event', $data['data']['type']); $this->assertEquals('event', $data['data']['type']);
$this->assertEquals('event', $data['data']['post-type']);
$this->assertEquals('Homebrew Website Club', $data['data']['name']); $this->assertEquals('Homebrew Website Club', $data['data']['name']);
$this->assertEquals($url, $data['data']['url']); $this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2016-02-09T18:30', $data['data']['start']); $this->assertEquals('2016-02-09T18:30', $data['data']['start']);
@ -504,6 +522,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('review', $data['data']['type']); $this->assertEquals('review', $data['data']['type']);
$this->assertEquals('review', $data['data']['post-type']);
$this->assertEquals('Review', $data['data']['name']); $this->assertEquals('Review', $data['data']['name']);
$this->assertEquals('Not great', $data['data']['summary']); $this->assertEquals('Not great', $data['data']['summary']);
$this->assertEquals('3', $data['data']['rating']); $this->assertEquals('3', $data['data']['rating']);
@ -527,6 +546,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('review', $data['data']['type']); $this->assertEquals('review', $data['data']['type']);
$this->assertEquals('review', $data['data']['post-type']);
$this->assertEquals('Review', $data['data']['name']); $this->assertEquals('Review', $data['data']['name']);
$this->assertEquals('Not great', $data['data']['summary']); $this->assertEquals('Not great', $data['data']['summary']);
$this->assertEquals('3', $data['data']['rating']); $this->assertEquals('3', $data['data']['rating']);
@ -548,6 +568,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('review', $data['data']['type']); $this->assertEquals('review', $data['data']['type']);
$this->assertEquals('review', $data['data']['post-type']);
$this->assertEquals('Not great', $data['data']['name']); $this->assertEquals('Not great', $data['data']['name']);
$this->assertEquals('3', $data['data']['rating']); $this->assertEquals('3', $data['data']['rating']);
$this->assertEquals('5', $data['data']['best']); $this->assertEquals('5', $data['data']['best']);
@ -568,6 +589,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('recipe', $data['data']['type']); $this->assertEquals('recipe', $data['data']['type']);
$this->assertEquals('recipe', $data['data']['post-type']);
$this->assertEquals('Cookie Recipe', $data['data']['name']); $this->assertEquals('Cookie Recipe', $data['data']['name']);
$this->assertEquals('12 Cookies', $data['data']['yield']); $this->assertEquals('12 Cookies', $data['data']['yield']);
$this->assertEquals('PT30M', $data['data']['duration']); $this->assertEquals('PT30M', $data['data']['duration']);
@ -599,6 +621,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('Comment text', $data['data']['content']['text']); $this->assertEquals('Comment text', $data['data']['content']['text']);
$this->assertEquals('http://source.example.com/fragment-id#comment-1000', $data['data']['url']); $this->assertEquals('http://source.example.com/fragment-id#comment-1000', $data['data']['url']);
$this->assertTrue($data['info']['found_fragment']); $this->assertTrue($data['info']['found_fragment']);
@ -626,6 +649,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$venue = $data['data']['checkin']; $venue = $data['data']['checkin'];
$this->assertEquals('checkin', $data['data']['post-type']);
$this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']); $this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']);
$this->assertEquals('DreamHost', $venue['name']); $this->assertEquals('DreamHost', $venue['name']);
$this->assertEquals('45.518716', $venue['latitude']); $this->assertEquals('45.518716', $venue['latitude']);
@ -644,6 +668,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('checkin', $data['data']['post-type']);
$venue = $data['data']['checkin']; $venue = $data['data']['checkin'];
$this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']); $this->assertEquals('https://foursquare.com/v/57104d2e498ece022e169dca', $venue['url']);
$this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']); $this->assertEquals('Homebrew Website Club!', $data['data']['content']['text']);
@ -660,6 +685,7 @@ class ParseTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true); $data = json_decode($body, true);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertEquals('http://xkcd.com/1810/', $data['data']['url']); $this->assertEquals('http://xkcd.com/1810/', $data['data']['url']);
$this->assertEquals('Chat Systems', $data['data']['name']); $this->assertEquals('Chat Systems', $data['data']['name']);
$this->assertContains('http://imgs.xkcd.com/comics/chat_systems_2x.png', $data['data']['photo']); $this->assertContains('http://imgs.xkcd.com/comics/chat_systems_2x.png', $data['data']['photo']);

+ 9
- 0
tests/TwitterTest.php View File

@ -56,6 +56,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(null, $data['code']); // no code is expected if we pass in the body $this->assertEquals(null, $data['code']); // no code is expected if we pass in the body
$this->assertEquals('https://twitter.com/pkdev/status/818913630569664512', $data['url']); $this->assertEquals('https://twitter.com/pkdev/status/818913630569664512', $data['url']);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('A tweet with a URL https://indieweb.org/ #and #some #hashtags', $data['data']['content']['text']); $this->assertEquals('A tweet with a URL https://indieweb.org/ #and #some #hashtags', $data['data']['content']['text']);
$this->assertContains('and', $data['data']['category']); $this->assertContains('and', $data['data']['category']);
$this->assertContains('some', $data['data']['category']); $this->assertContains('some', $data['data']['category']);
@ -95,6 +96,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertEquals('Tweet with a photo and a location', $data['data']['content']['text']); $this->assertEquals('Tweet with a photo and a location', $data['data']['content']['text']);
$this->assertEquals('https://pbs.twimg.com/media/C11cfRJUoAI26h9.jpg', $data['data']['photo'][0]); $this->assertEquals('https://pbs.twimg.com/media/C11cfRJUoAI26h9.jpg', $data['data']['photo'][0]);
} }
@ -105,6 +107,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertEquals('Two photos', $data['data']['content']['text']); $this->assertEquals('Two photos', $data['data']['content']['text']);
$this->assertContains('https://pbs.twimg.com/media/C11xS1wUcAAeaKF.jpg', $data['data']['photo']); $this->assertContains('https://pbs.twimg.com/media/C11xS1wUcAAeaKF.jpg', $data['data']['photo']);
$this->assertContains('https://pbs.twimg.com/media/C11wtndUoAE1WfE.jpg', $data['data']['photo']); $this->assertContains('https://pbs.twimg.com/media/C11wtndUoAE1WfE.jpg', $data['data']['photo']);
@ -116,6 +119,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('video', $data['data']['post-type']);
$this->assertEquals('Tweet with a video', $data['data']['content']['text']); $this->assertEquals('Tweet with a video', $data['data']['content']['text']);
$this->assertEquals('https://pbs.twimg.com/ext_tw_video_thumb/818913089248595970/pr/img/qVoEjF03Y41SKpNt.jpg', $data['data']['photo'][0]); $this->assertEquals('https://pbs.twimg.com/ext_tw_video_thumb/818913089248595970/pr/img/qVoEjF03Y41SKpNt.jpg', $data['data']['photo'][0]);
$this->assertEquals('https://video.twimg.com/ext_tw_video/818913089248595970/pr/vid/1280x720/qP-sDx-Q0Hs-ckVv.mp4', $data['data']['video'][0]); $this->assertEquals('https://video.twimg.com/ext_tw_video/818913089248595970/pr/vid/1280x720/qP-sDx-Q0Hs-ckVv.mp4', $data['data']['video'][0]);
@ -127,6 +131,8 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('https://twitter.com/SwiftOnSecurity/status/1018178408398966784', $data['data']['in-reply-to'][0]);
$this->assertEquals('Look! A distraction 🐁', $data['data']['content']['text']); $this->assertEquals('Look! A distraction 🐁', $data['data']['content']['text']);
$this->assertEquals('https://video.twimg.com/tweet_video/DiFOUuYV4AAUsgL.mp4', $data['data']['video'][0]); $this->assertEquals('https://video.twimg.com/tweet_video/DiFOUuYV4AAUsgL.mp4', $data['data']['video'][0]);
$this->assertEquals('https://pbs.twimg.com/tweet_video_thumb/DiFOUuYV4AAUsgL.jpg', $data['data']['photo'][0]); $this->assertEquals('https://pbs.twimg.com/tweet_video_thumb/DiFOUuYV4AAUsgL.jpg', $data['data']['photo'][0]);
@ -153,6 +159,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('repost', $data['data']['post-type']);
$this->assertArrayNotHasKey('content', $data['data']); $this->assertArrayNotHasKey('content', $data['data']);
$repostOf = 'https://twitter.com/aaronpk/status/817414679131660288'; $repostOf = 'https://twitter.com/aaronpk/status/817414679131660288';
$this->assertEquals($repostOf, $data['data']['repost-of']); $this->assertEquals($repostOf, $data['data']['repost-of']);
@ -166,6 +173,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('repost', $data['data']['post-type']);
$this->assertArrayNotHasKey('content', $data['data']); $this->assertArrayNotHasKey('content', $data['data']);
$this->assertArrayNotHasKey('photo', $data['data']); $this->assertArrayNotHasKey('photo', $data['data']);
$repostOf = 'https://twitter.com/phlaimeaux/status/819943954724556800'; $repostOf = 'https://twitter.com/phlaimeaux/status/819943954724556800';
@ -180,6 +188,7 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$data = $this->parse(['url' => $url, 'body' => $json]); $data = $this->parse(['url' => $url, 'body' => $json]);
$this->assertEquals('entry', $data['data']['type']); $this->assertEquals('entry', $data['data']['type']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('Quoted tweet with a #hashtag https://twitter.com/aaronpk/status/817414679131660288', $data['data']['content']['text']); $this->assertEquals('Quoted tweet with a #hashtag https://twitter.com/aaronpk/status/817414679131660288', $data['data']['content']['text']);
$this->assertEquals('https://twitter.com/aaronpk/status/817414679131660288', $data['data']['quotation-of']); $this->assertEquals('https://twitter.com/aaronpk/status/817414679131660288', $data['data']['quotation-of']);
$tweet = $data['data']['refs']['https://twitter.com/aaronpk/status/817414679131660288']; $tweet = $data['data']['refs']['https://twitter.com/aaronpk/status/817414679131660288'];

Loading…
Cancel
Save