|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Hyde\Publications\Testing\Feature; |
|
6
|
|
|
|
|
7
|
|
|
use Hyde\Facades\Filesystem; |
|
8
|
|
|
use Hyde\Foundation\Kernel\PageCollection; |
|
9
|
|
|
use Hyde\Framework\Factories\Concerns\CoreDataObject; |
|
10
|
|
|
use Hyde\Framework\Factories\Concerns\PageDataFactory; |
|
11
|
|
|
use Hyde\Framework\Factories\HydePageDataFactory; |
|
12
|
|
|
use Hyde\Framework\Features\Metadata\PageMetadataBag; |
|
13
|
|
|
use Hyde\Hyde; |
|
14
|
|
|
use Hyde\Markdown\Models\FrontMatter; |
|
15
|
|
|
use Hyde\Markdown\Models\Markdown; |
|
16
|
|
|
use Hyde\Publications\Models\PublicationType; |
|
17
|
|
|
use Hyde\Publications\Pages\PublicationPage; |
|
18
|
|
|
use Hyde\Support\Models\Route; |
|
19
|
|
|
use Hyde\Testing\TestCase; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @covers \Hyde\Publications\Pages\PublicationPage |
|
23
|
|
|
*/ |
|
24
|
|
|
class PublicationPageUnitTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
public function testSourceDirectory() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->assertSame( |
|
29
|
|
|
'', |
|
30
|
|
|
PublicationPage::sourceDirectory() |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testOutputDirectory() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->assertSame( |
|
37
|
|
|
'', |
|
38
|
|
|
PublicationPage::outputDirectory() |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testFileExtension() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->assertSame( |
|
45
|
|
|
'.md', |
|
46
|
|
|
PublicationPage::fileExtension() |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testSourcePath() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertSame( |
|
53
|
|
|
'hello-world.md', |
|
54
|
|
|
PublicationPage::sourcePath('hello-world') |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testOutputPath() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->assertSame( |
|
61
|
|
|
'hello-world.html', |
|
62
|
|
|
PublicationPage::outputPath('hello-world') |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function testPath() |
|
67
|
|
|
{ |
|
68
|
|
|
$this->assertSame( |
|
69
|
|
|
Hyde::path('hello-world.md'), |
|
70
|
|
|
PublicationPage::path('hello-world.md') |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testGetSourcePath() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertSame( |
|
77
|
|
|
'directory/hello-world.md', |
|
78
|
|
|
(new PublicationPage('hello-world', [], '', $this->pubType()))->getSourcePath() |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testGetOutputPath() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->assertSame( |
|
85
|
|
|
'directory/hello-world.html', |
|
86
|
|
|
(new PublicationPage('hello-world', [], '', $this->pubType()))->getOutputPath() |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testGetLink() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->assertSame( |
|
93
|
|
|
'directory/hello-world.html', |
|
94
|
|
|
(new PublicationPage('hello-world', [], '', $this->pubType()))->getLink() |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testMake() |
|
99
|
|
|
{ |
|
100
|
|
|
$this->assertEquals(PublicationPage::make(type: $this->pubType()), |
|
101
|
|
|
new PublicationPage('', [], '', $this->pubType())); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testMakeWithData() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->assertEquals( |
|
107
|
|
|
PublicationPage::make('foo', ['foo' => 'bar'], type: $this->pubType()), |
|
108
|
|
|
new PublicationPage('foo', ['foo' => 'bar'], '', $this->pubType()) |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function testShowInNavigation() |
|
113
|
|
|
{ |
|
114
|
|
|
$this->assertFalse((new PublicationPage('', [], '', $this->pubType()))->showInNavigation()); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function testNavigationMenuPriority() |
|
118
|
|
|
{ |
|
119
|
|
|
$this->assertSame(999, (new PublicationPage('', [], '', $this->pubType()))->navigationMenuPriority()); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testNavigationMenuLabel() |
|
123
|
|
|
{ |
|
124
|
|
|
$this->assertSame('Foo', (new PublicationPage('foo', [], '', $this->pubType()))->navigationMenuLabel()); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function testNavigationMenuGroup() |
|
128
|
|
|
{ |
|
129
|
|
|
$this->assertNull((new PublicationPage('foo', [], '', $this->pubType()))->navigationMenuGroup()); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function testGetBladeView() |
|
133
|
|
|
{ |
|
134
|
|
|
$this->expectException(\Error::class); |
|
135
|
|
|
$this->assertSame('', (new PublicationPage('foo', [], '', $this->pubType()))->getBladeView()); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testFiles() |
|
139
|
|
|
{ |
|
140
|
|
|
$this->assertSame([], PublicationPage::files()); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function testData() |
|
144
|
|
|
{ |
|
145
|
|
|
$this->assertSame('directory/foo', (new PublicationPage('foo', [], '', $this->pubType()))->data('identifier')); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function testGet() |
|
149
|
|
|
{ |
|
150
|
|
|
$page = new PublicationPage('foo', [], '', $this->pubType()); |
|
151
|
|
|
Hyde::pages()->put($page->getSourcePath(), $page); |
|
152
|
|
|
$this->assertSame($page, PublicationPage::get('directory/foo')); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function testParse() |
|
156
|
|
|
{ |
|
157
|
|
|
$this->directory('directory'); |
|
158
|
|
|
(new PublicationType('directory'))->save(); |
|
159
|
|
|
|
|
160
|
|
|
Filesystem::touch(PublicationPage::sourcePath('directory/foo')); |
|
161
|
|
|
$this->assertInstanceOf(PublicationPage::class, PublicationPage::parse('directory/foo')); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
public function testGetRouteKey() |
|
165
|
|
|
{ |
|
166
|
|
|
$this->assertSame('directory/foo', (new PublicationPage('foo', [], '', $this->pubType()))->getRouteKey()); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function testTitle() |
|
170
|
|
|
{ |
|
171
|
|
|
$this->assertSame('HydePHP - Foo', (new PublicationPage('foo', [], '', $this->pubType()))->title()); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function testAll() |
|
175
|
|
|
{ |
|
176
|
|
|
$this->assertInstanceOf(PageCollection::class, PublicationPage::all()); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
public function testMetadata() |
|
180
|
|
|
{ |
|
181
|
|
|
$this->assertInstanceOf(PageMetadataBag::class, |
|
182
|
|
|
(new PublicationPage('', [], '', $this->pubType()))->metadata()); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function test__construct() |
|
186
|
|
|
{ |
|
187
|
|
|
$this->assertInstanceOf(PublicationPage::class, new PublicationPage('', [], '', $this->pubType())); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function testGetRoute() |
|
191
|
|
|
{ |
|
192
|
|
|
$this->assertInstanceOf(Route::class, (new PublicationPage('', [], '', $this->pubType()))->getRoute()); |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function testGetIdentifier() |
|
196
|
|
|
{ |
|
197
|
|
|
$this->assertSame('directory/foo', (new PublicationPage('foo', [], '', $this->pubType()))->getIdentifier()); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function testHas() |
|
201
|
|
|
{ |
|
202
|
|
|
$this->assertTrue((new PublicationPage('foo', [], '', $this->pubType()))->has('identifier')); |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
public function testToCoreDataObject() |
|
206
|
|
|
{ |
|
207
|
|
|
$this->assertInstanceOf(CoreDataObject::class, |
|
208
|
|
|
(new PublicationPage('foo', [], '', $this->pubType()))->toCoreDataObject()); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
public function testCompile() |
|
212
|
|
|
{ |
|
213
|
|
|
$this->directory('directory'); |
|
214
|
|
|
Filesystem::touch('directory/detail.blade.php'); |
|
215
|
|
|
|
|
216
|
|
|
$page = new PublicationPage('foo', [], '', $this->pubType()); |
|
217
|
|
|
Hyde::shareViewData($page); |
|
218
|
|
|
$this->assertIsString(PublicationPage::class, $page->compile()); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
public function testMatter() |
|
222
|
|
|
{ |
|
223
|
|
|
$this->assertInstanceOf(FrontMatter::class, (new PublicationPage('foo', [], '', $this->pubType()))->matter()); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
public function testMarkdown() |
|
227
|
|
|
{ |
|
228
|
|
|
$this->assertInstanceOf(Markdown::class, (new PublicationPage('test-publication/foo', type: $this->pubType()))->markdown()); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
public function testSave() |
|
232
|
|
|
{ |
|
233
|
|
|
$this->directory('directory'); |
|
234
|
|
|
|
|
235
|
|
|
$page = new PublicationPage('foo', type: $this->pubType()); |
|
236
|
|
|
$this->assertSame($page, $page->save()); |
|
237
|
|
|
$this->assertFileExists(Hyde::path('directory/foo.md')); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
public function testGetType() |
|
241
|
|
|
{ |
|
242
|
|
|
$type = $this->pubType(); |
|
243
|
|
|
$this->assertInstanceOf(PublicationType::class, (new PublicationPage('foo', [], '', $type))->getType()); |
|
244
|
|
|
$this->assertSame($type, (new PublicationPage('foo', [], '', $type))->getType()); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
protected function pubType(): PublicationType |
|
248
|
|
|
{ |
|
249
|
|
|
return new PublicationType( |
|
250
|
|
|
'name', |
|
251
|
|
|
'canonicalField', |
|
252
|
|
|
'detail.blade.php', |
|
253
|
|
|
'list.blade.php', |
|
254
|
|
|
'sortField', true, 1, |
|
255
|
|
|
[], |
|
256
|
|
|
[], |
|
257
|
|
|
'directory' |
|
258
|
|
|
); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
protected function mockPageDataFactory(): PageDataFactory |
|
262
|
|
|
{ |
|
263
|
|
|
return new HydePageDataFactory(new CoreDataObject(new FrontMatter(), false, '', '', '', '', '')); |
|
264
|
|
|
} |
|
265
|
|
|
} |
|
266
|
|
|
|