1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Unit\Foundation; |
4
|
|
|
|
5
|
|
|
use Hyde\Framework\Hyde; |
6
|
|
|
use Hyde\Framework\Models\Pages\BladePage; |
7
|
|
|
use Hyde\Framework\Models\Pages\DocumentationPage; |
8
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPage; |
9
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPost; |
10
|
|
|
use Hyde\Testing\TestCase; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @covers \Hyde\Framework\HydeKernel |
14
|
|
|
* @covers \Hyde\Framework\Foundation\Filesystem |
15
|
|
|
* |
16
|
|
|
* @todo Merge into FilesystemTest |
17
|
|
|
*/ |
18
|
|
|
class FluentFilesystemModelPathHelpersTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public function test_get_model_source_path_method_returns_path_for_model_classes() |
21
|
|
|
{ |
22
|
|
|
$this->assertEquals( |
23
|
|
|
Hyde::path('_posts'), |
24
|
|
|
Hyde::getModelSourcePath(MarkdownPost::class) |
25
|
|
|
); |
26
|
|
|
|
27
|
|
|
$this->assertEquals( |
28
|
|
|
Hyde::path('_pages'), |
29
|
|
|
Hyde::getModelSourcePath(MarkdownPage::class) |
30
|
|
|
); |
31
|
|
|
|
32
|
|
|
$this->assertEquals( |
33
|
|
|
Hyde::path('_docs'), |
34
|
|
|
Hyde::getModelSourcePath(DocumentationPage::class) |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
$this->assertEquals( |
38
|
|
|
Hyde::path('_pages'), |
39
|
|
|
Hyde::getModelSourcePath(BladePage::class) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function test_get_model_source_path_method_returns_path_to_file_for_model_classes() |
44
|
|
|
{ |
45
|
|
|
$this->assertEquals( |
46
|
|
|
Hyde::path('_posts'.DIRECTORY_SEPARATOR.'foo.md'), |
47
|
|
|
Hyde::getModelSourcePath(MarkdownPost::class, 'foo.md') |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->assertEquals( |
51
|
|
|
Hyde::path('_pages'.DIRECTORY_SEPARATOR.'foo.md'), |
52
|
|
|
Hyde::getModelSourcePath(MarkdownPage::class, 'foo.md') |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
$this->assertEquals( |
56
|
|
|
Hyde::path('_docs'.DIRECTORY_SEPARATOR.'foo.md'), |
57
|
|
|
Hyde::getModelSourcePath(DocumentationPage::class, 'foo.md') |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->assertEquals( |
61
|
|
|
Hyde::path('_pages'.DIRECTORY_SEPARATOR.'foo.md'), |
62
|
|
|
Hyde::getModelSourcePath(BladePage::class, 'foo.md') |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function test_helper_for_blade_pages() |
67
|
|
|
{ |
68
|
|
|
$this->assertEquals( |
69
|
|
|
Hyde::path('_pages'), |
70
|
|
|
Hyde::getBladePagePath() |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function test_helper_for_markdown_pages() |
75
|
|
|
{ |
76
|
|
|
$this->assertEquals( |
77
|
|
|
Hyde::path('_pages'), |
78
|
|
|
Hyde::getMarkdownPagePath() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function test_helper_for_markdown_posts() |
83
|
|
|
{ |
84
|
|
|
$this->assertEquals( |
85
|
|
|
Hyde::path('_posts'), |
86
|
|
|
Hyde::getMarkdownPostPath() |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function test_helper_for_documentation_pages() |
91
|
|
|
{ |
92
|
|
|
$this->assertEquals( |
93
|
|
|
Hyde::path('_docs'), |
94
|
|
|
Hyde::getDocumentationPagePath() |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function test_helper_for_site_output_path() |
99
|
|
|
{ |
100
|
|
|
$this->assertEquals( |
101
|
|
|
Hyde::path('_site'), |
102
|
|
|
Hyde::getSiteOutputPath() |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function test_helper_for_site_output_path_returns_path_to_file_within_the_directory() |
107
|
|
|
{ |
108
|
|
|
$this->assertEquals( |
109
|
|
|
Hyde::path('_site'.DIRECTORY_SEPARATOR.'foo.html'), |
110
|
|
|
Hyde::getSiteOutputPath('foo.html') |
111
|
|
|
); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function test_get_site_output_path_returns_absolute_path() |
115
|
|
|
{ |
116
|
|
|
$this->assertEquals( |
117
|
|
|
Hyde::path('_site'), |
118
|
|
|
Hyde::getSiteOutputPath() |
119
|
|
|
); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
public function test_site_output_path_helper_ignores_trailing_slashes() |
123
|
|
|
{ |
124
|
|
|
$this->assertEquals( |
125
|
|
|
Hyde::path('_site'.DIRECTORY_SEPARATOR.'foo.html'), |
126
|
|
|
Hyde::getSiteOutputPath('/foo.html/') |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function test_path_to_relative_helper_decodes_hyde_path_into_relative() |
131
|
|
|
{ |
132
|
|
|
$s = DIRECTORY_SEPARATOR; |
133
|
|
|
$this->assertEquals('foo', Hyde::pathToRelative(Hyde::path('foo'))); |
134
|
|
|
$this->assertEquals('foo', Hyde::pathToRelative(Hyde::path('/foo/'))); |
135
|
|
|
$this->assertEquals('foo.md', Hyde::pathToRelative(Hyde::path('foo.md'))); |
136
|
|
|
$this->assertEquals("foo{$s}bar", Hyde::pathToRelative(Hyde::path("foo{$s}bar"))); |
137
|
|
|
$this->assertEquals("foo{$s}bar.md", Hyde::pathToRelative(Hyde::path("foo{$s}bar.md"))); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function test_path_to_relative_helper_does_not_modify_already_relative_paths() |
141
|
|
|
{ |
142
|
|
|
$this->assertEquals('foo', Hyde::pathToRelative('foo')); |
143
|
|
|
$this->assertEquals('foo/', Hyde::pathToRelative('foo/')); |
144
|
|
|
$this->assertEquals('../foo', Hyde::pathToRelative('../foo')); |
145
|
|
|
$this->assertEquals('../foo/', Hyde::pathToRelative('../foo/')); |
146
|
|
|
$this->assertEquals('foo.md', Hyde::pathToRelative('foo.md')); |
147
|
|
|
$this->assertEquals('foo/bar', Hyde::pathToRelative('foo/bar')); |
148
|
|
|
$this->assertEquals('foo/bar.md', Hyde::pathToRelative('foo/bar.md')); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function test_path_to_relative_helper_does_not_modify_non_project_paths() |
152
|
|
|
{ |
153
|
|
|
$testStrings = [ |
154
|
|
|
'C:\Documents\Newsletters\Summer2018.pdf', |
155
|
|
|
'\Program Files\Custom Utilities\StringFinder.exe', |
156
|
|
|
'2018\January.xlsx', |
157
|
|
|
'..\Publications\TravelBrochure.pdf', |
158
|
|
|
'C:\Projects\library\library.sln', |
159
|
|
|
'C:Projects\library\library.sln', |
160
|
|
|
'/home/seth/Pictures/penguin.jpg', |
161
|
|
|
'~/Pictures/penguin.jpg', |
162
|
|
|
]; |
163
|
|
|
|
164
|
|
|
foreach ($testStrings as $testString) { |
165
|
|
|
$this->assertEquals( |
166
|
|
|
$this->systemPath(($testString)), |
167
|
|
|
Hyde::pathToRelative( |
168
|
|
|
$this->systemPath($testString) |
169
|
|
|
) |
170
|
|
|
); |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
protected function systemPath(string $path): string |
175
|
|
|
{ |
176
|
|
|
return str_replace('/', DIRECTORY_SEPARATOR, $path); |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|