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