1<?php
2/**
3 * @group plugin_latexport
4 * @group plugins
5 */
6
7require_once DOKU_PLUGIN . 'latexport/_test/decorator_mock.php';
8require_once DOKU_PLUGIN . 'latexport/implementation/decorator_headings.php';
9
10class DecoratorHeadingsTest extends DokuWikiTest {
11
12    protected $pluginsEnabled = array('latexport', 'mathjax');
13
14	private $decoratorMock;
15
16	private $decoratorHeadings;
17
18    public static function setUpBeforeClass(){
19        parent::setUpBeforeClass();
20	}
21
22	public function setUp() {
23		$this->decoratorMock = new DecoratorMock();
24		$this->decoratorHeadings = new DecoratorHeadings($this->decoratorMock);
25    }
26
27    public function testFirstAndSecondH1AreH1AndNextAreH3() {
28		$this->decoratorHeadings->header("text1", 1, 10);	// This would open the main matter.
29		$this->decoratorHeadings->header("text2", 1, 20);	// This would open the appendix.
30		$this->decoratorHeadings->header("text3", 1, 30);	// This is a chapter in the appendix.
31		$this->decoratorHeadings->header("text4", 1, 40);   // This is a chapter in the appendix.
32
33		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text1", 1, 10));
34		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text2", 1, 20));
35		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text3", 3, 30));
36		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text4", 3, 40));
37
38		$this->assertTrue($this->decoratorMock->noCommands(), "Should not have more commands");
39    }
40
41    public function testH2BeforeH1AreChapters() {
42		$this->decoratorHeadings->header("text1", 2, 10);	// This is a chapter in the front matter.
43		$this->decoratorHeadings->header("text2", 2, 20);	// This is a chapter in the front matter.
44		$this->decoratorHeadings->header("text3", 1, 30);	// This opens the main matter.
45		$this->decoratorHeadings->header("text4", 2, 40);	// This is a section in the main matter.
46
47		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text1", 3, 10));
48		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text2", 3, 20));
49		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text3", 1, 30));
50		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text4", 2, 40));
51
52		$this->assertTrue($this->decoratorMock->noCommands(), "Should not have more commands");
53    }
54
55    public function testMinimumLevelIsH5() {
56		$this->decoratorHeadings->header("text1", 10, 10);
57		$this->assertEquals($this->decoratorMock->nextCommand(), new CommandHeader("text1", 5, 10));
58    }
59}
60?>
61