Skip to content

Commit b40ee7f

Browse files
author
Jolita Grazyte
committed
tests updated
1 parent 72a89ec commit b40ee7f

File tree

10 files changed

+83
-438
lines changed

10 files changed

+83
-438
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ build
22
composer.lock
33
docs
44
vendor
5-
.idea
5+
temp
66

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ return [
4343

4444
'feeds' => [
4545
[
46-
/**
47-
* Fill in for items a class with a method that returns a collection of items
48-
* that you want in the feed.
49-
*/
50-
'items' => '', // e.g.: 'App\Repositories\NewsItemRepository@getAllOnline'
51-
'url' => '', // here goes a feed url, on which the feeds will be shown
52-
'title' => '', // feed title in metadata
53-
'description' => '', // feed description in metadata
54-
'updated' => \Carbon\Carbon::now()->toAtomString()
46+
/**
47+
* Fill in for items a class with a method that returns a collection of items
48+
* that you want in the feed.
49+
* e.g.: 'App\Repositories\NewsItemRepository@getAllOnline'
50+
* For url fill in a url, on which the feeds will be shown.
51+
*/
52+
'items' => '',
53+
'url' => '',
54+
'title' => 'This is feed 1 from the unit tests',
55+
'description' => 'This is feed 1 from the unit tests.',
5556

5657
],
5758
],

config/laravel-feed.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
'feeds' => [
66
[
77
/**
8-
* Fill in for items a class with a method that returns a collection of items that you want in the feed.
8+
* Fill in for items a class with a method that returns a collection of items
9+
* that you want in the feed.
10+
* e.g.: 'App\Repositories\NewsItemRepository@getAllOnline'
11+
* For url fill in a url, on which the feeds will be shown.
912
*/
10-
'items' => '', // e.g.: 'App\Repositories\NewsItemRepository@getAllOnline'
11-
'url' => '', // here goes a feed url, on which the feeds will be shown.
13+
'items' => '',
14+
'url' => '',
1215
'title' => 'This is feed 1 from the unit tests',
1316
'description' => 'This is feed 1 from the unit tests.',
14-
'updated' => \Carbon\Carbon::now()->toAtomString()
15-
1617
],
1718
],
1819

resources/views/feed.blade.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
32
<feed xmlns="http://www.w3.org/2005/Atom">
4-
53
@foreach($meta as $key => $metaItem)
64
@if($key === 'link')
75
<{{ $key }} href="{{ url($metaItem) }}"></{{ $key }}>
86
@else
97
<{{ $key }}>{{ $metaItem }}</{{ $key }}>
108
@endif
11-
129
@endforeach
13-
10+
<updated></updated>
1411
@foreach($items as $item)
15-
1612
<entry>
17-
<title>
18-
{{ $item['title'] }}
19-
</title>
13+
<title>{{ $item['title'] }}</title>
2014
<link>{{ $item['link'] }}</link>
21-
22-
<id>
23-
{{ $item['id'] }}
24-
</id>
25-
15+
<id>{{ $item['id'] }}</id>
2616
<summary>
2717
{{ $item['summary'] }}
2818
</summary>
29-
3019
<updated>{{ $item['updated'] }}</updated>
31-
3220
</entry>
33-
3421
@endforeach
35-
36-
</feed>
22+
</feed>

src/Feed.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public function feed($feed) : HttpResponse
2828
$data['meta'] = [
2929
'link' => $feed['url'],
3030
'description' => $feed['description'],
31-
'title' => $feed['title'],
32-
'updated' => $feed['updated'],
31+
'title' => $feed['title']
3332
];
3433

35-
return Response::view('laravel-feed::feed', $data, 200, ['Content-Type' => 'application/atom+xml; chartset=UTF-8']);
34+
return Response::view(
35+
'laravel-feed::feed',
36+
$data, 200,
37+
['Content-Type' => 'application/atom+xml; chartset=UTF-8']
38+
);
3639
}
3740
}

tests/FeedTest.php

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Spatie\Feed\Test;
44

