Skip to content

Commit

Permalink
Merge pull request #1962 from hydephp/test-cleanup
Browse files Browse the repository at this point in the history
Internal: Test code refactors and cleanup hydephp/develop@7e4b929
  • Loading branch information
github-actions committed Sep 10, 2024
1 parent a50d074 commit a8ed755
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 99 deletions.
89 changes: 0 additions & 89 deletions tests/Feature/MetadataHelperTest.php

This file was deleted.

64 changes: 64 additions & 0 deletions tests/Unit/MetaFacadeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Hyde\Framework\Testing\Unit;

use Hyde\Facades\Meta;
use Hyde\Framework\Features\Metadata\GlobalMetadataBag;
use Hyde\Testing\UnitTestCase;

/**
* @covers \Hyde\Facades\Meta
*/
class MetaFacadeTest extends UnitTestCase
{
protected static bool $needsKernel = true;
protected static bool $needsConfig = true;
protected static bool $needsRender = true;

public function testNameMethodReturnsAValidHtmlMetaString()
{
$this->assertSame('<meta name="foo" content="bar">', (string) Meta::name('foo', 'bar'));
}

public function testPropertyMethodReturnsAValidHtmlMetaString()
{
$this->assertSame('<meta property="og:foo" content="bar">', (string) Meta::property('foo', 'bar'));
}

public function testPropertyMethodAcceptsPropertyWithOgPrefix()
{
$this->assertSame('<meta property="og:foo" content="bar">', (string) Meta::property('og:foo', 'bar'));
}

public function testPropertyMethodAcceptsPropertyWithoutOgPrefix()
{
$this->assertSame('<meta property="og:foo" content="bar">', (string) Meta::property('foo', 'bar'));
}

public function testLinkMethodReturnsAValidHtmlLinkString()
{
$this->assertSame('<link rel="foo" href="bar">', (string) Meta::link('foo', 'bar'));
}

public function testLinkMethodReturnsAValidHtmlLinkStringWithAttributes()
{
$this->assertSame('<link rel="foo" href="bar" title="baz">', (string) Meta::link('foo', 'bar', ['title' => 'baz']));
}

public function testLinkMethodReturnsAValidHtmlLinkStringWithMultipleAttributes()
{
$this->assertSame('<link rel="foo" href="bar" title="baz" type="text/css">', (string) Meta::link('foo', 'bar', ['title' => 'baz', 'type' => 'text/css']));
}

public function testGetMethodReturnsGlobalMetadataBag()
{
$this->assertEquals(Meta::get(), GlobalMetadataBag::make());
}

public function testRenderMethodRendersGlobalMetadataBag()
{
$this->assertSame(Meta::render(), GlobalMetadataBag::make()->render());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

declare(strict_types=1);

namespace Hyde\Framework\Testing\Feature;
namespace Hyde\Framework\Testing\Unit;

use Hyde\Facades\Filesystem;
use Hyde\Hyde;
use Hyde\Testing\UnitTestCase;
use Hyde\Pages\DocumentationPage;
use Hyde\Pages\MarkdownPage;
use Hyde\Testing\TestCase;
use Hyde\Testing\CreatesTemporaryFiles;

/**
* Test the constructor actions and schema constructors for page models.
Expand All @@ -19,8 +18,18 @@
* @covers \Hyde\Framework\Factories\HydePageDataFactory
* @covers \Hyde\Framework\Factories\BlogPostDataFactory
*/
class PageModelConstructorsTest extends TestCase
class PageModelParsingTest extends UnitTestCase
{
use CreatesTemporaryFiles;

protected static bool $needsKernel = true;
protected static bool $needsConfig = true;

protected function tearDown(): void
{
$this->cleanUpFilesystem();
}

public function testDynamicDataConstructorCanFindTitleFromFrontMatter()
{
$this->markdown('_pages/foo.md', '# Foo Bar', ['title' => 'My Title']);
Expand Down Expand Up @@ -55,13 +64,10 @@ public function testDocumentationPageParserCanGetGroupFromFrontMatter()

public function testDocumentationPageParserCanGetGroupAutomaticallyFromNestedPage()
{
mkdir(Hyde::path('_docs/foo'));
touch(Hyde::path('_docs/foo/bar.md'));
$this->directory('_docs/foo');
$this->file('_docs/foo/bar.md');

$page = DocumentationPage::parse('foo/bar');
$this->assertSame('foo', $page->navigationMenuGroup());

Filesystem::unlink('_docs/foo/bar.md');
rmdir(Hyde::path('_docs/foo'));
}
}

0 comments on commit a8ed755

Please sign in to comment.