Skip to content

Commit

Permalink
Extract JSON test data into fixture files
Browse files Browse the repository at this point in the history
  • Loading branch information
jdecool committed May 29, 2017
1 parent 2c2a6f9 commit d030a50
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 70 deletions.
20 changes: 20 additions & 0 deletions test/Fixtures/microblog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": "https://jsonfeed.org/version/1",
"user_comment": "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json",
"title": "Brent Simmons’s Microblog",
"home_page_url": "https://example.org/",
"feed_url": "https://example.org/feed.json",
"author": {
"name": "Brent Simmons",
"url": "http://example.org/",
"avatar": "https://example.org/avatar.png"
},
"items": [
{
"id": "2347259",
"url": "https://example.org/2347259",
"content_text": "Cats are neat. https://example.org/cats",
"date_published": "2016-02-09T14:22:00+02:00"
}
]
}
26 changes: 26 additions & 0 deletions test/Fixtures/podcast.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "https://jsonfeed.org/version/1",
"user_comment": "This is a podcast feed. You can add this feed to your podcast client using the following URL: http://therecord.co/feed.json",
"title": "The Record",
"home_page_url": "http://therecord.co/",
"feed_url": "http://therecord.co/feed.json",
"items": [
{
"id": "http://therecord.co/chris-parrish",
"title": "Special #1 - Chris Parrish",
"url": "http://therecord.co/chris-parrish",
"content_text": "Chris has worked at Adobe and as a founder of Rogue Sheep, which won an Apple Design Award for Postage. Chris’s new company is Aged & Distilled with Guy English — which shipped Napkin, a Mac app for visual collaboration. Chris is also the co-host of The Record. He lives on Bainbridge Island, a quick ferry ride from Seattle.",
"content_html": "Chris has worked at <a href=\"http://adobe.com/\">Adobe</a> and as a founder of Rogue Sheep, which won an Apple Design Award for Postage. Chris’s new company is Aged & Distilled with Guy English — which shipped <a href=\"http://aged-and-distilled.com/napkin/\">Napkin</a>, a Mac app for visual collaboration. Chris is also the co-host of The Record. He lives on <a href=\"http://www.ci.bainbridge-isl.wa.us/\">Bainbridge Island</a>, a quick ferry ride from Seattle.",
"summary": "Brent interviews Chris Parrish, co-host of The Record and one-half of Aged & Distilled.",
"date_published": "2014-05-09T14:04:00-07:00",
"attachments": [
{
"url": "http://therecord.co/downloads/The-Record-sp1e1-ChrisParrish.m4a",
"mime_type": "audio/x-m4a",
"size_in_bytes": 89970236,
"duration_in_seconds": 6629
}
]
}
]
}
18 changes: 18 additions & 0 deletions test/Fixtures/simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "https://jsonfeed.org/version/1",
"title": "My Example Feed",
"home_page_url": "https://example.org/",
"feed_url": "https://example.org/feed.json",
"items": [
{
"id": "2",
"content_text": "This is a second item.",
"url": "https://example.org/second-item"
},
{
"id": "1",
"content_html": "<p>Hello, world!</p>",
"url": "https://example.org/initial-post"
}
]
}
85 changes: 15 additions & 70 deletions test/Writer/Version1/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

class RendererTest extends TestCase
{
private static $fixturesPath;

public static function setUpBeforeClass()
{
self::$fixturesPath = realpath(__DIR__.'/../../Fixtures');
}

public function testSimpleFeed()
{
$feed = new Feed('My Example Feed');
Expand All @@ -29,26 +36,7 @@ public function testSimpleFeed()
$item1->setUrl('https://example.org/initial-post');
$feed->addItem($item1);

$expected = <<<JSON
{
"version": "https://jsonfeed.org/version/1",
"title": "My Example Feed",
"home_page_url": "https://example.org/",
"feed_url": "https://example.org/feed.json",
"items": [
{
"id": "2",
"content_text": "This is a second item.",
"url": "https://example.org/second-item"
},
{
"id": "1",
"content_html": "<p>Hello, world!</p>",
"url": "https://example.org/initial-post"
}
]
}
JSON;
$expected = $this->getFixtures('simple');

$render = new Renderer();
$this->assertJsonStringEqualsJsonString($expected, $render->render($feed));
Expand All @@ -75,34 +63,7 @@ public function testPodcastFeed()
$feed->setFeedUrl('http://therecord.co/feed.json');
$feed->addItem($item);

$expected = <<<JSON
{
"version": "https://jsonfeed.org/version/1",
"user_comment": "This is a podcast feed. You can add this feed to your podcast client using the following URL: http://therecord.co/feed.json",
"title": "The Record",
"home_page_url": "http://therecord.co/",
"feed_url": "http://therecord.co/feed.json",
"items": [
{
"id": "http://therecord.co/chris-parrish",
"title": "Special #1 - Chris Parrish",
"url": "http://therecord.co/chris-parrish",
"content_text": "Chris has worked at Adobe and as a founder of Rogue Sheep, which won an Apple Design Award for Postage. Chris’s new company is Aged & Distilled with Guy English — which shipped Napkin, a Mac app for visual collaboration. Chris is also the co-host of The Record. He lives on Bainbridge Island, a quick ferry ride from Seattle.",
"content_html": "Chris has worked at <a href=\"http://adobe.com/\">Adobe</a> and as a founder of Rogue Sheep, which won an Apple Design Award for Postage. Chris’s new company is Aged & Distilled with Guy English — which shipped <a href=\"http://aged-and-distilled.com/napkin/\">Napkin</a>, a Mac app for visual collaboration. Chris is also the co-host of The Record. He lives on <a href=\"http://www.ci.bainbridge-isl.wa.us/\">Bainbridge Island</a>, a quick ferry ride from Seattle.",
"summary": "Brent interviews Chris Parrish, co-host of The Record and one-half of Aged & Distilled.",
"date_published": "2014-05-09T14:04:00-07:00",
"attachments": [
{
"url": "http://therecord.co/downloads/The-Record-sp1e1-ChrisParrish.m4a",
"mime_type": "audio/x-m4a",
"size_in_bytes": 89970236,
"duration_in_seconds": 6629
}
]
}
]
}
JSON;
$expected = $this->getFixtures('podcast');

$render = new Renderer();
$this->assertJsonStringEqualsJsonString($expected, $render->render($feed));
Expand All @@ -126,30 +87,14 @@ public function testMicroblogFeed()
$feed->setAuthor($author);
$feed->addItem($item);

$expected = <<<JSON
{
"version": "https://jsonfeed.org/version/1",
"user_comment": "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json",
"title": "Brent Simmons’s Microblog",
"home_page_url": "https://example.org/",
"feed_url": "https://example.org/feed.json",
"author": {
"name": "Brent Simmons",
"url": "http://example.org/",
"avatar": "https://example.org/avatar.png"
},
"items": [
{
"id": "2347259",
"url": "https://example.org/2347259",
"content_text": "Cats are neat. https://example.org/cats",
"date_published": "2016-02-09T14:22:00+02:00"
}
]
}
JSON;
$expected = $this->getFixtures('microblog');

$render = new Renderer();
$this->assertJsonStringEqualsJsonString($expected, $render->render($feed));
}

private function getFixtures($name)
{
return file_get_contents(self::$fixturesPath.'/'.$name.'.json');
}
}

0 comments on commit d030a50

Please sign in to comment.