1<?php
2
3require_once(__DIR__ . '/../webcomponent.php');
4
5/**
6 * Test the component plugin
7 *
8 * @group plugin_webcomponent
9 * @group plugins
10 */
11class plugin_webcomponent_button_test extends DokuWikiTest
12{
13
14    protected $pluginsEnabled = [webcomponent::PLUGIN_NAME];
15
16
17    public function test_component_name()
18    {
19
20        $componentName = syntax_plugin_webcomponent_button::getTag();
21
22        $this->assertEquals('button', $componentName);
23
24    }
25
26    public function test_base()
27    {
28
29        // https://getbootstrap.com/docs/4.3/components/card/#using-custom-css
30        $elements = syntax_plugin_webcomponent_button::getTags();
31        $link_content = 'Go Somewhere';
32        $expected = '<a href="/./doku.php?id=:namespace:page%23section" class="btn btn-primary">' . $link_content . '</a>';
33        $info = array();
34        foreach ($elements as $element) {
35            $doku_text = '<' . $element . '>' . '[[:namespace:page#section|' . $link_content . ']]' . '</' . $element . '>';
36            $instructions = p_get_instructions($doku_text);
37            $xhtml = p_render('xhtml', $instructions, $info);
38            $this->assertEquals($expected, $xhtml);
39        }
40
41    }
42
43    public function test_indexer()
44    {
45
46        $pageIdReferent = webcomponent::getNameSpace().'referrer';
47        $pageId =  webcomponent::getNameSpace() . 'test_indexer';
48
49
50        $element = syntax_plugin_webcomponent_button::getTags()[0];
51        $doku_text = '<' . $element . '>' . '[['.$pageIdReferent.']]' . '</' . $element . '>';
52
53
54        saveWikiText($pageIdReferent, 'Not null', 'test_indexer test base');
55        idx_addPage($pageIdReferent);
56
57
58        saveWikiText($pageId, $doku_text, 'test_indexer test base');
59        idx_addPage($pageId);
60
61        $backlinks = ft_backlinks($pageIdReferent);
62        $expected = 1;
63        $this->assertEquals($expected, sizeof($backlinks));
64
65
66    }
67
68
69}
70