|
2 | 2 |
|
3 | 3 | namespace Hyde\Framework\Testing\Feature;
|
4 | 4 |
|
| 5 | +use Hyde\Framework\Hyde; |
5 | 6 | use Hyde\Framework\Models\Pages\BladePage;
|
| 7 | +use Hyde\Framework\Models\Pages\DocumentationPage; |
6 | 8 | use Hyde\Framework\Models\Pages\MarkdownPage;
|
| 9 | +use Hyde\Framework\Models\Pages\MarkdownPost; |
7 | 10 | use Hyde\Framework\Modules\Routing\Route;
|
8 | 11 | use Hyde\Framework\Modules\Routing\RouteContract;
|
9 | 12 | use Hyde\Framework\Modules\Routing\RouteNotFoundException;
|
@@ -95,4 +98,65 @@ public function test_get_or_fail_does_not_return_null_if_route_is_not_found()
|
95 | 98 | $this->expectException(RouteNotFoundException::class);
|
96 | 99 | $this->assertNotNull(Route::getOrFail('not-found'));
|
97 | 100 | }
|
| 101 | + |
| 102 | + public function test_get_from_source_returns_route_from_router_index() |
| 103 | + { |
| 104 | + $this->assertEquals(new Route(BladePage::parse('index')), Route::getFromSource('_pages/index.blade.php')); |
| 105 | + $this->assertInstanceOf(RouteContract::class, Route::getFromSource('_pages/index.blade.php')); |
| 106 | + } |
| 107 | + |
| 108 | + public function test_get_from_source_returns_null_if_route_is_not_found() |
| 109 | + { |
| 110 | + $this->assertNull(Route::getFromSource('not-found')); |
| 111 | + } |
| 112 | + |
| 113 | + public function test_get_from_source_or_fail_returns_route_from_router_index() |
| 114 | + { |
| 115 | + $this->assertEquals(new Route(BladePage::parse('index')), Route::getFromSourceOrFail('_pages/index.blade.php')); |
| 116 | + $this->assertInstanceOf(RouteContract::class, Route::getFromSourceOrFail('_pages/index.blade.php')); |
| 117 | + } |
| 118 | + |
| 119 | + /** @covers \Hyde\Framework\Modules\Routing\RouteNotFoundException */ |
| 120 | + public function test_get_from_source_or_fail_throws_exception_if_route_is_not_found() |
| 121 | + { |
| 122 | + $this->expectException(RouteNotFoundException::class); |
| 123 | + $this->expectExceptionMessage("Route not found: 'not-found'"); |
| 124 | + $this->expectExceptionCode(404); |
| 125 | + |
| 126 | + Route::getFromSourceOrFail('not-found'); |
| 127 | + } |
| 128 | + |
| 129 | + public function test_get_from_source_or_fail_does_not_return_null_if_route_is_not_found() |
| 130 | + { |
| 131 | + $this->expectException(RouteNotFoundException::class); |
| 132 | + $this->assertNotNull(Route::getFromSourceOrFail('not-found')); |
| 133 | + } |
| 134 | + |
| 135 | + public function test_get_from_source_can_find_blade_pages() |
| 136 | + { |
| 137 | + touch(Hyde::path('_pages/foo.blade.php')); |
| 138 | + $this->assertEquals(new Route(BladePage::parse('foo')), Route::getFromSource('_pages/foo.blade.php')); |
| 139 | + unlink(Hyde::path('_pages/foo.blade.php')); |
| 140 | + } |
| 141 | + |
| 142 | + public function test_get_from_source_can_find_markdown_pages() |
| 143 | + { |
| 144 | + touch(Hyde::path('_pages/foo.md')); |
| 145 | + $this->assertEquals(new Route(MarkdownPage::parse('foo')), Route::getFromSource('_pages/foo.md')); |
| 146 | + unlink(Hyde::path('_pages/foo.md')); |
| 147 | + } |
| 148 | + |
| 149 | + public function test_get_from_source_can_find_markdown_posts() |
| 150 | + { |
| 151 | + touch(Hyde::path('_posts/foo.md')); |
| 152 | + $this->assertEquals(new Route(MarkdownPost::parse('foo')), Route::getFromSource('_posts/foo.md')); |
| 153 | + unlink(Hyde::path('_posts/foo.md')); |
| 154 | + } |
| 155 | + |
| 156 | + public function test_get_from_source_can_find_documentation_pages() |
| 157 | + { |
| 158 | + touch(Hyde::path('_docs/foo.md')); |
| 159 | + $this->assertEquals(new Route(DocumentationPage::parse('foo')), Route::getFromSource('_docs/foo.md')); |
| 160 | + unlink(Hyde::path('_docs/foo.md')); |
| 161 | + } |
98 | 162 | }
|
0 commit comments