Skip to content

Commit

Permalink
Begin basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Dec 22, 2017
1 parent a1ec21f commit 361e461
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 12 deletions.
12 changes: 0 additions & 12 deletions test/unit/DocumentTest.php

This file was deleted.

41 changes: 41 additions & 0 deletions test/unit/HTMLDocumentTest.php
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() {
//
// }
}
54 changes: 54 additions & 0 deletions test/unit/Helper/Helper.php
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;


}

0 comments on commit 361e461

Please sign in to comment.