Skip to content

Commit

Permalink
Merge pull request #492 from hydephp/breaking-page-refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Sep 11, 2022
1 parent 8d90cc8 commit bd76742
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 88 deletions.
96 changes: 89 additions & 7 deletions tests/Feature/HydePageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,106 @@
*/
class HydePageTest extends TestCase
{
protected function tearDown(): void
// Section: Baseline tests

public function testSourceDirectory()
{
BladePage::$sourceDirectory = '_pages';
MarkdownPage::$sourceDirectory = '_pages';
MarkdownPost::$sourceDirectory = '_posts';
DocumentationPage::$sourceDirectory = '_docs';
MarkdownPage::$fileExtension = '.md';
$this->assertSame(
'source',
HandlesPageFilesystemTestClass::sourceDirectory()
);
}

parent::tearDown();
public function testOutputDirectory()
{
$this->assertSame(
'output',
HandlesPageFilesystemTestClass::outputDirectory()
);
}

public function testFileExtension()
{
$this->assertSame(
'.md',
HandlesPageFilesystemTestClass::fileExtension()
);
}

public function testSourcePath()
{
$this->assertSame(
'source/hello-world.md',
HandlesPageFilesystemTestClass::sourcePath('hello-world')
);
}

public function testOutputPath()
{
$this->assertSame(
'output/hello-world.html',
HandlesPageFilesystemTestClass::outputPath('hello-world')
);
}

public function testGetSourcePath()
{
$this->assertSame(
'source/hello-world.md',
(new HandlesPageFilesystemTestClass('hello-world'))->getSourcePath()
);
}

public function testGetOutputPath()
{
$this->assertSame(
'output/hello-world.html',
(new HandlesPageFilesystemTestClass('hello-world'))->getOutputPath()
);
}

// Section: In-depth tests

public function test_get_source_directory_returns_static_property()
{
MarkdownPage::$sourceDirectory = 'foo';
$this->assertEquals('foo', MarkdownPage::sourceDirectory());
$this->resetDirectoryConfiguration();
}

public function test_get_source_directory_trims_trailing_slashes()
{
MarkdownPage::$sourceDirectory = '/foo/\\';
$this->assertEquals('foo', MarkdownPage::sourceDirectory());
$this->resetDirectoryConfiguration();
}

public function test_get_output_directory_returns_static_property()
{
MarkdownPage::$outputDirectory = 'foo';
$this->assertEquals('foo', MarkdownPage::outputDirectory());
$this->resetDirectoryConfiguration();
}

public function test_get_output_directory_trims_trailing_slashes()
{
MarkdownPage::$outputDirectory = '/foo/\\';
$this->assertEquals('foo', MarkdownPage::outputDirectory());
$this->resetDirectoryConfiguration();
}

public function test_get_file_extension_returns_static_property()
{
MarkdownPage::$fileExtension = '.foo';
$this->assertEquals('.foo', MarkdownPage::fileExtension());
$this->resetDirectoryConfiguration();
}

public function test_get_file_extension_forces_leading_period()
{
MarkdownPage::$fileExtension = 'foo';
$this->assertEquals('.foo', MarkdownPage::fileExtension());
$this->resetDirectoryConfiguration();
}

public function test_get_identifier_returns_identifier_property()
Expand Down Expand Up @@ -128,6 +183,7 @@ public function test_qualify_basename_uses_the_static_properties()
MarkdownPage::$sourceDirectory = 'foo';
MarkdownPage::$fileExtension = 'txt';
$this->assertEquals('foo/bar.txt', MarkdownPage::sourcePath('bar'));
$this->resetDirectoryConfiguration();
}

public function test_get_output_location_returns_the_file_output_path_for_the_supplied_basename()
Expand All @@ -139,12 +195,14 @@ public function test_get_output_location_returns_the_configured_location()
{
MarkdownPage::$outputDirectory = 'foo';
$this->assertEquals('foo/bar.html', MarkdownPage::outputPath('bar'));
$this->resetDirectoryConfiguration();
}

public function test_get_output_location_trims_trailing_slashes_from_directory_setting()
{
MarkdownPage::$outputDirectory = '/foo/\\';
$this->assertEquals('foo/bar.html', MarkdownPage::outputPath('bar'));
$this->resetDirectoryConfiguration();
}

public function test_get_output_location_trims_trailing_slashes_from_basename()
Expand All @@ -163,13 +221,15 @@ public function test_get_current_page_path_returns_output_directory_and_basename
MarkdownPage::$outputDirectory = 'foo';
$page = new MarkdownPage('bar');
$this->assertEquals('foo/bar', $page->getRouteKey());
$this->resetDirectoryConfiguration();
}

public function test_get_current_page_path_trims_trailing_slashes_from_directory_setting()
{
MarkdownPage::$outputDirectory = '/foo/\\';
$page = new MarkdownPage('bar');
$this->assertEquals('foo/bar', $page->getRouteKey());
$this->resetDirectoryConfiguration();
}

public function test_get_output_path_returns_current_page_path_with_html_extension_appended()
Expand Down Expand Up @@ -675,4 +735,26 @@ public function test_save_method_writes_page_body_to_file_with_front_matter()
);
unlink(Hyde::path('_pages/foo.md'));
}

protected function resetDirectoryConfiguration(): void
{
BladePage::$sourceDirectory = '_pages';
MarkdownPage::$sourceDirectory = '_pages';
MarkdownPost::$sourceDirectory = '_posts';
DocumentationPage::$sourceDirectory = '_docs';
MarkdownPage::$fileExtension = '.md';
}
}

class HandlesPageFilesystemTestClass extends HydePage
{
public static string $sourceDirectory = 'source';
public static string $outputDirectory = 'output';
public static string $fileExtension = '.md';
public static string $template = 'template';

public function compile(): string
{
return '';
}
}
81 changes: 0 additions & 81 deletions tests/Unit/HydePageFileHelpersTest.php

This file was deleted.

0 comments on commit bd76742

Please sign in to comment.