Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit d030a50

Browse files
committed
Extract JSON test data into fixture files
1 parent 2c2a6f9 commit d030a50

File tree

4 files changed

+79
-70
lines changed

4 files changed

+79
-70
lines changed

Diff for: test/Fixtures/microblog.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": "https://jsonfeed.org/version/1",
3+
"user_comment": "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json",
4+
"title": "Brent Simmons’s Microblog",
5+
"home_page_url": "https://example.org/",
6+
"feed_url": "https://example.org/feed.json",
7+
"author": {
8+
"name": "Brent Simmons",
9+
"url": "http://example.org/",
10+
"avatar": "https://example.org/avatar.png"
11+
},
12+
"items": [
13+
{
14+
"id": "2347259",
15+
"url": "https://example.org/2347259",
16+
"content_text": "Cats are neat. https://example.org/cats",
17+
"date_published": "2016-02-09T14:22:00+02:00"
18+
}
19+
]
20+
}

Diff for: test/Fixtures/podcast.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"version": "https://jsonfeed.org/version/1",
3+
"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",
4+
"title": "The Record",
5+
"home_page_url": "http://therecord.co/",
6+
"feed_url": "http://therecord.co/feed.json",
7+
"items": [
8+
{
9+
"id": "http://therecord.co/chris-parrish",
10+
"title": "Special #1 - Chris Parrish",
11+
"url": "http://therecord.co/chris-parrish",
12+
"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.",
13+
"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.",
14+
"summary": "Brent interviews Chris Parrish, co-host of The Record and one-half of Aged & Distilled.",
15+
"date_published": "2014-05-09T14:04:00-07:00",
16+
"attachments": [
17+
{
18+
"url": "http://therecord.co/downloads/The-Record-sp1e1-ChrisParrish.m4a",
19+
"mime_type": "audio/x-m4a",
20+
"size_in_bytes": 89970236,
21+
"duration_in_seconds": 6629
22+
}
23+
]
24+
}
25+
]
26+
}

Diff for: test/Fixtures/simple.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"version": "https://jsonfeed.org/version/1",
3+
"title": "My Example Feed",
4+
"home_page_url": "https://example.org/",
5+
"feed_url": "https://example.org/feed.json",
6+
"items": [
7+
{
8+
"id": "2",
9+
"content_text": "This is a second item.",
10+
"url": "https://example.org/second-item"
11+
},
12+
{
13+
"id": "1",
14+
"content_html": "<p>Hello, world!</p>",
15+
"url": "https://example.org/initial-post"
16+
}
17+
]
18+
}

Diff for: test/Writer/Version1/RendererTest.php

+15-70
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313

1414
class RendererTest extends TestCase
1515
{
16+
private static $fixturesPath;
17+
18+
public static function setUpBeforeClass()
19+
{
20+
self::$fixturesPath = realpath(__DIR__.'/../../Fixtures');
21+
}
22+
1623
public function testSimpleFeed()
1724
{
1825
$feed = new Feed('My Example Feed');
@@ -29,26 +36,7 @@ public function testSimpleFeed()
2936
$item1->setUrl('https://example.org/initial-post');
3037
$feed->addItem($item1);
3138

32-
$expected = <<<JSON
33-
{
34-
"version": "https://jsonfeed.org/version/1",
35-
"title": "My Example Feed",
36-
"home_page_url": "https://example.org/",
37-
"feed_url": "https://example.org/feed.json",
38-
"items": [
39-
{
40-
"id": "2",
41-
"content_text": "This is a second item.",
42-
"url": "https://example.org/second-item"
43-
},
44-
{
45-
"id": "1",
46-
"content_html": "<p>Hello, world!</p>",
47-
"url": "https://example.org/initial-post"
48-
}
49-
]
50-
}
51-
JSON;
39+
$expected = $this->getFixtures('simple');
5240

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

78-
$expected = <<<JSON
79-
{
80-
"version": "https://jsonfeed.org/version/1",
81-
"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",
82-
"title": "The Record",
83-
"home_page_url": "http://therecord.co/",
84-
"feed_url": "http://therecord.co/feed.json",
85-
"items": [
86-
{
87-
"id": "http://therecord.co/chris-parrish",
88-
"title": "Special #1 - Chris Parrish",
89-
"url": "http://therecord.co/chris-parrish",
90-
"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.",
91-
"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.",
92-
"summary": "Brent interviews Chris Parrish, co-host of The Record and one-half of Aged & Distilled.",
93-
"date_published": "2014-05-09T14:04:00-07:00",
94-
"attachments": [
95-
{
96-
"url": "http://therecord.co/downloads/The-Record-sp1e1-ChrisParrish.m4a",
97-
"mime_type": "audio/x-m4a",
98-
"size_in_bytes": 89970236,
99-
"duration_in_seconds": 6629
100-
}
101-
]
102-
}
103-
]
104-
}
105-
JSON;
66+
$expected = $this->getFixtures('podcast');
10667

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

129-
$expected = <<<JSON
130-
{
131-
"version": "https://jsonfeed.org/version/1",
132-
"user_comment": "This is a microblog feed. You can add this to your feed reader using the following URL: https://example.org/feed.json",
133-
"title": "Brent Simmons’s Microblog",
134-
"home_page_url": "https://example.org/",
135-
"feed_url": "https://example.org/feed.json",
136-
"author": {
137-
"name": "Brent Simmons",
138-
"url": "http://example.org/",
139-
"avatar": "https://example.org/avatar.png"
140-
},
141-
"items": [
142-
{
143-
"id": "2347259",
144-
"url": "https://example.org/2347259",
145-
"content_text": "Cats are neat. https://example.org/cats",
146-
"date_published": "2016-02-09T14:22:00+02:00"
147-
}
148-
]
149-
}
150-
JSON;
90+
$expected = $this->getFixtures('microblog');
15191

15292
$render = new Renderer();
15393
$this->assertJsonStringEqualsJsonString($expected, $render->render($feed));
15494
}
95+
96+
private function getFixtures($name)
97+
{
98+
return file_get_contents(self::$fixturesPath.'/'.$name.'.json');
99+
}
155100
}

0 commit comments

Comments
 (0)