1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PODEntender\Infrastructure\Domain\Model\Post; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use PODEntender\Domain\Model\FileProcessing\RssFeedConfiguration; |
7
|
|
|
use PODEntender\Infrastructure\Domain\Factory\JigsawPostFactory; |
8
|
|
|
use TightenCo\Jigsaw\IterableObject; |
9
|
|
|
use TightenCo\Jigsaw\Jigsaw; |
10
|
|
|
use TightenCo\Jigsaw\PageVariable; |
11
|
|
|
|
12
|
|
|
class JigsawPostRepositoryTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
private $jigsaw; |
15
|
|
|
|
16
|
|
|
/** @var JigsawPostRepository */ |
17
|
|
|
private $postRepository; |
18
|
|
|
|
19
|
|
|
protected function setUp(): void |
20
|
|
|
{ |
21
|
|
|
$this->jigsaw = $this->prophesize(Jigsaw::class); |
22
|
|
|
$rssConfiguration = $this->prophesize(RssFeedConfiguration::class); |
23
|
|
|
$rssConfiguration->explicit()->willReturn('clean'); |
24
|
|
|
|
25
|
|
|
$this->postRepository = new JigsawPostRepository( |
26
|
|
|
$this->jigsaw->reveal(), |
27
|
|
|
new JigsawPostFactory($rssConfiguration->reveal()) |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private function buildNewPage( |
32
|
|
|
string $postDate, |
33
|
|
|
?string $category = 'default', |
34
|
|
|
?bool $hasAudio = false |
35
|
|
|
): PageVariable |
36
|
|
|
{ |
37
|
|
|
return new PageVariable([ |
38
|
|
|
'extends' => '_layouts/test-base', |
39
|
|
|
'postDate' => strtotime($postDate), |
40
|
|
|
'category' => $category, |
41
|
|
|
'date' => strtotime($postDate), |
42
|
|
|
'episode' => [ |
43
|
|
|
'title' => '', |
44
|
|
|
'description' => '', |
45
|
|
|
'author' => '', |
46
|
|
|
'date' => strtotime($postDate), |
47
|
|
|
'audioUrl' => $hasAudio ? $postDate . '.mp3' : null, |
48
|
|
|
'cover' => [ |
49
|
|
|
'url' => '', |
50
|
|
|
], |
51
|
|
|
], |
52
|
|
|
'_meta' => new IterableObject([ |
53
|
|
|
'baseUrl' => 'tmp://test.env', |
54
|
|
|
'category' => $category, |
55
|
|
|
'content' => 'dummy content', |
56
|
|
|
'collectionName' => 'episodes', |
57
|
|
|
'url' => '/test/' . $postDate . '.html', |
58
|
|
|
'filename' => 'test/filename/' . $postDate . '.md', |
59
|
|
|
]), |
60
|
|
|
]); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testLatestPost(): void |
64
|
|
|
{ |
65
|
|
|
$this->jigsaw->getCollection('episodes')->willReturn(new PageVariable([ |
66
|
|
|
$this->buildNewPage('2019-04-18'), |
67
|
|
|
$this->buildNewPage('2019-04-28'), |
68
|
|
|
$this->buildNewPage('2019-04-08'), |
69
|
|
|
])); |
70
|
|
|
|
71
|
|
|
$latestPost = $this->postRepository->latestPost(); |
72
|
|
|
|
73
|
|
|
$this->assertEquals('2019-04-28', $latestPost->createdAt()->format('Y-m-d')); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testLatestPosts(): void |
77
|
|
|
{ |
78
|
|
|
$this->jigsaw->getCollection('episodes')->willReturn(new PageVariable([ |
79
|
|
|
$this->buildNewPage('2019-04-01'), |
80
|
|
|
$this->buildNewPage('2019-04-18'), |
81
|
|
|
$this->buildNewPage('2019-04-08'), |
82
|
|
|
$this->buildNewPage('2019-04-28'), |
83
|
|
|
])); |
84
|
|
|
|
85
|
|
|
$latestPosts = $this->postRepository->latestPosts(2); |
86
|
|
|
|
87
|
|
|
$this->assertCount(2, $latestPosts); |
88
|
|
|
$this->assertEquals('2019-04-28', $latestPosts->first()->createdAt()->format('Y-m-d')); |
89
|
|
|
$this->assertEquals('2019-04-18', $latestPosts->last()->createdAt()->format('Y-m-d')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testByCategory(): void |
93
|
|
|
{ |
94
|
|
|
$this->jigsaw->getCollection('episodes')->willReturn(new PageVariable([ |
95
|
|
|
$this->buildNewPage('2019-04-01', 'news'), |
96
|
|
|
$this->buildNewPage('2019-04-08', 'news'), |
97
|
|
|
$this->buildNewPage('2019-04-18', 'drops'), |
98
|
|
|
$this->buildNewPage('2019-04-28', 'drops'), |
99
|
|
|
])); |
100
|
|
|
|
101
|
|
|
$news = $this->postRepository->byCategory('news'); |
102
|
|
|
|
103
|
|
|
$this->assertCount(2, $news); |
104
|
|
|
$this->assertEquals('2019-04-01', $news->first()->createdAt()->format('Y-m-d')); |
105
|
|
|
$this->assertEquals('2019-04-08', $news->last()->createdAt()->format('Y-m-d')); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testWithAudio(): void |
109
|
|
|
{ |
110
|
|
|
$this->jigsaw->getCollection('episodes')->willReturn(new PageVariable([ |
111
|
|
|
$this->buildNewPage('2019-04-01', 'default', true), |
112
|
|
|
$this->buildNewPage('2019-04-08', 'default', false), |
113
|
|
|
$this->buildNewPage('2019-04-18', 'default', false), |
114
|
|
|
$this->buildNewPage('2019-04-28', 'default', true), |
115
|
|
|
])); |
116
|
|
|
|
117
|
|
|
$episodes = $this->postRepository->withAudio(); |
118
|
|
|
|
119
|
|
|
$this->assertCount(2, $episodes); |
120
|
|
|
$this->assertEquals('2019-04-01', $episodes->first()->createdAt()->format('Y-m-d')); |
121
|
|
|
$this->assertEquals('2019-04-28', $episodes->last()->createdAt()->format('Y-m-d')); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|