Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests PSR compatible #34

Merged
merged 5 commits into from
May 15, 2014
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@
},
"autoload": {
"psr-0": {"HTML5": "src"}
}
},
"autoload-dev": {
"psr-4": {"HTML5\\Tests\\": "test/HTML5"}
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<phpunit colors="true" bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="PHPUnit">
<directory>test/HTML5/</directory>
Expand Down
2 changes: 0 additions & 2 deletions test/HTML5/ElementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

use \HTML5\Elements;

require_once 'TestCase.php';

class ElementsTest extends TestCase {

public $html5Elements = array(
Expand Down
2 changes: 0 additions & 2 deletions test/HTML5/Html5Test.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?php
namespace HTML5\Tests;

require_once 'TestCase.php';

class Html5Test extends TestCase {

/**
Expand Down
5 changes: 2 additions & 3 deletions test/HTML5/Parser/CharacterReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
* @file
* Test the Scanner. This requires the InputStream tests are all good.
*/
namespace HTML5\Parser;

require_once __DIR__ . '/../TestCase.php';
namespace HTML5\Tests\Parser;

use HTML5\Parser\CharacterReference;
class CharacterReferenceTest extends \HTML5\Tests\TestCase {
public function testLookupName() {
$this->assertEquals('&', CharacterReference::lookupName('amp'));
Expand Down
16 changes: 8 additions & 8 deletions test/HTML5/Parser/DOMTreeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
* @file
* Test the Tree Builder.
*/
namespace HTML5\Parser;
namespace HTML5\Tests\Parser;

use HTML5\Elements;

require_once __DIR__ . '/../TestCase.php';
use HTML5\Parser\StringInputStream;
use HTML5\Parser\Scanner;
use HTML5\Parser\Tokenizer;
use HTML5\Parser\DOMTreeBuilder;

/**
* These tests are functional, not necessarily unit tests.
Expand Down Expand Up @@ -108,7 +110,7 @@ public function testSVGAttributes() {
<svg width='150' viewbox='2'>
<rect textlength='2'/>
<animatecolor>foo</animatecolor>
</svg>
</svg>
</body></html>";
$doc = $this->parse($html);
$root = $doc->documentElement;
Expand Down Expand Up @@ -208,7 +210,7 @@ public function testParseErrors() {
$html = "<!DOCTYPE html><html><math><![CDATA[test";
$doc = $this->parse($html);

// We're JUST testing that we can access errors. Actual testing of
// We're JUST testing that we can access errors. Actual testing of
// error messages happen in the Tokenizer's tests.
$this->assertGreaterThan(0, count($doc->errors));
$this->assertTrue(is_string($doc->errors[0]));
Expand Down Expand Up @@ -344,9 +346,7 @@ public function testInstructionProcessor() {
$this->assertEquals('div', $div->tagName);
$this->assertEquals('foo', $div->textContent);
}
}

class InstructionProcessorMock implements \HTML5\InstructionProcessor {
}class InstructionProcessorMock implements \HTML5\InstructionProcessor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing bracket for the class and the definition for the next class should be on different lines.


public $name = NULL;
public $data = NULL;
Expand Down
3 changes: 2 additions & 1 deletion test/HTML5/Parser/EventStack.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace HTML5\Parser;
namespace HTML5\Tests\Parser;

use HTML5\Elements;
use HTML5\Parser\EventHandler;

/**
* This testing class gathers events from a parser and builds a stack of events.
Expand Down
6 changes: 2 additions & 4 deletions test/HTML5/Parser/FileInputStreamTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
namespace HTML5\Tests;
namespace HTML5\Tests\Parser;

use \HTML5\Parser\FileInputStream;

require_once __DIR__ . '/../TestCase.php';

class FileInputStreamTest extends \HTML5\Tests\TestCase {

function testConstruct() {
Expand Down Expand Up @@ -61,7 +59,7 @@ public function testColumnOffset() {
$this->assertEquals(2, $s->columnOffset());
$s->next();
$this->assertEquals(3, $s->columnOffset());

// Make sure we get to the second line
$s->next(); $s->next(); $s->next(); $s->next();
$s->next(); $s->next(); $s->next(); $s->next();
Expand Down
2 changes: 0 additions & 2 deletions test/HTML5/Parser/ScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use \HTML5\Parser\StringInputStream;
use \HTML5\Parser\Scanner;

require_once __DIR__ . '/../TestCase.php';

class ScannerTest extends \HTML5\Tests\TestCase {

/**
Expand Down
16 changes: 7 additions & 9 deletions test/HTML5/Parser/StringInputStreamTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php
namespace HTML5\Tests;
namespace HTML5\Tests\Parser;

use \HTML5\Parser\StringInputStream;

require_once __DIR__ . '/../TestCase.php';

class StringInputStreamTest extends \HTML5\Tests\TestCase {

/**
Expand Down Expand Up @@ -218,7 +216,7 @@ public function testInvalidReplace() {
}

// MPB:
// It appears that iconv just leaves these alone. Not sure what to
// It appears that iconv just leaves these alone. Not sure what to
// do.
/*
$converted = array(
Expand Down Expand Up @@ -263,19 +261,19 @@ public function testInvalidParseError() {
$this->invalidParseErrorTestHandler("\x1D", 1, 'U+001D (C0 control)');
$this->invalidParseErrorTestHandler("\x1E", 1, 'U+001E (C0 control)');
$this->invalidParseErrorTestHandler("\x1F", 1, 'U+001F (C0 control)');

// DEL (U+007F)
$this->invalidParseErrorTestHandler("\x7F", 1, 'U+007F');

// C1 Controls
$this->invalidParseErrorTestHandler("\xC2\x80", 1, 'U+0080 (C1 control)');
$this->invalidParseErrorTestHandler("\xC2\x9F", 1, 'U+009F (C1 control)');
$this->invalidParseErrorTestHandler("\xC2\xA0", 0, 'U+00A0 (first codepoint above highest C1 control)');

// Charcters surrounding surrogates
$this->invalidParseErrorTestHandler("\xED\x9F\xBF", 0, 'U+D7FF (one codepoint below lowest surrogate codepoint)');
$this->invalidParseErrorTestHandler("\xEF\xBF\xBD", 0, 'U+DE00 (one codepoint above highest surrogate codepoint)');

// Permanent noncharacters
$this->invalidParseErrorTestHandler("\xEF\xB7\x90", 1, 'U+FDD0 (permanent noncharacter)');
$this->invalidParseErrorTestHandler("\xEF\xB7\xAF", 1, 'U+FDEF (permanent noncharacter)');
Expand Down Expand Up @@ -325,7 +323,7 @@ public function testInvalidParseError() {
$this->invalidParseErrorTestHandler("\xED\xB0\x80", 1, 'U+DC00 (UTF-16 surrogate character)');
$this->invalidParseErrorTestHandler("\xED\xBE\x80", 1, 'U+DF80 (UTF-16 surrogate character)');
$this->invalidParseErrorTestHandler("\xED\xBF\xBF", 1, 'U+DFFF (UTF-16 surrogate character)');

// Paired UTF-16 surrogates
$this->invalidParseErrorTestHandler("\xED\xA0\x80\xED\xB0\x80", 2, 'U+D800 U+DC00 (paired UTF-16 surrogates)');
$this->invalidParseErrorTestHandler("\xED\xA0\x80\xED\xBF\xBF", 2, 'U+D800 U+DFFF (paired UTF-16 surrogates)');
Expand Down
20 changes: 11 additions & 9 deletions test/HTML5/Parser/TokenizerTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php
namespace HTML5\Parser;
require_once __DIR__ . '/../TestCase.php';
require 'EventStack.php';
namespace HTML5\Tests\Parser;

class TokenizerTest extends \HTML5\Tests\TestCase {
use HTML5\Parser\UTF8Utils;
use HTML5\Parser\StringInputStream;
use HTML5\Parser\Scanner;
use HTML5\Parser\Tokenizer;
require 'EventStack.php';class TokenizerTest extends \HTML5\Tests\TestCase {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The require and class definition should be on different lines.

// ================================================================
// Additional assertions.
// ================================================================
Expand Down Expand Up @@ -109,7 +111,7 @@ public function testCharacterReference() {
$e1 = $events->get(0);
$this->assertEquals('error', $e1['name']);

// FIXME: Once the text processor is done, need to verify that the
// FIXME: Once the text processor is done, need to verify that the
// tokens are transformed correctly into text.
}

Expand Down Expand Up @@ -139,12 +141,12 @@ public function testEndTag() {
$succeed = array(
'</a>' => 'a',
'</test>' => 'test',
'</test
'</test
>' => 'test',
'</thisIsTheTagThatDoesntEndItJustGoesOnAndOnMyFriend>' =>
'thisIsTheTagThatDoesntEndItJustGoesOnAndOnMyFriend',
// See 8.2.4.10, which requires this and does not say error.
'</a<b>' => 'a<b',
'</a<b>' => 'a<b',
);
$this->isAllGood('endTag', 2, $succeed);

Expand Down Expand Up @@ -271,8 +273,8 @@ public function testDoctype() {
public function testProcessorInstruction() {
$good = array(
'<?hph ?>' => 'hph',
'<?hph echo "Hello World"; ?>' => array('hph', 'echo "Hello World"; '),
"<?hph \necho 'Hello World';\n?>" => array('hph', "echo 'Hello World';\n"),
'<?hph echo "Hello World"; ?>' => array('hph', 'echo "Hello World"; '),
"<?hph \necho 'Hello World';\n?>" => array('hph', "echo 'Hello World';\n"),
);
$this->isAllGood('pi', 2, $good);
}
Expand Down
9 changes: 7 additions & 2 deletions test/HTML5/Parser/TreeBuildingRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
* @file
* Test the Tree Builder's special-case rules.
*/
namespace HTML5\Parser;
namespace HTML5\Tests\Parser;

use HTML5\Elements;
use HTML5\Parser\TreeBuildingRules;
use HTML5\Parser\Tokenizer;
use HTML5\Parser\Scanner;
use HTML5\Parser\StringInputStream;
use HTML5\Parser\DOMTreeBuilder;


require_once __DIR__ . '/../TestCase.php';

/**
* These tests are functional, not necessarily unit tests.
Expand Down
6 changes: 2 additions & 4 deletions test/HTML5/Serializer/OutputRulesTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php
namespace HTML5\Tests;
namespace HTML5\Tests\Serializer;

use \HTML5\Serializer\OutputRules;
use \HTML5\Serializer\Traverser;
use \HTML5\Parser;

require_once __DIR__ . '/../TestCase.php';

class OutputRulesTest extends \HTML5\Tests\TestCase {

protected $markup = '<!doctype html>
Expand All @@ -22,7 +20,7 @@ class OutputRulesTest extends \HTML5\Tests\TestCase {

/**
* Using reflection we make a protected method accessible for testing.
*
*
* @param string $name
* The name of the method on the Traverser class to test.
*
Expand Down
6 changes: 2 additions & 4 deletions test/HTML5/Serializer/TraverserTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?php
namespace HTML5\Tests;
namespace HTML5\Tests\Serializer;

use \HTML5\Serializer\OutputRules;
use \HTML5\Serializer\Traverser;
use \HTML5\Parser;

require_once __DIR__ . '/../TestCase.php';

class TraverserTest extends \HTML5\Tests\TestCase {

protected $markup = '<!doctype html>
Expand All @@ -22,7 +20,7 @@ class TraverserTest extends \HTML5\Tests\TestCase {

/**
* Using reflection we make a protected method accessible for testing.
*
*
* @param string $name
* The name of the method on the Traverser class to test.
*
Expand Down
3 changes: 0 additions & 3 deletions test/HTML5/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?php
namespace HTML5\Tests;

require_once 'PHPUnit/Autoload.php';
require_once __DIR__ . '/../../vendor/autoload.php';

class TestCase extends \PHPUnit_Framework_TestCase {
const DOC_OPEN = '<!DOCTYPE html><html><head><title>test</title></head><body>';
const DOC_CLOSE = '</body></html>';
Expand Down