Browse Source

Update all tests to support phpunit9

pull/107/head
Josemar Lohn 3 years ago
parent
commit
504f59555d
No known key found for this signature in database GPG Key ID: 441E69D80355E46F
17 changed files with 4300 additions and 3936 deletions
  1. +240
    -225
      tests/ActivityStreamsTest.php
  2. +197
    -182
      tests/AuthorTest.php
  3. +523
    -493
      tests/FeedTest.php
  4. +227
    -188
      tests/FetchTest.php
  5. +27
    -22
      tests/FetchTestDisabled.php
  6. +234
    -217
      tests/FindFeedsTest.php
  7. +132
    -124
      tests/GitHubTest.php
  8. +61
    -50
      tests/HackernewsTest.php
  9. +37
    -31
      tests/HelpersTest.php
  10. +318
    -292
      tests/InstagramTest.php
  11. +57
    -50
      tests/LibraryTest.php
  12. +42
    -36
      tests/MediaTypeTest.php
  13. +1298
    -1196
      tests/ParseTest.php
  14. +415
    -389
      tests/SanitizeTest.php
  15. +165
    -150
      tests/TokenTest.php
  16. +319
    -287
      tests/TwitterTest.php
  17. +8
    -4
      tests/bootstrap.php

+ 240
- 225
tests/ActivityStreamsTest.php View File

