1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class TocifierTest extends PHPUnit_Framework_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
public function testProcess() |
6
|
|
|
{ |
7
|
|
|
$tocifier = new Tocifier(1234); |
8
|
|
|
$this->assertFalse($tocifier->process()); |
9
|
|
|
|
10
|
|
|
$tocifier = new Tocifier(''); |
11
|
|
|
$this->assertFalse($tocifier->process()); |
12
|
|
|
|
13
|
|
|
$tocifier = new Tocifier(null); |
14
|
|
|
$this->assertFalse($tocifier->process()); |
15
|
|
|
|
16
|
|
|
$tocifier = new Tocifier(array('1234')); |
|
|
|
|
17
|
|
|
$this->assertFalse($tocifier->process()); |
18
|
|
|
|
19
|
|
|
$tocifier = new Tocifier('1234'); |
20
|
|
|
$this->assertTrue($tocifier->process()); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function testHtml() |
24
|
|
|
{ |
25
|
|
|
$tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1')); |
26
|
|
|
$this->assertEquals($tocifier->getHtml(), ''); |
27
|
|
|
$this->assertTrue($tocifier->process()); |
28
|
|
|
$this->assertStringEqualsFile(__DIR__ . '/html1', $tocifier->getHtml()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testTOC() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1')); |
34
|
|
|
$this->assertEquals($tocifier->getTOC(), array()); |
35
|
|
|
$this->assertTrue($tocifier->process()); |
36
|
|
|
$this->assertNotNull($tocifier->getTOC()); |
37
|
|
|
|
38
|
|
|
ob_start(); |
39
|
|
|
$tocifier->dumpTOC(); |
40
|
|
|
$returned = ob_get_clean(); |
41
|
|
|
$this->assertStringEqualsFile(__DIR__ . '/toc1', $returned); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testDataHideFromTOC() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$tocifier = new Tocifier(file_get_contents(__DIR__ . '/test2')); |
47
|
|
|
$this->assertEquals($tocifier->getHtml(), ''); |
48
|
|
|
$this->assertTrue($tocifier->process()); |
49
|
|
|
|
50
|
|
|
// Check the augmented HTML is equal to the original one |
51
|
|
|
$this->assertStringEqualsFile(__DIR__ . '/test2', $tocifier->getHtml()); |
52
|
|
|
|
53
|
|
|
ob_start(); |
54
|
|
|
$tocifier->dumpTOC(); |
55
|
|
|
$returned = ob_get_clean(); |
56
|
|
|
$this->assertEquals("\n", $returned); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.