1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
<?php
namespace HTML5\Tests;
use \HTML5\Serializer\Traverser;
use \HTML5\Parser;
require_once __DIR__ . '/../TestCase.php';
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.
*
* @return \ReflectionMethod
* \ReflectionMethod for the specified method
*/
function getProtectedMethod($name) {
$class = new \ReflectionClass('\HTML5\Serializer\Traverser');
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
public function testIsBlock() {
$blocks = array('html', 'body', 'head', 'p', 'div', 'h1', 'h2', 'h3', 'h4',
'h5', 'h6', 'title', 'script', 'link', 'meta', 'section', 'article',
'table', 'tbody', 'tr', 'th', 'td',
//'form',
);
// Mocking the required input because there is no checking.
$t = new Traverser('', '');
$method = $this->getProtectedMethod('isBlock');
foreach ($blocks as $block) {
$this->assertTrue($method->invoke($t, $block), 'Block test failed on: ' . $block);
// Also test the uppercase version.
$this->assertTrue($method->invoke($t, strtoupper($block)), 'Block test failed on: ' . strtoupper($block));
}
$nonblocks = array('span', 'a', 'img');
foreach ($nonblocks as $tag) {
$this->assertFalse($method->invoke($t, $tag), 'Block test failed on: ' . $tag);
// Also test the uppercase version.
$this->assertFalse($method->invoke($t, strtoupper($tag)), 'Block test failed on: ' . strtoupper($tag));
}
}
public function testIsUnary() {
$elements = array( 'area', 'base', 'basefont', 'bgsound', 'br', 'col',
'command', 'embed', 'frame', 'hr', 'img',
);
// Mocking the required input because there is no checking.
$t = new Traverser('', '');
$method = $this->getProtectedMethod('isUnary');
foreach ($elements as $element) {
$this->assertTrue($method->invoke($t, $element), 'Unary test failed on: ' . $element);
// Also test the uppercase version.
$this->assertTrue($method->invoke($t, strtoupper($element)), 'Unary test failed on: ' . strtoupper($element));
}
$nonblocks = array('span', 'a', 'div');
foreach ($nonblocks as $tag) {
$this->assertFalse($method->invoke($t, $tag), 'Unary test failed on: ' . $tag);
// Also test the uppercase version.
$this->assertFalse($method->invoke($t, strtoupper($tag)), 'Unary test failed on: ' . strtoupper($tag));
}
}
}
|