@ -2,230 +2,245 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ActivityStreamsTest extends PHPUnit_Framework_TestCase {
private $http;
public function setUp() {
$this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params) {
$request = new Request($params);
$response = new Response();
return $this->client->parse($request, $response);
}
public function testAuthorProfile() {
$url = 'http://activitystreams.example/aaronpk';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('card', $data['data']['type']);
$this->assertEquals('aaronpk', $data['data']['name']);
$this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['photo']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['url']);
}
public function testNoteWithTags() {
$url = 'http://activitystreams.example/note.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
$this->assertSame(['activitystreams'], $data['data']['category']);
$this->assertEquals('aaronpk', $data['data']['author']['name']);
$this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['author']['photo']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
}
public function testArticle() {
$url = 'http://activitystreams.example/article.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('article', $data['data']['post-type']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals('An Article', $data['data']['name']);
$this->assertEquals('This is the content of an ActivityStreams article', $data['data']['content']['text']);
$this->assertEquals('<p>This is the content of an <b>ActivityStreams</b> article</p>', $data['data']['content']['html']);
$this->assertEquals('aaronpk', $data['data']['author']['name']);
$this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['author']['photo']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
}
public function testPhoto() {
$url = 'http://activitystreams.example/photo.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertEquals('This is the text content of an ActivityStreams photo', $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
$this->assertSame(['activitystreams'], $data['data']['category']);
$this->assertSame(['https://aaronparecki.com/2018/06/28/26/photo.jpg'], $data['data']['photo']);
}
public function testVideo() {
$url = 'http://activitystreams.example/video.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('video', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertSame(['https://aaronparecki.com/2018/07/21/19/video.mp4'], $data['data']['video']);
}
public function testReply() {
$url = 'http://activitystreams.example/reply.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertArrayNotHasKey('category', $data['data']); // should not include the person-tag
// For now, don't fetch the reply context
$this->assertEquals(['http://activitystreams.example/note.json'], $data['data']['in-reply-to']);
}
public function testCustomEmoji() {
$url = 'http://activitystreams.example/custom-emoji.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals("https://mastodon.social/@Gargron/100465999501820229", $data['data']['url']);
$this->assertEquals('2018-07-30T22:24:54+00:00', $data['data']['published']);
$this->assertEquals(':yikes:', $data['data']['content']['text']);
$this->assertEquals('<p><img src="https://files.mastodon.social/custom_emojis/images/000/031/275/original/yikes.png" alt=":yikes:" title=":yikes:" height="24" class="xray-emoji"></p>', $data['data']['content']['html']);
$this->assertEquals('Eugen', $data['data']['author']['name']);
$this->assertEquals('Gargron', $data['data']['author']['nickname']);
$this->assertEquals('https://files.mastodon.social/accounts/avatars/000/000/001/original/eb9e00274b135808.png', $data['data']['author']['photo']);
$this->assertEquals('https://mastodon.social/@Gargron', $data['data']['author']['url']);
}
public function testRelAlternatePriority() {
$url = 'http://source.example.com/rel-alternate-as2';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('http://activitystreams.example/note.json', $data['parsed-url']);
$this->assertEquals('http://source.example.com/rel-alternate-as2', $data['url']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
$this->assertSame(['activitystreams'], $data['data']['category']);
}
public function testSensitiveContent() {
$url = 'http://activitystreams.example/sensitive.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('sensitive topic', $data['data']['summary']);
$this->assertEquals('This is the text content of a sensitive ActivityStreams note', $data['data']['content']['text']);
$this->assertArrayNotHasKey('name', $data['data']);
}
public function testRepost() {
$url = 'http://activitystreams.example/repost.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('repost', $data['data']['post-type']);
$this->assertArrayNotHasKey('content', $data['data']);
$this->assertArrayNotHasKey('name', $data['data']);
$this->assertEquals('Gargron', $data['data']['author']['nickname']);
$this->assertEquals(['http://activitystreams.example/note.json'], $data['data']['repost-of']);
$this->assertArrayHasKey('http://activitystreams.example/note.json', $data['data']['refs']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['refs']['http://activitystreams.example/note.json']['content']['text']);
}
public function testLike() {
$url = 'http://activitystreams.example/like.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('like', $data['data']['post-type']);
$this->assertArrayNotHasKey('content', $data['data']);
$this->assertArrayNotHasKey('name', $data['data']);
$this->assertEquals('Gargron', $data['data']['author']['nickname']);
$this->assertEquals(['http://activitystreams.example/note.json'], $data['data']['like-of']);
$this->assertArrayHasKey('http://activitystreams.example/note.json', $data['data']['refs']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['refs']['http://activitystreams.example/note.json']['content']['text']);
}
public function testNoteWrappedInCreate() {
$url = 'http://activitystreams.example/create.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('https://toot.cat/@jamey/100471682482196371', $data['data']['url']);
$this->assertEquals('2018-07-31T22:30:09+00:00', $data['data']['published']);
$this->assertEquals('@darius Huh, I just have never encountered anyone using the phrase generically like that.But you might consider writing IndieWeb.org-style bots (Atom+WebSub, and optionally WebMention if you want them to be interactive), and then using https://fed.brid.gy/ as an alternative to implementing ActivityPub yourself...', $data['data']['content']['text']);
$this->assertEquals('https://social.tinysubversions.com/users/darius/statuses/100471614681787834', $data['data']['in-reply-to'][0]);
$this->assertEquals('Jamey Sharp', $data['data']['author']['name']);
$this->assertEquals('https://s3-us-west-2.amazonaws.com/tootcatapril2017/accounts/avatars/000/013/259/original/c904452a8411e4f5.jpg', $data['data']['author']['photo']);
$this->assertEquals('https://toot.cat/@jamey', $data['data']['author']['url']);
}
class ActivityStreamsTest extends PHPUnit\Framework\TestCase
{
private $http;
public function setUp(): void
{
$this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params)
{
$request = new Request($params);
$response = new Response();
return $this->client->parse($request, $response);
}
public function testAuthorProfile()
{
$url = 'http://activitystreams.example/aaronpk';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('card', $data['data']['type']);
$this->assertEquals('aaronpk', $data['data']['name']);
$this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['photo']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['url']);
}
public function testNoteWithTags()
{
$url = 'http://activitystreams.example/note.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
$this->assertSame(['activitystreams'], $data['data']['category']);
$this->assertEquals('aaronpk', $data['data']['author']['name']);
$this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['author']['photo']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
}
public function testArticle()
{
$url = 'http://activitystreams.example/article.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('article', $data['data']['post-type']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals('An Article', $data['data']['name']);
$this->assertEquals('This is the content of an ActivityStreams article', $data['data']['content']['text']);
$this->assertEquals('<p>This is the content of an <b>ActivityStreams</b> article</p>', $data['data']['content']['html']);
$this->assertEquals('aaronpk', $data['data']['author']['name']);
$this->assertEquals('https://aaronparecki.com/images/profile.jpg', $data['data']['author']['photo']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
}
public function testPhoto()
{
$url = 'http://activitystreams.example/photo.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals($url, $data['data']['url']);
$this->assertEquals('photo', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertEquals('This is the text content of an ActivityStreams photo', $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
$this->assertSame(['activitystreams'], $data['data']['category']);
$this->assertSame(['https://aaronparecki.com/2018/06/28/26/photo.jpg'], $data['data']['photo']);
}
public function testVideo()
{
$url = 'http://activitystreams.example/video.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('video', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertSame(['https://aaronparecki.com/2018/07/21/19/video.mp4'], $data['data']['video']);
}
public function testReply()
{
$url = 'http://activitystreams.example/reply.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertArrayNotHasKey('category', $data['data']); // should not include the person-tag
// For now, don't fetch the reply context
$this->assertEquals(['http://activitystreams.example/note.json'], $data['data']['in-reply-to']);
}
public function testCustomEmoji()
{
$url = 'http://activitystreams.example/custom-emoji.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals("https://mastodon.social/@Gargron/100465999501820229", $data['data']['url']);
$this->assertEquals('2018-07-30T22:24:54+00:00', $data['data']['published']);
$this->assertEquals(':yikes:', $data['data']['content']['text']);
$this->assertEquals('<p><img src="https://files.mastodon.social/custom_emojis/images/000/031/275/original/yikes.png" alt=":yikes:" title=":yikes:" height="24" class="xray-emoji"></p>', $data['data']['content']['html']);
$this->assertEquals('Eugen', $data['data']['author']['name']);
$this->assertEquals('Gargron', $data['data']['author']['nickname']);
$this->assertEquals('https://files.mastodon.social/accounts/avatars/000/000/001/original/eb9e00274b135808.png', $data['data']['author']['photo']);
$this->assertEquals('https://mastodon.social/@Gargron', $data['data']['author']['url']);
}
public function testRelAlternatePriority()
{
$url = 'http://source.example.com/rel-alternate-as2';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('http://activitystreams.example/note.json', $data['parsed-url']);
$this->assertEquals('http://source.example.com/rel-alternate-as2', $data['url']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('2018-07-12T13:02:04-07:00', $data['data']['published']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['content']['text']);
$this->assertArrayNotHasKey('html', $data['data']['content']);
$this->assertSame(['activitystreams'], $data['data']['category']);
}
public function testSensitiveContent()
{
$url = 'http://activitystreams.example/sensitive.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('note', $data['data']['post-type']);
$this->assertEquals('sensitive topic', $data['data']['summary']);
$this->assertEquals('This is the text content of a sensitive ActivityStreams note', $data['data']['content']['text']);
$this->assertArrayNotHasKey('name', $data['data']);
}
public function testRepost()
{
$url = 'http://activitystreams.example/repost.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('repost', $data['data']['post-type']);
$this->assertArrayNotHasKey('content', $data['data']);
$this->assertArrayNotHasKey('name', $data['data']);
$this->assertEquals('Gargron', $data['data']['author']['nickname']);
$this->assertEquals(['http://activitystreams.example/note.json'], $data['data']['repost-of']);
$this->assertArrayHasKey('http://activitystreams.example/note.json', $data['data']['refs']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['refs']['http://activitystreams.example/note.json']['content']['text']);
}
public function testLike()
{
$url = 'http://activitystreams.example/like.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('like', $data['data']['post-type']);
$this->assertArrayNotHasKey('content', $data['data']);
$this->assertArrayNotHasKey('name', $data['data']);
$this->assertEquals('Gargron', $data['data']['author']['nickname']);
$this->assertEquals(['http://activitystreams.example/note.json'], $data['data']['like-of']);
$this->assertArrayHasKey('http://activitystreams.example/note.json', $data['data']['refs']);
$this->assertEquals('This is the text content of an ActivityStreams note', $data['data']['refs']['http://activitystreams.example/note.json']['content']['text']);
}
public function testNoteWrappedInCreate()
{
$url = 'http://activitystreams.example/create.json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body, true);
$this->assertEquals('activity+json', $data['source-format']);
$this->assertEquals('reply', $data['data']['post-type']);
$this->assertEquals('https://toot.cat/@jamey/100471682482196371', $data['data']['url']);
$this->assertEquals('2018-07-31T22:30:09+00:00', $data['data']['published']);
$this->assertEquals('@darius Huh, I just have never encountered anyone using the phrase generically like that.But you might consider writing IndieWeb.org-style bots (Atom+WebSub, and optionally WebMention if you want them to be interactive), and then using https://fed.brid.gy/ as an alternative to implementing ActivityPub yourself...', $data['data']['content']['text']);
$this->assertEquals('https://social.tinysubversions.com/users/darius/statuses/100471614681787834', $data['data']['in-reply-to'][0]);
$this->assertEquals('Jamey Sharp', $data['data']['author']['name']);
$this->assertEquals('https://s3-us-west-2.amazonaws.com/tootcatapril2017/accounts/avatars/000/013/259/original/c904452a8411e4f5.jpg', $data['data']['author']['photo']);
$this->assertEquals('https://toot.cat/@jamey', $data['data']['author']['url']);
}
}

+ 197
- 182
tests/AuthorTest.php View File

@ -2,186 +2,201 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class AuthorTest extends PHPUnit_Framework_TestCase {
private $http;
public function setUp() {
$this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params) {
$request = new Request($params);
$response = new Response();
return $this->client->parse($request, $response);
}
public function testHEntryAuthorIsName() {
$url = 'http://author.example.com/h-entry-author-is-name';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$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);
}
public function testHEntryAuthorIsRelLinkToHCardOnPage() {
$url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-on-page';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsRelLinkToHCardWithRelMe() {
$url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-rel-me';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-rel-me', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsRelLinkToHCardWithUrlUid() {
$url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-url-uid';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-url-uid', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsUrlToHCardOnPage() {
$url = 'http://author.example.com/h-entry-author-is-url-to-h-card-on-page';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsUrlToHCardWithMultipleLinks() {
$url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-with-multiple-urls', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsUrlToHCardWithNoURL() {
$url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-no-url';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-no-url', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryHasHCardAndUrlAuthor() {
$url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryHasHCardAuthor() {
$url = 'http://author.example.com/h-entry-has-h-card-author';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testPageIsHCard() {
$url = 'http://author.example.com/about';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('card', $data->data->type);
$this->assertEquals('http://author.example.com/about', $data->data->url);
$this->assertEquals('Author Full Name', $data->data->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
}
public function testPageIsHCardWithNoURL() {
$url = 'http://author.example.com/about-no-url';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('card', $data->data->type);
$this->assertEquals('Author Full Name', $data->data->name);
$this->assertEquals($url, $data->data->url);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
}
public function testHEntryAuthorIs0() {
$url = 'http://author.example.com/author-name-is-0';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('card', $data->data->type);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
$this->assertEquals('0', $data->data->name);
}
/*
public function testHFeedHasHCardAuthor() {
class AuthorTest extends PHPUnit\Framework\TestCase
{
private $http;
public function setUp(): void
{
$this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params)
{
$request = new Request($params);
$response = new Response();
return $this->client->parse($request, $response);
}
public function testHEntryAuthorIsName()
{
$url = 'http://author.example.com/h-entry-author-is-name';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$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);
}
public function testHEntryAuthorIsRelLinkToHCardOnPage()
{
$url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-on-page';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsRelLinkToHCardWithRelMe()
{
$url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-rel-me';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-rel-me', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsRelLinkToHCardWithUrlUid()
{
$url = 'http://author.example.com/h-entry-author-is-rel-link-to-h-card-with-url-uid';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-url-uid', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsUrlToHCardOnPage()
{
$url = 'http://author.example.com/h-entry-author-is-url-to-h-card-on-page';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsUrlToHCardWithMultipleLinks()
{
$url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-multiple-links';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-with-multiple-urls', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryAuthorIsUrlToHCardWithNoURL()
{
$url = 'http://author.example.com/h-entry-author-is-url-to-h-card-with-no-url';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about-no-url', $data->data->author->url);
$this->assertEquals('Author Full Name', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryHasHCardAndUrlAuthor()
{
$url = 'http://author.example.com/h-entry-has-h-card-and-url-author';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testHEntryHasHCardAuthor()
{
$url = 'http://author.example.com/h-entry-has-h-card-author';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
public function testPageIsHCard()
{
$url = 'http://author.example.com/about';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('card', $data->data->type);
$this->assertEquals('http://author.example.com/about', $data->data->url);
$this->assertEquals('Author Full Name', $data->data->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
}
public function testPageIsHCardWithNoURL()
{
$url = 'http://author.example.com/about-no-url';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('card', $data->data->type);
$this->assertEquals('Author Full Name', $data->data->name);
$this->assertEquals($url, $data->data->url);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
}
public function testHEntryAuthorIs0()
{
$url = 'http://author.example.com/author-name-is-0';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertEquals('card', $data->data->type);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->photo);
$this->assertEquals('0', $data->data->name);
}
/*
public function testHFeedHasHCardAuthor() {
$url = 'http://author.example.com/h-feed-has-h-card-author';
$response = $this->parse(['url' => $url]);
@ -192,7 +207,7 @@ class AuthorTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('http://author.example.com/about', $data->data->author->url);
$this->assertEquals('Author', $data->data->author->name);
$this->assertEquals('http://author.example.com/photo.jpg', $data->data->author->photo);
}
*/
}
*/
}

+ 523
- 493
tests/FeedTest.php
File diff suppressed because it is too large
View File


+ 227
- 188
tests/FetchTest.php View File

@ -2,192 +2,231 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FetchTest extends PHPUnit_Framework_TestCase {
private $http;
public function setUp() {
$this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params) {
$request = new Request($params);
$response = new Response();
return $this->client->parse($request, $response);
}
public function testRedirectLimit() {
$url = 'http://redirect.example.com/3';
$response = $this->parse([
'url' => $url,
'max_redirects' => 1
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('too_many_redirects', $data->error);
$url = 'http://redirect.example.com/2';
$response = $this->parse([
'url' => $url,
'max_redirects' => 1
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('too_many_redirects', $data->error);
}
public function testRedirectUnderLimit() {
$url = 'http://redirect.example.com/2';
$response = $this->parse([
'url' => $url,
'max_redirects' => 2
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(200, $data->code);
$this->assertEquals('The Final Page', $data->data->name);
$this->assertEquals('http://redirect.example.com/0', $data->url);
}
public function testReturnsHTTPStatusCode() {
$url = 'http://redirect.example.com/code-418';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals($url, $data->url);
$this->assertEquals(418, $data->code);
}
public function testReturnsForbidden() {
$url = 'http://redirect.example.com/code-403';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('forbidden', $data->error);
$this->assertEquals($url, $data->url);
$this->assertEquals(403, $data->code);
}
public function testReturnsUnauthorized() {
$url = 'http://redirect.example.com/code-401';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('unauthorized', $data->error);
$this->assertEquals($url, $data->url);
$this->assertEquals(401, $data->code);
}
public function testDeleted() {
$url = 'http://source.example.com/deleted-gone';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('This post has been deleted.', $data->data->content->text);
}
public function testDeletedEmptyBody() {
$url = 'http://source.example.com/deleted-empty';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('unknown', $data->data->type);
}
public function testDeletedTargetProvided() {
$url = 'http://source.example.com/deleted-gone';
$response = $this->parse([
'url' => $url,
'target' => 'http://example.com/'
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('no_link_found', $data->error);
$this->assertEquals(410, $data->code);
}
public function testMetaEquivDeleted() {
$url = 'http://source.example.com/deleted';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('This post has been deleted.', $data->data->content->text);
}
public function testMetaEquivDeletedCaps() {
$url = 'http://source.example.com/deleted-2';
$response = $this->parse([
'url' => $url
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('This post has been deleted.', $data->data->content->text);
}
public function testMetaEquivDeletedTargetProvided() {
// for example when verifying a webmention but the source was replaced with an html deleted page
$url = 'http://source.example.com/deleted';
$response = $this->parse([
'url' => $url,
'target' => 'http://example.com/'
]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('no_link_found', $data->error);
$this->assertEquals(410, $data->code);
}
class FetchTest extends PHPUnit\Framework\TestCase
{
private $http;
public function setUp(): void
{
$this->client = new Parse();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params)
{
$request = new Request($params);
$response = new Response();
return $this->client->parse($request, $response);
}
public function testRedirectLimit()
{
$url = 'http://redirect.example.com/3';
$response = $this->parse(
[
'url' => $url,
'max_redirects' => 1
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('too_many_redirects', $data->error);
$url = 'http://redirect.example.com/2';
$response = $this->parse(
[
'url' => $url,
'max_redirects' => 1
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('too_many_redirects', $data->error);
}
public function testRedirectUnderLimit()
{
$url = 'http://redirect.example.com/2';
$response = $this->parse(
[
'url' => $url,
'max_redirects' => 2
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(200, $data->code);
$this->assertEquals('The Final Page', $data->data->name);
$this->assertEquals('http://redirect.example.com/0', $data->url);
}
public function testReturnsHTTPStatusCode()
{
$url = 'http://redirect.example.com/code-418';
$response = $this->parse(
[
'url' => $url
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals($url, $data->url);
$this->assertEquals(418, $data->code);
}
public function testReturnsForbidden()
{
$url = 'http://redirect.example.com/code-403';
$response = $this->parse(
[
'url' => $url
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('forbidden', $data->error);
$this->assertEquals($url, $data->url);
$this->assertEquals(403, $data->code);
}
public function testReturnsUnauthorized()
{
$url = 'http://redirect.example.com/code-401';
$response = $this->parse(
[
'url' => $url
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('unauthorized', $data->error);
$this->assertEquals($url, $data->url);
$this->assertEquals(401, $data->code);
}
public function testDeleted()
{
$url = 'http://source.example.com/deleted-gone';
$response = $this->parse(
[
'url' => $url
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('This post has been deleted.', $data->data->content->text);
}
public function testDeletedEmptyBody()
{
$url = 'http://source.example.com/deleted-empty';
$response = $this->parse(
[
'url' => $url
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('unknown', $data->data->type);
}
public function testDeletedTargetProvided()
{
$url = 'http://source.example.com/deleted-gone';
$response = $this->parse(
[
'url' => $url,
'target' => 'http://example.com/'
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('no_link_found', $data->error);
$this->assertEquals(410, $data->code);
}
public function testMetaEquivDeleted()
{
$url = 'http://source.example.com/deleted';
$response = $this->parse(
[
'url' => $url
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('This post has been deleted.', $data->data->content->text);
}
public function testMetaEquivDeletedCaps()
{
$url = 'http://source.example.com/deleted-2';
$response = $this->parse(
[
'url' => $url
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectNotHasAttribute('error', $data);
$this->assertEquals(410, $data->code);
$this->assertEquals('This post has been deleted.', $data->data->content->text);
}
public function testMetaEquivDeletedTargetProvided()
{
// for example when verifying a webmention but the source was replaced with an html deleted page
$url = 'http://source.example.com/deleted';
$response = $this->parse(
[
'url' => $url,
'target' => 'http://example.com/'
]
);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body);
$this->assertObjectHasAttribute('error', $data);
$this->assertEquals('no_link_found', $data->error);
$this->assertEquals(410, $data->code);
}
}

+ 27
- 22
tests/FetchTestDisabled.php View File

@ -2,32 +2,37 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FetchTest extends PHPUnit_Framework_TestCase {
class FetchTest extends PHPUnit\Framework\TestCase
{
private $http;
private $http;
public function setUp() {
$this->http = new p3k\HTTP();
}
public function setUp(): void
{
$this->http = new p3k\HTTP();
}
public function testTimeout() {
$url = 'https://nghttp2.org/httpbin/delay/2';
$this->http->timeout = 1;
$response = $this->http->get($url);
$this->assertEquals('timeout', $response['error']);
}
public function testTimeout()
{
$url = 'https://nghttp2.org/httpbin/delay/2';
$this->http->timeout = 1;
$response = $this->http->get($url);
$this->assertEquals('timeout', $response['error']);
}
public function testRedirectLimit() {
$url = 'https://nghttp2.org/httpbin/redirect/3';
$this->http->max_redirects = 1;
$response = $this->http->get($url);
$this->assertEquals('too_many_redirects', $response['error']);
}
public function testRedirectLimit()
{
$url = 'https://nghttp2.org/httpbin/redirect/3';
$this->http->max_redirects = 1;
$response = $this->http->get($url);
$this->assertEquals('too_many_redirects', $response['error']);
}
public function testNoError() {
$url = 'https://nghttp2.org/httpbin/ip';
$response = $this->http->get($url);
$this->assertEquals('', $response['error']);
}
public function testNoError()
{
$url = 'https://nghttp2.org/httpbin/ip';
$response = $this->http->get($url);
$this->assertEquals('', $response['error']);
}
}

+ 234
- 217
tests/FindFeedsTest.php View File

@ -2,221 +2,238 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FindFeedsTest extends PHPUnit_Framework_TestCase {
private $http;
public function setUp() {
$this->client = new Feeds();
$this->client->http = new p3k\HTTP\Test(dirname(__FILE__).'/data/');
$this->client->mc = null;
}
private function parse($params) {
$request = new Request($params);
$response = new Response();
return $this->client->find($request, $response);
}
// h-feed with no alternates
public function testMf2HFeed() {
$url = 'http://feed.example.com/h-feed-with-child-author';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/h-feed-with-child-author', $feeds[0]->url);
$this->assertEquals('microformats', $feeds[0]->type);
}
// h-feed that links to Atom alternate
public function testMf2WithAtomAlternate() {
$url = 'http://feed.example.com/h-feed-with-atom-alternate';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(2, count($feeds));
// Should rank h-feed above Atom
$this->assertEquals('http://feed.example.com/h-feed-with-atom-alternate', $feeds[0]->url);
$this->assertEquals('microformats', $feeds[0]->type);
$this->assertEquals('http://feed.example.com/atom', $feeds[1]->url);
$this->assertEquals('atom', $feeds[1]->type);
}
// h-feed that links to RSS alternate
public function testMf2WithRSSAlternate() {
$url = 'http://feed.example.com/h-feed-with-rss-alternate';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(2, count($feeds));
// Should rank JSONFeed above Atom
$this->assertEquals('http://feed.example.com/h-feed-with-rss-alternate', $feeds[0]->url);
$this->assertEquals('microformats', $feeds[0]->type);
$this->assertEquals('http://feed.example.com/podcast.xml', $feeds[1]->url);
$this->assertEquals('rss', $feeds[1]->type);
}
// No mf2 but links to Atom alternate
public function testNoMf2() {
$url = 'http://feed.example.com/html-with-atom-alternate';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/atom', $feeds[0]->url);
$this->assertEquals('atom', $feeds[0]->type);
}
public function testNoMf2WithJSONAndAtom() {
$url = 'http://feed.example.com/html-with-json-and-atom';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(2, count($feeds));
// Should rank JSONFeed above Atom
$this->assertEquals('http://feed.example.com/jsonfeed', $feeds[0]->url);
$this->assertEquals('jsonfeed', $feeds[0]->type);
$this->assertEquals('http://feed.example.com/atom', $feeds[1]->url);
$this->assertEquals('atom', $feeds[1]->type);
}
// input URL is an Atom feed
public function testInputIsAtom() {
$url = 'http://feed.example.com/atom';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/atom', $feeds[0]->url);
$this->assertEquals('atom', $feeds[0]->type);
}
// input URL is an RSS feed with xml content type
public function testInputIsRSSWithXML() {
$url = 'http://feed.example.com/rss-xml-content-type';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/rss-xml-content-type', $feeds[0]->url);
$this->assertEquals('rss', $feeds[0]->type);
}
// input URL redirects to an Atom feed
public function testInputIsRedirectToAtom() {
$url = 'http://feed.example.com/redirect-to-atom';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/atom', $feeds[0]->url);
$this->assertEquals('atom', $feeds[0]->type);
}
// input URL is a temporary redirect to another page.
// report the original input URL
public function testInputIsTemporaryRedirect() {
$url = 'http://feed.example.com/temporary-redirect';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/temporary-redirect', $feeds[0]->url);
$this->assertEquals('microformats', $feeds[0]->type);
}
public function testInputIsPermanentRedirect() {
$url = 'http://feed.example.com/permanent-redirect';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/permanent-redirect-target', $feeds[0]->url);
$this->assertEquals('microformats', $feeds[0]->type);
}
// input URL is an RSS feed
public function testInputIsRSS() {
$url = 'http://feed.example.com/rss';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/rss', $feeds[0]->url);
$this->assertEquals('rss', $feeds[0]->type);
}
// input URL is a JSON feed
public function testInputIsJSONFeed() {
$url = 'http://feed.example.com/jsonfeed';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));
$this->assertEquals('http://feed.example.com/jsonfeed', $feeds[0]->url);
$this->assertEquals('jsonfeed', $feeds[0]->type);
}
public function testInputIsMicroformats2JSON() {
$url = 'http://feed.example.com/microformats2-json';
$response = $this->parse(['url' => $url]);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$feeds = json_decode($body)->feeds;
$this->assertEquals(1, count($feeds));