|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hyde\Framework\Testing\Feature; |
|
4
|
|
|
|
|
5
|
|
|
use Hyde\Framework\Contracts\HydeKernelContract; |
|
6
|
|
|
use Hyde\Framework\Contracts\RouteContract; |
|
7
|
|
|
use Hyde\Framework\Helpers\Features; |
|
8
|
|
|
use Hyde\Framework\Hyde; |
|
9
|
|
|
use Hyde\Framework\HydeKernel; |
|
10
|
|
|
use Hyde\Framework\Models\Pages\BladePage; |
|
11
|
|
|
use Hyde\Framework\Models\Pages\DocumentationPage; |
|
12
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPage; |
|
13
|
|
|
use Hyde\Framework\Models\Pages\MarkdownPost; |
|
14
|
|
|
use Hyde\Framework\Models\Route; |
|
15
|
|
|
use Hyde\Testing\TestCase; |
|
16
|
|
|
use Illuminate\Support\Facades\Config; |
|
17
|
|
|
use Illuminate\Support\Facades\View; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* This test class runs high-level tests on the HydeKernel class, |
|
21
|
|
|
* as most of the logic actually resides in linked service classes. |
|
22
|
|
|
* |
|
23
|
|
|
* @covers \Hyde\Framework\HydeKernel |
|
24
|
|
|
* |
|
25
|
|
|
* @see \Hyde\Framework\Testing\Unit\HydeHelperFacadeMakeTitleTest |
|
26
|
|
|
*/ |
|
27
|
|
|
class HydeKernelTest extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
public function test_kernel_singleton_can_be_accessed_by_service_container() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->assertSame(app(HydeKernelContract::class), app(HydeKernelContract::class)); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function test_kernel_singleton_can_be_accessed_by_kernel_static_method() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->assertSame(app(HydeKernelContract::class), HydeKernel::getInstance()); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function test_kernel_singleton_can_be_accessed_by_hyde_facade_method() |
|
40
|
|
|
{ |
|
41
|
|
|
$this->assertSame(app(HydeKernelContract::class), Hyde::getInstance()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function test_kernel_singleton_can_be_accessed_by_helper_function() |
|
45
|
|
|
{ |
|
46
|
|
|
$this->assertSame(app(HydeKernelContract::class), hyde()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function test_features_helper_returns_new_features_instance() |
|
50
|
|
|
{ |
|
51
|
|
|
$this->assertInstanceOf(Features::class, Hyde::features()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function test_has_feature_helper_calls_method_on_features_class() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->assertEquals(Features::enabled('foo'), Hyde::hasFeature('foo')); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function test_current_page_helper_returns_current_page_name() |
|
60
|
|
|
{ |
|
61
|
|
|
View::share('currentPage', 'foo'); |
|
62
|
|
|
$this->assertEquals('foo', Hyde::currentPage()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function test_current_route_helper_returns_current_route_object() |
|
66
|
|
|
{ |
|
67
|
|
|
$expected = new Route(new MarkdownPage()); |
|
68
|
|
|
View::share('currentRoute', $expected); |
|
69
|
|
|
$this->assertInstanceOf(RouteContract::class, Hyde::currentRoute()); |
|
70
|
|
|
$this->assertEquals($expected, Hyde::currentRoute()); |
|
71
|
|
|
$this->assertSame($expected, Hyde::currentRoute()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function test_make_title_helper_returns_title_from_page_slug() |
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertEquals('Foo Bar', Hyde::makeTitle('foo-bar')); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function test_format_html_path_helper_formats_path_according_to_config_rules() |
|
80
|
|
|
{ |
|
81
|
|
|
Config::set('site.pretty_urls', false); |
|
82
|
|
|
$this->assertEquals('foo.html', Hyde::formatHtmlPath('foo.html')); |
|
83
|
|
|
$this->assertEquals('index.html', Hyde::formatHtmlPath('index.html')); |
|
84
|
|
|
|
|
85
|
|
|
Config::set('site.pretty_urls', true); |
|
86
|
|
|
$this->assertEquals('foo', Hyde::formatHtmlPath('foo.html')); |
|
87
|
|
|
$this->assertEquals('/', Hyde::formatHtmlPath('index.html')); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function test_relative_link_helper_returns_relative_link_to_destination() |
|
91
|
|
|
{ |
|
92
|
|
|
View::share('currentPage', 'bar'); |
|
93
|
|
|
$this->assertEquals('foo', Hyde::relativeLink('foo')); |
|
94
|
|
|
|
|
95
|
|
|
View::share('currentPage', 'foo/bar'); |
|
96
|
|
|
$this->assertEquals('../foo', Hyde::relativeLink('foo')); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function test_image_helper_returns_image_path_for_given_name() |
|
100
|
|
|
{ |
|
101
|
|
|
View::share('currentPage', 'foo'); |
|
102
|
|
|
$this->assertEquals('media/foo.jpg', Hyde::image('foo.jpg')); |
|
103
|
|
|
$this->assertEquals('https://example.com/foo.jpg', Hyde::image('https://example.com/foo.jpg')); |
|
104
|
|
|
|
|
105
|
|
|
View::share('currentPage', 'foo/bar'); |
|
106
|
|
|
$this->assertEquals('../media/foo.jpg', Hyde::image('foo.jpg')); |
|
107
|
|
|
$this->assertEquals('https://example.com/foo.jpg', Hyde::image('https://example.com/foo.jpg')); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function test_has_site_url_helper_returns_boolean_value_for_when_config_setting_is_set() |
|
111
|
|
|
{ |
|
112
|
|
|
Config::set('site.url', 'https://example.com'); |
|
113
|
|
|
$this->assertTrue(Hyde::hasSiteUrl()); |
|
114
|
|
|
|
|
115
|
|
|
Config::set('site.url', null); |
|
116
|
|
|
$this->assertFalse(Hyde::hasSiteUrl()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function test_url_returns_qualified_url_paths() |
|
120
|
|
|
{ |
|
121
|
|
|
Config::set('site.url', 'https://example.com'); |
|
122
|
|
|
$this->assertEquals('https://example.com', Hyde::url()); |
|
123
|
|
|
$this->assertEquals('https://example.com/foo', Hyde::url('foo')); |
|
124
|
|
|
|
|
125
|
|
|
Config::set('site.pretty_urls', false); |
|
126
|
|
|
$this->assertEquals('https://example.com/foo.html', Hyde::url('foo.html')); |
|
127
|
|
|
$this->assertEquals('https://example.com/index.html', Hyde::url('index.html')); |
|
128
|
|
|
|
|
129
|
|
|
Config::set('site.pretty_urls', true); |
|
130
|
|
|
$this->assertEquals('https://example.com/foo', Hyde::url('foo.html')); |
|
131
|
|
|
$this->assertEquals('https://example.com', Hyde::url('index.html')); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function test_path_returns_qualified_path_for_given_path() |
|
135
|
|
|
{ |
|
136
|
|
|
$this->assertEquals(Hyde::getBasePath(), Hyde::path()); |
|
137
|
|
|
$this->assertEquals(Hyde::getBasePath().DIRECTORY_SEPARATOR.'foo', Hyde::path('foo')); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function test_vendor_path_returns_qualified_path_for_given_path() |
|
141
|
|
|
{ |
|
142
|
|
|
$this->assertEquals(Hyde::getBasePath().DIRECTORY_SEPARATOR.'vendor/hyde/framework', Hyde::vendorPath()); |
|
143
|
|
|
$this->assertEquals(Hyde::getBasePath().DIRECTORY_SEPARATOR.'vendor/hyde/framework/foo', Hyde::vendorPath('foo')); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function test_copy_helper_copies_file_from_given_path_to_given_path() |
|
147
|
|
|
{ |
|
148
|
|
|
touch('foo'); |
|
149
|
|
|
$this->assertTrue(Hyde::copy('foo', 'bar')); |
|
150
|
|
|
$this->assertFileExists('bar'); |
|
151
|
|
|
unlink('foo'); |
|
152
|
|
|
unlink('bar'); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
public function test_fluent_model_source_path_helpers() |
|
156
|
|
|
{ |
|
157
|
|
|
$this->assertEquals(Hyde::path('_posts'), Hyde::getModelSourcePath(MarkdownPost::class)); |
|
158
|
|
|
$this->assertEquals(Hyde::path('_pages'), Hyde::getModelSourcePath(MarkdownPage::class)); |
|
159
|
|
|
$this->assertEquals(Hyde::path('_docs'), Hyde::getModelSourcePath(DocumentationPage::class)); |
|
160
|
|
|
$this->assertEquals(Hyde::path('_pages'), Hyde::getModelSourcePath(BladePage::class)); |
|
161
|
|
|
|
|
162
|
|
|
$this->assertEquals(Hyde::path('_pages'), Hyde::getBladePagePath()); |
|
163
|
|
|
$this->assertEquals(Hyde::path('_pages'), Hyde::getMarkdownPagePath()); |
|
164
|
|
|
$this->assertEquals(Hyde::path('_posts'), Hyde::getMarkdownPostPath()); |
|
165
|
|
|
$this->assertEquals(Hyde::path('_docs'), Hyde::getDocumentationPagePath()); |
|
166
|
|
|
$this->assertEquals(Hyde::path('_site'), Hyde::getSiteOutputPath()); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
public function test_path_to_relative_helper_returns_relative_path_for_given_path() |
|
170
|
|
|
{ |
|
171
|
|
|
$this->assertEquals('foo', Hyde::pathToRelative(Hyde::path('foo'))); |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|