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