summaryrefslogtreecommitdiff
path: root/platform/www/lib/plugins/bureaucracy/_test/actions_template.test.php
blob: befefc348ea8576439796cc002af14faba4d834f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
 * @group plugin_bureaucracy
 * @group plugins
 */
class syntax_plugin_bureaucracy_action_template_test extends DokuWikiTest {

    protected $pluginsEnabled = array('bureaucracy');

    public function testPrepareLanguagePlaceholderNoTranslate() {
        $action = $this->getTemplateClass();
        $action->prepareLanguagePlaceholder();

        $this->assertEquals('en', $action->values['__lang__']);
        $this->assertEquals('/@LANG@/', $action->patterns['__lang__']);
        $this->assertEquals('', $action->values['__trans__']);
        $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']);
    }

    public function testPrepareLanguagePlaceholderTranslateDefaultNS() {
        global $conf;
        global $ID;

        $conf['plugin']['translation']['translations'] = 'de';
        $ID = 'bla';

        plugin_enable('translation');
        if (null === plugin_load('helper', 'translation')) return;

        $action = $this->getTemplateClass();
        $action->prepareLanguagePlaceholder();

        $this->assertEquals('en', $action->values['__lang__']);
        $this->assertEquals('/@LANG@/', $action->patterns['__lang__']);
        $this->assertEquals('', $action->values['__trans__']);
        $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']);
    }

    public function testPrepareLanguagePlaceholderTranslateLanguageNS() {
        global $conf;
        global $ID;

        $conf['plugin']['translation']['translations'] = 'de';
        $ID = 'de:bla';

        plugin_enable('translation');
        $translation = plugin_load('helper', 'translation');
        if (null === $translation) return;

        $action = $this->getTemplateClass();
        $action->prepareLanguagePlaceholder();

        $this->assertEquals('en', $action->values['__lang__']);
        $this->assertEquals('/@LANG@/', $action->patterns['__lang__']);
        $this->assertEquals('de', $action->values['__trans__']);
        $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']);
    }

    public function testProcessFields() {
        $data = array();
        /** @var helper_plugin_bureaucracy_fieldstatic $staticfield */
        $staticfield = plugin_load('helper', 'bureaucracy_fieldstatic');
        $staticfield->initialize(array('text', 'text1'));
        $data[] = $staticfield;

        $action = $this->getTemplateClass();
        $action->prepareFieldReplacements($data, '_', '');

        $this->assertEquals('/(@@|##)text1(?:\|(.*?))\1/si', $action->patterns['text1']);
        $this->assertEquals('$2', $action->values['text1']);
        $this->assertEmpty($action->targetpages);
    }

    /**
     * @return helper_plugin_bureaucracy_actiontemplate
     */
    private function getTemplateClass() {
        /** @var helper_plugin_bureaucracy_actiontemplate $templateaction */
        $templateaction = plugin_load('helper', 'bureaucracy_actiontemplate');
        $templateaction->patterns = array();
        $templateaction->values = array();
        $templateaction->targetpages = array();
        $templateaction->pagename = array();
        return $templateaction;
    }


}