From 37e5921bc1b46cd98b133668f6859922571b7a23 Mon Sep 17 00:00:00 2001
From: Caen De Silva This is a regular link with no Hyde syntax. This is a regular link with no Hyde syntax.
This is a regular link with no Hyde syntax.
'; + $this->assertSame($input, DynamicMarkdownLinkProcessor::postprocess($input)); } } From df09449ab2e856f3fe360888382f958cf3c104bf Mon Sep 17 00:00:00 2001 From: Caen De SilvaThis is a paragraph with a link to home and an about link.
+Another paragraph with an .
+ + HTML; + + $this->assertSame($expected, Hyde::markdown($input)->toHtml()); + } + + public function testDynamicMarkdownLinksInLists() + { + $input = <<<'MARKDOWN' + - [Home](hyde::route('home')) + - [About](hyde::relativeLink('about')) + - ![Logo](hyde::asset('logo.png')) + MARKDOWN; + + $expected = <<<'HTML' + + + HTML; + + $this->assertSame($expected, Hyde::markdown($input)->toHtml()); + } + + public function testDynamicMarkdownLinksWithNestedRoutes() + { + $input = <<<'MARKDOWN' + [Blog Post](hyde::route('blog/post')) + [Relative Blog](hyde::relativeLink('blog/post')) + MARKDOWN; + + $expected = <<<'HTML' + + + HTML; + + $this->assertSame($expected, Hyde::markdown($input)->toHtml()); + } + + public function testMixOfDynamicAndRegularMarkdownLinks() + { + $input = <<<'MARKDOWN' + [Home](hyde::route('home')) + [External](https://example.com) + [About](hyde::relativeLink('about')) + [Regular](regular-link.html) + ![Logo](hyde::asset('logo.png')) + ![External Image](https://example.com/image.jpg) + MARKDOWN; + + $expected = <<<'HTML' +Home + External + About + Regular + +
+ + HTML; + + $this->assertSame($expected, Hyde::markdown($input)->toHtml()); + } } From a8aeb8bf91e0e1d7d86ec81199df1780882c2b5a Mon Sep 17 00:00:00 2001 From: Caen De SilvaThis is a paragraph with a link to home and an about link.
+This is a paragraph with a link to home.
Another paragraph with an .
HTML; @@ -94,7 +88,6 @@ public function testDynamicMarkdownLinksInLists() { $input = <<<'MARKDOWN' - [Home](hyde::route('home')) - - [About](hyde::relativeLink('about')) - ![Logo](hyde::asset('logo.png')) MARKDOWN; @@ -104,9 +97,6 @@ public function testDynamicMarkdownLinksInLists() HomeHome -
- - HTML; + unlink('_media/logo.png'); + unlink('_media/image.jpg'); - $this->assertSame($expected, Hyde::markdown($input)->toHtml()); + parent::tearDownAfterClass(); } - public function testDynamicMarkdownLinksWithDoubleQuotes() + public function testBasicDynamicMarkdownLinks() { - $this->markTestSkipped('https://github.com/hydephp/develop/pull/1590#discussion_r1690082732'); - $input = <<<'MARKDOWN' - [Home](hyde::route("home")) - ![Logo](hyde::asset("logo.png")) + [Home](/_pages/index.blade.php) + ![Logo](/_media/logo.png) MARKDOWN; $expected = <<<'HTML' -Home +
HTML; @@ -70,13 +53,13 @@ public function testDynamicMarkdownLinksWithDoubleQuotes() public function testDynamicMarkdownLinksInParagraphs() { $input = <<<'MARKDOWN' - This is a paragraph with a [link to home](hyde::route('home')). + This is a paragraph with a [link to home](/_pages/index.blade.php). - Another paragraph with an ![image](hyde::asset('image.jpg')). + Another paragraph with an ![image](/_media/image.jpg). MARKDOWN; $expected = <<<'HTML' -This is a paragraph with a link to home.
+This is a paragraph with a link to home.
Another paragraph with an .
HTML; @@ -87,14 +70,14 @@ public function testDynamicMarkdownLinksInParagraphs() public function testDynamicMarkdownLinksInLists() { $input = <<<'MARKDOWN' - - [Home](hyde::route('home')) - - ![Logo](hyde::asset('logo.png')) + - [Home](/_pages/index.blade.php) + - ![Logo](/_media/logo.png) MARKDOWN; $expected = <<<'HTML'Home +
Home External Regular @@ -141,4 +126,20 @@ public function testMixOfDynamicAndRegularMarkdownLinks() $this->assertSame($expected, Hyde::markdown($input)->toHtml()); } + + public function testLinksWithLeadingSlash() + { + $input = <<<'MARKDOWN' + [Home with slash](/_pages/index.blade.php) + ![Logo with slash](/_media/logo.png) + MARKDOWN; + + $expected = <<<'HTML' +
+ + HTML; + + $this->assertSame($expected, Hyde::markdown($input)->toHtml()); + } } diff --git a/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php b/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php index daca2d7ea34..002ba287a8a 100644 --- a/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php +++ b/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php @@ -6,13 +6,13 @@ namespace Hyde\Framework\Testing\Feature\Services\Markdown; -use Hyde\Pages\InMemoryPage; +use Hyde\Pages\BladePage; +use Hyde\Pages\MarkdownPost; use Hyde\Testing\UnitTestCase; use Hyde\Support\Models\Route; use Hyde\Support\Facades\Render; use Hyde\Foundation\Facades\Routes; use Hyde\Support\Models\RenderData; -use Hyde\Framework\Exceptions\RouteNotFoundException; use Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor; /** @@ -31,37 +31,40 @@ protected function setUp(): void Render::swap(new RenderData()); - Routes::addRoute(new Route(new InMemoryPage('home'))); + Routes::addRoute(new Route(new BladePage('index'))); + Routes::addRoute(new Route(new MarkdownPost('post'))); + + // Todo: No way to mock media files, so we are using app.css as a test asset for now. } public function testRouteReplacement() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testRouteReplacementWithoutQuotes() + public function testRouteReplacementWithLeadingSlash() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } public function testAssetReplacement() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testAssetReplacementWithoutQuotes() + public function testAssetReplacementWithLeadingSlash() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } @@ -69,13 +72,13 @@ public function testAssetReplacementWithoutQuotes() public function testMultipleReplacements() { $input = <<<'HTML' - Home - + Home + HTML; $expected = <<<'HTML' - Home - + Home + HTML; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); @@ -88,61 +91,28 @@ public function testNoReplacements() $this->assertSame($input, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testNonExistentRouteThrowsException() - { - $this->expectException(RouteNotFoundException::class); - $this->expectExceptionMessage('Route [non-existent] not found.'); - - $input = ''; - DynamicMarkdownLinkProcessor::postprocess($input); - } - - // Fault tolerance tests - - public function testMalformedRouteLink() - { - $input = ''; - $expected = ''; - - $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); - } - - public function testMalformedRouteLink2() - { - $input = ''; - $expected = ''; - - $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); - } - - public function testMalformedRouteLink3() + public function testNestedRouteReplacement() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testMalformedAssetLink() - { - $input = ''; - $expected = ''; - - $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); - } + // Fault tolerance tests - public function testEmptyRouteLink() + public function testNonExistentRouteIsNotReplaced() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testEmptyAssetLink() + public function testNonExistentAssetIsNotReplaced() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } @@ -150,35 +120,19 @@ public function testEmptyAssetLink() public function testMixedValidAndInvalidLinks() { $input = <<<'HTML' - Valid Home - Invalid Route - - + Valid Home + Invalid Route + + HTML; $expected = <<<'HTML' - Valid Home - Invalid Route - - + Valid Home + Invalid Route + + HTML; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - - public function testMalformedHydeSyntax() - { - $input = ''; - $expected = ''; - - $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); - } - - public function testNonExistentRouteFunction() - { - $input = ''; - $expected = ''; - - $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); - } } From 9e613daae4995f0b078c91b1a481db45933b0cce Mon Sep 17 00:00:00 2001 From: Caen De SilvaHome +
+ + HTML; - parent::tearDownAfterClass(); + $this->assertSame($expected, Hyde::markdown($input)->toHtml()); } - public function testBasicDynamicMarkdownLinks() + public function testDynamicMarkdownLinksWithDoubleQuotes() { + $this->markTestSkipped('https://github.com/hydephp/develop/pull/1590#discussion_r1690082732'); + $input = <<<'MARKDOWN' - [Home](/_pages/index.blade.php) - ![Logo](/_media/logo.png) + [Home](hyde::route("home")) + ![Logo](hyde::asset("logo.png")) MARKDOWN; $expected = <<<'HTML' -Home +
HTML; @@ -56,13 +70,13 @@ public function testBasicDynamicMarkdownLinks() public function testDynamicMarkdownLinksInParagraphs() { $input = <<<'MARKDOWN' - This is a paragraph with a [link to home](/_pages/index.blade.php). + This is a paragraph with a [link to home](hyde::route('home')). - Another paragraph with an ![image](/_media/image.jpg). + Another paragraph with an ![image](hyde::asset('image.jpg')). MARKDOWN; $expected = <<<'HTML' -This is a paragraph with a link to home.
+This is a paragraph with a link to home.
Another paragraph with an .
HTML; @@ -73,14 +87,14 @@ public function testDynamicMarkdownLinksInParagraphs() public function testDynamicMarkdownLinksInLists() { $input = <<<'MARKDOWN' - - [Home](/_pages/index.blade.php) - - ![Logo](/_media/logo.png) + - [Home](hyde::route('home')) + - ![Logo](hyde::asset('logo.png')) MARKDOWN; $expected = <<<'HTML'Home +
Home External Regular @@ -129,124 +141,4 @@ public function testMixOfDynamicAndRegularMarkdownLinks() $this->assertSame($expected, Hyde::markdown($input)->toHtml()); } - - public function testLinksWithLeadingSlash() - { - $input = <<<'MARKDOWN' - [Home with slash](/_pages/index.blade.php) - ![Logo with slash](/_media/logo.png) - MARKDOWN; - - $expected = <<<'HTML' -
- - HTML; - - $this->assertSame($expected, Hyde::markdown($input)->toHtml()); - } - - public function testCanRenderPageWithDynamicMarkdownLinks() - { - $this->file('_pages/test.md', <<<'MARKDOWN' - [Home](/_pages/index.blade.php) - ![Logo](/_media/logo.png) - - [non-existent](/_pages/non-existent.md) - ![non-existent](/_media/non-existent.png) - MARKDOWN); - - $page = MarkdownPage::get('test'); - Hyde::shareViewData($page); - $html = $page->compile(); - - $expected = [ - 'Home', - '', - 'non-existent', - '', - ]; - - foreach ($expected as $expectation) { - $this->assertStringContainsString($expectation, $html); - } - } - - public function testCanRenderNestedPageWithDynamicMarkdownLinks() - { - $this->file('_pages/nested/test.md', <<<'MARKDOWN' - [Home](/_pages/index.blade.php) - ![Logo](/_media/logo.png) - - [non-existent](/_pages/non-existent.md) - ![non-existent](/_media/non-existent.png) - MARKDOWN); - - $page = MarkdownPage::get('nested/test'); - Hyde::shareViewData($page); - $html = $page->compile(); - - $expected = [ - 'Home', - '', - 'non-existent', - '', - ]; - - foreach ($expected as $expectation) { - $this->assertStringContainsString($expectation, $html); - } - } - - public function testCanRenderIncludeWithDynamicMarkdownLinks() - { - // if there is no current path data, we assume the file is included from the root - - $this->file('resources/includes/test.md', <<<'MARKDOWN' - [Home](/_pages/index.blade.php) - ![Logo](/_media/logo.png) - - [non-existent](/_pages/non-existent.md) - ![non-existent](/_media/non-existent.png) - MARKDOWN); - - $html = Includes::markdown('test')->toHtml(); - - $expected = [ - 'Home', - '', - 'non-existent', - '', - ]; - - foreach ($expected as $expectation) { - $this->assertStringContainsString($expectation, $html); - } - } - - public function testCanRenderIncludeFromNestedPageWithDynamicMarkdownLinks() - { - $this->mockCurrentPage('nested/test'); - - $this->file('resources/includes/test.md', <<<'MARKDOWN' - [Home](/_pages/index.blade.php) - ![Logo](/_media/logo.png) - - [non-existent](/_pages/non-existent.md) - ![non-existent](/_media/non-existent.png) - MARKDOWN); - - $html = Includes::markdown('test')->toHtml(); - - $expected = [ - 'Home', - '', - 'non-existent', - '', - ]; - - foreach ($expected as $expectation) { - $this->assertStringContainsString($expectation, $html); - } - } } diff --git a/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php b/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php index 002ba287a8a..daca2d7ea34 100644 --- a/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php +++ b/packages/framework/tests/Feature/Services/Markdown/DynamicMarkdownLinkProcessorTest.php @@ -6,13 +6,13 @@ namespace Hyde\Framework\Testing\Feature\Services\Markdown; -use Hyde\Pages\BladePage; -use Hyde\Pages\MarkdownPost; +use Hyde\Pages\InMemoryPage; use Hyde\Testing\UnitTestCase; use Hyde\Support\Models\Route; use Hyde\Support\Facades\Render; use Hyde\Foundation\Facades\Routes; use Hyde\Support\Models\RenderData; +use Hyde\Framework\Exceptions\RouteNotFoundException; use Hyde\Markdown\Processing\DynamicMarkdownLinkProcessor; /** @@ -31,40 +31,37 @@ protected function setUp(): void Render::swap(new RenderData()); - Routes::addRoute(new Route(new BladePage('index'))); - Routes::addRoute(new Route(new MarkdownPost('post'))); - - // Todo: No way to mock media files, so we are using app.css as a test asset for now. + Routes::addRoute(new Route(new InMemoryPage('home'))); } public function testRouteReplacement() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testRouteReplacementWithLeadingSlash() + public function testRouteReplacementWithoutQuotes() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } public function testAssetReplacement() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testAssetReplacementWithLeadingSlash() + public function testAssetReplacementWithoutQuotes() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } @@ -72,13 +69,13 @@ public function testAssetReplacementWithLeadingSlash() public function testMultipleReplacements() { $input = <<<'HTML' - Home - + Home + HTML; $expected = <<<'HTML' - Home - + Home + HTML; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); @@ -91,28 +88,61 @@ public function testNoReplacements() $this->assertSame($input, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testNestedRouteReplacement() + public function testNonExistentRouteThrowsException() { - $input = ''; - $expected = ''; + $this->expectException(RouteNotFoundException::class); + $this->expectExceptionMessage('Route [non-existent] not found.'); - $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); + $input = ''; + DynamicMarkdownLinkProcessor::postprocess($input); } // Fault tolerance tests - public function testNonExistentRouteIsNotReplaced() + public function testMalformedRouteLink() + { + $input = ''; + $expected = ''; + + $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); + } + + public function testMalformedRouteLink2() + { + $input = ''; + $expected = ''; + + $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); + } + + public function testMalformedRouteLink3() + { + $input = ''; + $expected = ''; + + $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); + } + + public function testMalformedAssetLink() + { + $input = ''; + $expected = ''; + + $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); + } + + public function testEmptyRouteLink() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } - public function testNonExistentAssetIsNotReplaced() + public function testEmptyAssetLink() { - $input = ''; - $expected = ''; + $input = ''; + $expected = ''; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } @@ -120,19 +150,35 @@ public function testNonExistentAssetIsNotReplaced() public function testMixedValidAndInvalidLinks() { $input = <<<'HTML' - Valid Home - Invalid Route - - + Valid Home + Invalid Route + + HTML; $expected = <<<'HTML' - Valid Home - Invalid Route - - + Valid Home + Invalid Route + + HTML; $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); } + + public function testMalformedHydeSyntax() + { + $input = ''; + $expected = ''; + + $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); + } + + public function testNonExistentRouteFunction() + { + $input = ''; + $expected = ''; + + $this->assertSame($expected, DynamicMarkdownLinkProcessor::postprocess($input)); + } } diff --git a/packages/framework/tests/Unit/IncludesFacadeUnitTest.php b/packages/framework/tests/Unit/IncludesFacadeUnitTest.php index 6dac17db2f5..1da30c9d435 100644 --- a/packages/framework/tests/Unit/IncludesFacadeUnitTest.php +++ b/packages/framework/tests/Unit/IncludesFacadeUnitTest.php @@ -9,12 +9,9 @@ use Hyde\Hyde; use Hyde\Support\Includes; use Hyde\Testing\UnitTestCase; -use Hyde\Support\Facades\Render; use Illuminate\Support\HtmlString; -use Hyde\Support\Models\RenderData; use Illuminate\Support\Facades\Blade; use Illuminate\Filesystem\Filesystem; -use Hyde\Testing\MocksKernelFeatures; /** * @covers \Hyde\Support\Includes @@ -23,8 +20,6 @@ */ class IncludesFacadeUnitTest extends UnitTestCase { - use MocksKernelFeatures; - protected static bool $needsKernel = true; protected static bool $needsConfig = true; @@ -33,10 +28,6 @@ protected function setUp(): void parent::setUp(); Blade::swap(Mockery::mock()); - - $this->setupTestKernel(); - $this->kernel->setRoutes(collect()); - Render::swap(new RenderData()); } protected function tearDown(): void From 9c19e5025063d8575c8e1b0a6972e3a2d1499cb4 Mon Sep 17 00:00:00 2001 From: Caen De SilvaHome -
-Home -
- - HTML; - - $this->assertSame($expected, Hyde::markdown($input)->toHtml()); - } - - public function testDynamicMarkdownLinksWithDoubleQuotes() - { - $this->markTestSkipped('https://github.com/hydephp/develop/pull/1590#discussion_r1690082732'); - - $input = <<<'MARKDOWN' - [Home](hyde::route("home")) - ![Logo](hyde::asset("logo.png")) - MARKDOWN; - - $expected = <<<'HTML' -Home +
HTML; @@ -78,13 +56,13 @@ public function testDynamicMarkdownLinksWithDoubleQuotes() public function testDynamicMarkdownLinksInParagraphs() { $input = <<<'MARKDOWN' - This is a paragraph with a [link to home](hyde::route('home')). + This is a paragraph with a [link to home](/_pages/index.blade.php). - Another paragraph with an ![image](hyde::asset('image.jpg')). + Another paragraph with an ![image](/_media/image.jpg). MARKDOWN; $expected = <<<'HTML' -This is a paragraph with a link to home.
+This is a paragraph with a link to home.
Another paragraph with an .
HTML; @@ -95,14 +73,14 @@ public function testDynamicMarkdownLinksInParagraphs() public function testDynamicMarkdownLinksInLists() { $input = <<<'MARKDOWN' - - [Home](hyde::route('home')) - - ![Logo](hyde::asset('logo.png')) + - [Home](/_pages/index.blade.php) + - ![Logo](/_media/logo.png) MARKDOWN; $expected = <<<'HTML'Home +
Home External Regular @@ -149,4 +129,20 @@ public function testMixOfDynamicAndRegularMarkdownLinks() $this->assertSame($expected, Hyde::markdown($input)->toHtml()); } + + public function testLinksWithLeadingSlash() + { + $input = <<<'MARKDOWN' + [Home with slash](/_pages/index.blade.php) + ![Logo with slash](/_media/logo.png) + MARKDOWN; + + $expected = <<<'HTML' +
+ + HTML; + + $this->assertSame($expected, Hyde::markdown($input)->toHtml()); + } } From 60786a556133fc1b26e131b7e34deb23a5149e58 Mon Sep 17 00:00:00 2001 From: Caen De Silva