silverstripe-autotoc 

silverstripe-autotoc Git Source Tree

Root/tests/TocifierTest.php

1<?php
2
3namespace eNTiDi\Autotoc\Tests;
4
5use eNTiDi\Autotoc\Tocifier;
6use PHPUnit_Framework_TestCase;
7
8class 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(array('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(array('\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 public function testTOC()
49 {
50 $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1'));
51 $this->assertEquals(array(), $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 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}

Archive Download this file