1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace eNTiDi\Autotoc\Tests; |
4
|
|
|
|
5
|
|
|
use eNTiDi\Autotoc\Tocifier; |
6
|
|
|
use PHPUnit_Framework_TestCase; |
7
|
|
|
|
8
|
|
|
class TocifierTest extends PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function testProcess() |
11
|
|
|
{ |
12
|
|
|
$tocifier = new Tocifier(1234); |
13
|
|
|
$this->assertFalse($tocifier->process()); |
14
|
|
|
|
15
|
|
|
$tocifier = new Tocifier(''); |
16
|
|
|
$this->assertFalse($tocifier->process()); |
17
|
|
|
|
18
|
|
|
$tocifier = new Tocifier(null); |
19
|
|
|
$this->assertFalse($tocifier->process()); |
20
|
|
|
|
21
|
|
|
$tocifier = new Tocifier(['1234']); |
|
|
|
|
22
|
|
|
$this->assertFalse($tocifier->process()); |
23
|
|
|
|
24
|
|
|
$tocifier = new Tocifier('1234'); |
25
|
|
|
$this->assertTrue($tocifier->process()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testPrependAnchor() |
29
|
|
|
{ |
30
|
|
|
$tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
31
|
|
|
$this->assertEquals('', $tocifier->getHtml()); |
32
|
|
|
|
33
|
|
|
$tocifier->setAugmentCallback(['\eNTiDi\Autotoc\Tocifier', 'prependAnchor']); |
34
|
|
|
$this->assertTrue($tocifier->process()); |
35
|
|
|
$this->assertStringEqualsFile(__DIR__.'/html1', $tocifier->getHtml()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testSetId() |
39
|
|
|
{ |
40
|
|
|
$tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
41
|
|
|
$this->assertEquals('', $tocifier->getHtml()); |
42
|
|
|
|
43
|
|
|
// The default augmenting method should already be setId |
44
|
|
|
$this->assertTrue($tocifier->process()); |
45
|
|
|
$this->assertStringEqualsFile(__DIR__.'/html2', $tocifier->getHtml()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function testTOC() |
49
|
|
|
{ |
50
|
|
|
$tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
51
|
|
|
$this->assertEquals([], $tocifier->getTOC()); |
52
|
|
|
$this->assertTrue($tocifier->process()); |
53
|
|
|
$this->assertNotNull($tocifier->getTOC()); |
54
|
|
|
|
55
|
|
|
ob_start(); |
56
|
|
|
$tocifier->dumpTOC(); |
57
|
|
|
$returned = ob_get_clean(); |
58
|
|
|
$this->assertStringEqualsFile(__DIR__.'/toc1', $returned); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
public function testDataHideFromTOC() |
62
|
|
|
{ |
63
|
|
|
$tocifier = new Tocifier(file_get_contents(__DIR__.'/test2')); |
64
|
|
|
$this->assertEquals('', $tocifier->getHtml()); |
65
|
|
|
$this->assertTrue($tocifier->process()); |
66
|
|
|
|
67
|
|
|
// Check the augmented HTML is equal to the original one |
68
|
|
|
$this->assertStringEqualsFile(__DIR__.'/test2', $tocifier->getHtml()); |
69
|
|
|
|
70
|
|
|
ob_start(); |
71
|
|
|
$tocifier->dumpTOC(); |
72
|
|
|
$returned = ob_get_clean(); |
73
|
|
|
$this->assertEquals("\n", $returned); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: