-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
12 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test; | ||
|
||
use Gt\DomTemplate\HTMLDocument; | ||
use Gt\DomTemplate\Test\Helper\Helper; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class HTMLDocumentTest extends TestCase { | ||
public function testTemplateExtractWithNoTemplatesCount() { | ||
$document = new HTMLDocument(Helper::HTML_NO_TEMPLATES); | ||
$count = $document->extractTemplates(); | ||
self::assertEquals(0, $count); | ||
} | ||
|
||
public function testTemplateExtractWithNoTemplatesDoesNotAffectContent() { | ||
$document = new HTMLDocument(Helper::HTML_NO_TEMPLATES); | ||
$nodeList = $document->querySelectorAll("*"); | ||
$document->extractTemplates(); | ||
$newNodeList = $document->querySelectorAll("*"); | ||
self::assertCount(count($nodeList), $newNodeList); | ||
} | ||
|
||
public function testTemplateExtractCount() { | ||
$document = new HTMLDocument(Helper::HTML_TEMPLATES); | ||
$count = $document->extractTemplates(); | ||
self::assertEquals(3, $count); | ||
} | ||
|
||
public function testTemplateExtractRemovesTemplates() { | ||
$document = new HTMLDocument(Helper::HTML_TEMPLATES); | ||
$templateElements = $document->querySelectorAll("template,[data-template]"); | ||
self::assertGreaterThan(0, count($templateElements)); | ||
$document->extractTemplates(); | ||
$newTemplateElements = $document->querySelectorAll("template,[data-template]"); | ||
self::assertEquals(0, count($newTemplateElements)); | ||
} | ||
|
||
// public function testTemplateGet() { | ||
// | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
namespace Gt\DomTemplate\Test\Helper; | ||
|
||
class Helper { | ||
const HTML_NO_TEMPLATES = <<<HTML | ||
<!doctype html> | ||
<meta charset="utf-8" /> | ||
<title>This document has no templates</title> | ||
<main> | ||
<section> | ||
<h1>Hello, World!</h1> | ||
<p> | ||
Lorem ipsum dolor sit amet, consectetur adipisicing elit. A aliquam animi | ||
deleniti distinctio dolore doloremque, eius et facilis iure maiores nihil | ||
nisi, nostrum optio perferendis perspiciatis, rerum vitae voluptates. | ||
</p> | ||
</section> | ||
</main> | ||
HTML; | ||
|
||
const HTML_TEMPLATES = <<<HTML | ||
<!doctype html> | ||
<meta charset="utf-8" /> | ||
<title>This document has some templates</title> | ||
<main> | ||
<section> | ||
<h1>Hello, World!</h1> | ||
<ul> | ||
<li data-template="list-item">This is a list item</li> | ||
</ul> | ||
<p> | ||
Above this paragraph is an unordered list, with the LI elements templated. | ||
</p> | ||
<dl> | ||
<template id="title-definition"> | ||
<dt>Title</dt> | ||
<dd>Definition</dd> | ||
</template> | ||
</dl> | ||
<p> | ||
Above this paragraph is a definition list, with a template element wrapping the elements to extract. | ||
</p> | ||
<p> | ||
Below is an ordered list with the LI elements templated. | ||
</p> | ||
<ol> | ||
<li data-template="ordered-list-item">This is an item in the second list</li> | ||
</ol> | ||
</section> | ||
</main> | ||
HTML; | ||
|
||
|
||
} |