|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Unit\Foundation; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Hyde; |
|
6
|
|
|
use Hyde\Testing\TestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers \Hyde\Framework\Foundation\Hyperlinks::relativeLink |
|
10
|
|
|
*/ |
|
11
|
|
|
class HyperlinkFileHelperRelativeLinkTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function test_helper_returns_string_as_is_if_current_is_not_set() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->assertEquals('foo/bar.html', Hyde::relativeLink('foo/bar.html')); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function test_helper_injects_proper_number_of_doubles_slash() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
21
|
|
|
$this->assertEquals('../foo.html', Hyde::relativeLink('foo.html')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function test_helper_injects_proper_number_of_doubles_slash_for_deeply_nested_paths() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->mockCurrentPage('foo/bar/baz/qux.html'); |
|
27
|
|
|
$this->assertEquals('../../../foo.html', Hyde::relativeLink('foo.html')); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function test_helper_handles_destination_without_file_extension() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
33
|
|
|
$this->assertEquals('../foo', Hyde::relativeLink('foo')); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function test_helper_handles_current_without_file_extension() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->mockCurrentPage('foo/bar'); |
|
39
|
|
|
$this->assertEquals('../foo.html', Hyde::relativeLink('foo.html')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function test_helper_handles_case_without_any_file_extensions() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->mockCurrentPage('foo/bar'); |
|
45
|
|
|
$this->assertEquals('../foo', Hyde::relativeLink('foo')); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function test_helper_handles_case_with_mixed_file_extensions() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->mockCurrentPage('foo/bar.md'); |
|
51
|
|
|
$this->assertEquals('../foo.md', Hyde::relativeLink('foo.md')); |
|
52
|
|
|
$this->mockCurrentPage('foo/bar.txt'); |
|
53
|
|
|
$this->assertEquals('../foo.txt', Hyde::relativeLink('foo.txt')); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function test_helper_handles_different_file_extensions() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->mockCurrentPage('foo/bar'); |
|
59
|
|
|
$this->assertEquals('../foo.png', Hyde::relativeLink('foo.png')); |
|
60
|
|
|
$this->assertEquals('../foo.css', Hyde::relativeLink('foo.css')); |
|
61
|
|
|
$this->assertEquals('../foo.js', Hyde::relativeLink('foo.js')); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function test_helper_returns_pretty_url_if_enabled_and_destination_is_a_html_file() |
|
65
|
|
|
{ |
|
66
|
|
|
config(['site.pretty_urls' => true]); |
|
67
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
68
|
|
|
$this->assertEquals('../foo', Hyde::relativeLink('foo.html')); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function test_helper_method_does_not_require_current_path_to_be_html_to_use_pretty_urls() |
|
72
|
|
|
{ |
|
73
|
|
|
config(['site.pretty_urls' => true]); |
|
74
|
|
|
$this->mockCurrentPage('foo/bar'); |
|
75
|
|
|
$this->assertEquals('../foo', Hyde::relativeLink('foo.html')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function test_helper_returns_does_not_return_pretty_url_if_when_enabled_but_and_destination_is_not_a_html_file() |
|
79
|
|
|
{ |
|
80
|
|
|
config(['site.pretty_urls' => true]); |
|
81
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
82
|
|
|
$this->assertEquals('../foo.png', Hyde::relativeLink('foo.png')); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function test_helper_rewrites_index_when_using_pretty_urls() |
|
86
|
|
|
{ |
|
87
|
|
|
config(['site.pretty_urls' => true]); |
|
88
|
|
|
$this->mockCurrentPage('foo.html'); |
|
89
|
|
|
$this->assertEquals('/', Hyde::relativeLink('index.html')); |
|
90
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
91
|
|
|
$this->assertEquals('../', Hyde::relativeLink('index.html')); |
|
92
|
|
|
$this->mockCurrentPage('foo/bar/baz.html'); |
|
93
|
|
|
$this->assertEquals('../../', Hyde::relativeLink('index.html')); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function test_helper_does_not_rewrite_index_when_not_using_pretty_urls() |
|
97
|
|
|
{ |
|
98
|
|
|
config(['site.pretty_urls' => false]); |
|
99
|
|
|
$this->mockCurrentPage('foo.html'); |
|
100
|
|
|
$this->assertEquals('index.html', Hyde::relativeLink('index.html')); |
|
101
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
102
|
|
|
$this->assertEquals('../index.html', Hyde::relativeLink('index.html')); |
|
103
|
|
|
$this->mockCurrentPage('foo/bar/baz.html'); |
|
104
|
|
|
$this->assertEquals('../../index.html', Hyde::relativeLink('index.html')); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function test_helper_rewrites_documentation_page_index_when_using_pretty_urls() |
|
108
|
|
|
{ |
|
109
|
|
|
config(['site.pretty_urls' => true]); |
|
110
|
|
|
$this->mockCurrentPage('foo.html'); |
|
111
|
|
|
$this->assertEquals('docs/', Hyde::relativeLink('docs/index.html')); |
|
112
|
|
|
$this->mockCurrentPage('docs.html'); |
|
113
|
|
|
$this->assertEquals('docs/', Hyde::relativeLink('docs/index.html')); |
|
114
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
115
|
|
|
$this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html')); |
|
116
|
|
|
$this->mockCurrentPage('docs/foo.html'); |
|
117
|
|
|
$this->assertEquals('../docs/', Hyde::relativeLink('docs/index.html')); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function test_helper_does_not_rewrite_documentation_page_index_when_not_using_pretty_urls() |
|
121
|
|
|
{ |
|
122
|
|
|
config(['site.pretty_urls' => false]); |
|
123
|
|
|
$this->mockCurrentPage('foo.html'); |
|
124
|
|
|
$this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html')); |
|
125
|
|
|
$this->mockCurrentPage('docs.html'); |
|
126
|
|
|
$this->assertEquals('docs/index.html', Hyde::relativeLink('docs/index.html')); |
|
127
|
|
|
$this->mockCurrentPage('foo/bar.html'); |
|
128
|
|
|
$this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html')); |
|
129
|
|
|
$this->mockCurrentPage('docs/foo.html'); |
|
130
|
|
|
$this->assertEquals('../docs/index.html', Hyde::relativeLink('docs/index.html')); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function test_helper_does_not_rewrite_already_processed_links() |
|
134
|
|
|
{ |
|
135
|
|
|
$this->assertEquals('../foo', Hyde::relativeLink('../foo')); |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|