5-
use Illuminate\Filesystem\Filesystem as File;
6-
75
class FeedTest extends TestCase
86
{
97
/** @test */
@@ -28,17 +26,10 @@ public function a_feed_contains_meta_data()
2826
/** @test */
2927
public function a_feed_contains_xml_content()
3028
{
31-
$this->validate_xml($this->getContent());
32-
}
33-
34-
private function validate_xml($contents)
35-
{
36-
for ($i = 0; $i < count($contents); ++$i) {
37-
$file = $this->makeXmlFiles($i, $contents[$i]);
38-
$xml_reader = new \XMLReader();
39-
$xml_reader->open($file);
40-
$xml_reader->setParserProperty($xml_reader::VALIDATE, true);
41-
$this->assertTrue($xml_reader->isValid());
29+
$i=0;
30+
foreach($this->getContent() as $content){
31+
$this->assertTrue($this->validateXml($i, $content));
32+
$i++;
4233
}
4334
}
4435

@@ -53,19 +44,15 @@ public function a_feed_contains_all_selected_models()
5344
/** @test */
5445
public function all_feed_items_have_expected_data()
5546
{
56-
$this->check_if_feed_has_expected_content($this->getContent());
57-
}
58-
59-
private function check_if_feed_has_expected_content($contents)
60-
{
61-
for ($i = 0; $i < count($contents); ++$i) {
62-
$this->makeXmlFiles($i, $contents[$i]);
63-
$saved_file = app(File::class)->get('tests/xml-files/feeds_'.$i.'.xml');
64-
$file = app(File::class)->get('tests/feeds_'.$i.'.xml');
65-
$this->assertEquals($file, $saved_file);
47+
$i = 0;
48+
foreach($this->getContent() as $content){
49+
$this->assertEquals(file_get_contents('tests/stubs/feeds_' . $i . '.xml'), $content);
50+
$i++;
6651
}
6752
}
68-
private function getMetaData()
53+
54+
55+
protected function getMetaData()
6956
{
7057
return [
7158
[
@@ -81,19 +68,22 @@ private function getMetaData()
8168
];
8269
}
8370

84-
private function getContent()
71+
protected function getContent()
8572
{
8673
return [
8774
$this->call('GET', '/feed1')->getContent(),
8875
$this->call('GET', '/feed2')->getContent(),
8976
];
9077
}
9178

92-
private function makeXmlFiles($i, $content)
79+
protected function validateXml($i, $content)
9380
{
94-
$file = 'tests/feeds_'.$i.'.xml';
95-
app(File::class)->put($file, $content);
96-
97-
return $file;
81+
$file = 'tests/temp/feeds_'.$i.'.xml';
82+
file_put_contents($file, $content);
83+
$xml_reader = new \XMLReader();
84+
$xml_reader->open($file);
85+
$xml_reader->setParserProperty($xml_reader::VALIDATE, true);
86+
unlink($file);
87+
return $xml_reader->isValid();
9888
}
9989
}
Lines changed: 18 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,52 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
32
<feed xmlns="http://www.w3.org/2005/Atom">
4-
53
<link href="http://localhost/feed1"></link>
6-
7-
<description>This is feed 1 from the unit tests</description>
8-
9-
<title>Feed 1</title>
10-
11-
<updated>2016-02-29T16:06:18+00:00</updated>
12-
13-
14-
15-
<entry>
16-
<title>
17-
Ducimus ipsum consequatur vel libero debitis quis voluptatem.
18-
</title>
4+
<description>This is feed 1 from the unit tests</description>
5+
<title>Feed 1</title>
6+
<updated></updated>
7+
<entry>
8+
<title>Ducimus ipsum consequatur vel libero debitis quis voluptatem.</title>
199
<link>http://localhost/news/ducimus-ipsum-consequatur-vel-libero-debitis-quis-voluptatem</link>
20-
21-
<id>
22-
1
23-
</id>
24-
10+
<id>1</id>
2511
<summary>
2612
Officia aliquid rem repudiandae ut sed voluptatem non. Fuga libero omnis atque quam error. Iure dolorum labore ducimus temporibus.
2713
</summary>
28-
2914
<updated>2016-02-29 16:06:18</updated>
30-
3115
</entry>
32-
33-
34-
<entry>
35-
<title>
36-
Ducimus ipsum consequatur vel libero debitis quis voluptatem.
37-
</title>
16+
<entry>
17+
<title>Ducimus ipsum consequatur vel libero debitis quis voluptatem.</title>
3818
<link>http://localhost/news/ducimus-ipsum-consequatur-vel-libero-debitis-quis-voluptatem</link>
39-
40-
<id>
41-
1
42-
</id>
43-
19+
<id>1</id>
4420
<summary>
4521
Officia aliquid rem repudiandae ut sed voluptatem non. Fuga libero omnis atque quam error. Iure dolorum labore ducimus temporibus.
4622
</summary>
47-
4823
<updated>2016-02-29 16:06:18</updated>
49-
5024
</entry>
51-
52-
53-
<entry>
54-
<title>
55-
Ducimus ipsum consequatur vel libero debitis quis voluptatem.
56-
</title>
25+
<entry>
26+
<title>Ducimus ipsum consequatur vel libero debitis quis voluptatem.</title>
5727
<link>http://localhost/news/ducimus-ipsum-consequatur-vel-libero-debitis-quis-voluptatem</link>
58-
59-
<id>
60-
1
61-
</id>
62-
28+
<id>1</id>
6329
<summary>
6430
Officia aliquid rem repudiandae ut sed voluptatem non. Fuga libero omnis atque quam error. Iure dolorum labore ducimus temporibus.
6531
</summary>
66-
6732
<updated>2016-02-29 16:06:18</updated>
68-
6933
</entry>
70-
71-
72-
<entry>
73-
<title>
74-
Ducimus ipsum consequatur vel libero debitis quis voluptatem.
75-
</title>
34+
<entry>
35+
<title>Ducimus ipsum consequatur vel libero debitis quis voluptatem.</title>
7636
<link>http://localhost/news/ducimus-ipsum-consequatur-vel-libero-debitis-quis-voluptatem</link>
77-
78-
<id>
79-
1
80-
</id>
81-
37+
<id>1</id>
8238
<summary>
8339
Officia aliquid rem repudiandae ut sed voluptatem non. Fuga libero omnis atque quam error. Iure dolorum labore ducimus temporibus.
8440
</summary>
85-
8641
<updated>2016-02-29 16:06:18</updated>
87-
8842
</entry>
89-
90-
91-
<entry>
92-
<title>
93-
Ducimus ipsum consequatur vel libero debitis quis voluptatem.
94-
</title>
43+
<entry>
44+
<title>Ducimus ipsum consequatur vel libero debitis quis voluptatem.</title>
9545
<link>http://localhost/news/ducimus-ipsum-consequatur-vel-libero-debitis-quis-voluptatem</link>
96-
97-
<id>
98-
1
99-
</id>
100-
46+
<id>1</id>
10147
<summary>
10248
Officia aliquid rem repudiandae ut sed voluptatem non. Fuga libero omnis atque quam error. Iure dolorum labore ducimus temporibus.
10349
</summary>
104-
10550
<updated>2016-02-29 16:06:18</updated>
106-
10751
</entry>
108-
109-
11052
</feed>

0 commit comments

Comments
 (0)