Skip to content

Commit

Permalink
simplify TagEngineTest
Browse files Browse the repository at this point in the history
  • Loading branch information
LordSimal committed Aug 10, 2024
1 parent 6150d04 commit 30ee0fc
Showing 1 changed file with 23 additions and 102 deletions.
125 changes: 23 additions & 102 deletions tests/TagEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ class TagEngineTest extends TestCase
{
protected const CACHE_DIR = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;

protected TagEngine $tagEngine;

protected function setUp(): void
{
if (!file_exists(self::CACHE_DIR)) {
mkdir(self::CACHE_DIR);
}
$this->tagEngine = new TagEngine([
'tag_directories' => [
__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
],
]);
}

protected function tearDown(): void
Expand All @@ -46,10 +54,7 @@ protected function tearDown(): void
public function testTagWithAttribute(): void
{
$element = '<c-youtube src="RLdsCL4RDf8"></c-youtube>';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<iframe width="560" height="315"
src="https://www.youtube.com/embed/RLdsCL4RDf8"
Expand All @@ -68,10 +73,7 @@ public function testTagWithAttribute(): void
public function testTagWithAttributeSelfClosing(): void
{
$element = '<c-youtube src="RLdsCL4RDf8" />';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<iframe width="560" height="315"
src="https://www.youtube.com/embed/RLdsCL4RDf8"
Expand All @@ -90,10 +92,7 @@ public function testTagWithAttributeSelfClosing(): void
public function testMultipleTagsWithAttributeSelfClosing(): void
{
$element = '<c-youtube src="RLdsCL4RDf8" /><c-youtube src="RLdsCL4RDf8" />';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<iframe width="560" height="315"
src="https://www.youtube.com/embed/RLdsCL4RDf8"
Expand All @@ -116,10 +115,7 @@ public function testMultipleTagsWithAttributeSelfClosing(): void
public function testTagWithMultipleAttributes(): void
{
$element = '<c-button type="primary" text="Click me" url="/something/stupid" />';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<a href="/something/stupid" class="c-button c-button--primary">Click me</a>
HTML;
Expand All @@ -134,13 +130,7 @@ public function testTagWithMultipleAttributes(): void
public function testTagInSubFolder(): void
{
$element = '<c-github></c-github>';
$tagEngine = new TagEngine([
'tag_directories' => [
__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
This is a render from a plugin tag
Expand All @@ -156,13 +146,7 @@ public function testTagInSubFolder(): void
public function testTagWithInnerContent(): void
{
$element = '<c-github>Inner Content</c-github>';
$tagEngine = new TagEngine([
'tag_directories' => [
__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
This is a render from a plugin tag
Inner Content
Expand All @@ -178,13 +162,7 @@ public function testTagWithInnerContent(): void
public function testTagsNested(): void
{
$element = '<c-github><c-github></c-github></c-github>';
$tagEngine = new TagEngine([
'tag_directories' => [
__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
This is a render from a plugin tag
<c-github></c-github>
Expand All @@ -200,47 +178,14 @@ public function testTagsNested(): void
public function testNestedContentRendersWithConfig(): void
{
$element = '<c-nested />';
$tagEngine = new TagEngine([
'tag_directories' => [
__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
This is a render from a plugin tag
HTML;
$this->assertSame($expected, $result);
}

/**
* Test that sub-tags will trigger cache correctly
*
* @return void
*/
public function testNestedContentRendersWithCache(): void
{
$element = '<c-nested />';
$tagEngine = new TagEngine([
'tag_directories' => [
__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
],
'cache_tags' => true,
'cache_directory' => self::CACHE_DIR,
]);
$result = $tagEngine->parse($element);
$expected = <<<HTML
This is a render from a plugin tag
HTML;
$this->assertSame($expected, $result);

$result = $tagEngine->parse($element);
$this->assertSame($expected, $result);
}

/**
* Test tag variant and normal HTML
*
Expand All @@ -249,10 +194,7 @@ public function testNestedContentRendersWithCache(): void
public function testTagWithAttributeAndNormalHTML(): void
{
$element = '<c-youtube src="RLdsCL4RDf8"></c-youtube><div>Test</div>';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<iframe width="560" height="315"
src="https://www.youtube.com/embed/RLdsCL4RDf8"
Expand All @@ -271,10 +213,7 @@ public function testTagWithAttributeAndNormalHTML(): void
public function testTagWithAttributeSelfClosingAndNormalHTML(): void
{
$element = '<c-youtube src="RLdsCL4RDf8" /><div>Test</div><input type="text"/>';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<iframe width="560" height="315"
src="https://www.youtube.com/embed/RLdsCL4RDf8"
Expand All @@ -293,10 +232,7 @@ public function testTagWithAttributeSelfClosingAndNormalHTML(): void
public function testDisabledTag(): void
{
$element = '<c-disabled />';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = '';
$this->assertSame($expected, $result);
}
Expand All @@ -309,10 +245,7 @@ public function testDisabledTag(): void
public function testNoCustomTag(): void
{
$element = '<div>This is a Test</div>';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = '<div>This is a Test</div>';
$this->assertSame($expected, $result);
}
Expand All @@ -325,15 +258,9 @@ public function testNoCustomTag(): void
public function testOutputBuffered(): void
{
$element = '<c-github></c-github>';
$tagEngine = new TagEngine([
'tag_directories' => [
__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR,
__DIR__ . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR,
],
]);
ob_start();
echo $element;
$result = $tagEngine->parse();
$result = $this->tagEngine->parse();
$expected = <<<HTML
This is a render from a plugin tag
Expand All @@ -346,10 +273,7 @@ public function testWithDivWrapped(): void
$element = '<div>
<c-youtube src="RLdsCL4RDf8"/>
</div>';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<div>
<iframe width="560" height="315"
Expand All @@ -365,10 +289,7 @@ public function testWithDivWrapped(): void
public function testSimpleTag(): void
{
$element = '<input type="text" />';
$tagEngine = new TagEngine([
'tag_directories' => [__DIR__ . DIRECTORY_SEPARATOR . 'Tags' . DIRECTORY_SEPARATOR],
]);
$result = $tagEngine->parse($element);
$result = $this->tagEngine->parse($element);
$expected = <<<HTML
<input type="text" />
HTML;
Expand Down

0 comments on commit 30ee0fc

Please sign in to comment.