1<?php
2/*
3 * Yurii's Gantt Plugin
4 *
5 * Copyright (C) 2020 Yurii K.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program.  If not, see http://www.gnu.org/licenses
19 */
20
21use dokuwiki\plugin\yuriigantt\src\Driver\Embedded;
22use dokuwiki\plugin\yuriigantt\src\Driver\Embedded\Handler;
23use dokuwiki\plugin\yuriigantt\src\Driver\Embedded\Renderer;
24use dokuwiki\plugin\yuriigantt\src\Driver\Embedded\Lexer;
25
26/**
27 * @group plugin_yuriigantt
28 * @group plugins
29 */
30class plugin_yuriigantt_storage_test extends DokuWikiTest
31{
32    protected $pluginsEnabled = ['yuriigantt'];
33//
34//    public static function setUpBeforeClass(){
35//        parent::setUpBeforeClass();
36//        // copy our own config files to the test directory
37//        TestUtils::rcopy(dirname(DOKU_CONF), dirname(__FILE__).'/conf');
38//    }
39
40    public function testExample()
41    {
42        $rawPage = file_get_contents(dirname(__DIR__) . '/test_page.txt');
43
44        $handler = new Handler();
45        $lexer = new Lexer($handler, Embedded::MODE);
46        Embedded::addLexerPattern($lexer, Embedded::MODE);
47        $result = $lexer->parse($rawPage);
48        $instructions = $handler->calls;
49
50        // check instructions are correct
51        $this->assertTrue($result);
52        $this->assertEquals('raw', $instructions[0][0]);
53        $this->assertEquals('plugin', $instructions[1][0]);
54        $this->assertEquals('yuriigantt', $instructions[1][1][0]);
55        $this->assertInstanceOf(stdClass::class, $instructions[1][1][1]);
56        $this->assertStringStartsWith('~~~~GANTT~~~~', $instructions[1][1][3]);
57        $this->assertStringEndsWith('~~~~~~~~~~~', $instructions[1][1][3]);
58        $this->assertEquals('raw', $instructions[2][0]);
59        $this->assertEquals("\n\n\nzzz\n", $instructions[2][1][0]);
60
61        // check output is same if nothing was updated
62        $renderer = new Renderer();
63        foreach ($instructions as $instruction) {
64            call_user_func_array(array(&$renderer, $instruction[0]), $instruction[1] ? $instruction[1] : array());
65        }
66        //file_put_contents(__DIR__.'/test_page_output.txt', $renderer->doc);
67        $this->assertEquals($renderer->doc, $rawPage);
68
69        // check database
70        $database = $handler->getDatabase();
71        $this->assertIsObject($database);
72        $this->assertEquals($database->pageId, 'asd');
73        $this->assertEquals($database->version, '1.0');
74        $this->assertEquals($database->dsn, Embedded::DSN);
75        $this->assertEquals($database->dsn, Embedded::DSN);
76        $this->assertEquals($database->increment->task, 12);
77        $this->assertEquals($database->increment->link, 8);
78    }
79}
80