1<?php
2/**
3 * @group plugin_bureaucracy
4 * @group plugins
5 */
6class syntax_plugin_bureaucracy_action_template_test extends DokuWikiTest {
7
8    protected $pluginsEnabled = array('bureaucracy');
9
10    public function testPrepareLanguagePlaceholderNoTranslate() {
11        $action = $this->getTemplateClass();
12        $action->prepareLanguagePlaceholder();
13
14        $this->assertEquals('en', $action->values['__lang__']);
15        $this->assertEquals('/@LANG@/', $action->patterns['__lang__']);
16        $this->assertEquals('', $action->values['__trans__']);
17        $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']);
18    }
19
20    public function testPrepareLanguagePlaceholderTranslateDefaultNS() {
21        global $conf;
22        global $ID;
23
24        $conf['plugin']['translation']['translations'] = 'de';
25        $ID = 'bla';
26
27        plugin_enable('translation');
28        if (null === plugin_load('helper', 'translation')) return;
29
30        $action = $this->getTemplateClass();
31        $action->prepareLanguagePlaceholder();
32
33        $this->assertEquals('en', $action->values['__lang__']);
34        $this->assertEquals('/@LANG@/', $action->patterns['__lang__']);
35        $this->assertEquals('', $action->values['__trans__']);
36        $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']);
37    }
38
39    public function testPrepareLanguagePlaceholderTranslateLanguageNS() {
40        global $conf;
41        global $ID;
42
43        $conf['plugin']['translation']['translations'] = 'de';
44        $ID = 'de:bla';
45
46        plugin_enable('translation');
47        $translation = plugin_load('helper', 'translation');
48        if (null === $translation) return;
49
50        $action = $this->getTemplateClass();
51        $action->prepareLanguagePlaceholder();
52
53        $this->assertEquals('en', $action->values['__lang__']);
54        $this->assertEquals('/@LANG@/', $action->patterns['__lang__']);
55        $this->assertEquals('de', $action->values['__trans__']);
56        $this->assertEquals('/@TRANS@/', $action->patterns['__trans__']);
57    }
58
59    public function testProcessFields() {
60        $data = array();
61        /** @var helper_plugin_bureaucracy_fieldstatic $staticfield */
62        $staticfield = plugin_load('helper', 'bureaucracy_fieldstatic');
63        $staticfield->initialize(array('text', 'text1'));
64        $data[] = $staticfield;
65
66        $action = $this->getTemplateClass();
67        $action->prepareFieldReplacements($data, '_', '');
68
69        $this->assertEquals('/(@@|##)text1(?:\|(.*?))\1/si', $action->patterns['text1']);
70        $this->assertEquals('$2', $action->values['text1']);
71        $this->assertEmpty($action->targetpages);
72    }
73
74    /**
75     * @return helper_plugin_bureaucracy_actiontemplate
76     */
77    private function getTemplateClass() {
78        /** @var helper_plugin_bureaucracy_actiontemplate $templateaction */
79        $templateaction = plugin_load('helper', 'bureaucracy_actiontemplate');
80        $templateaction->patterns = array();
81        $templateaction->values = array();
82        $templateaction->targetpages = array();
83        $templateaction->pagename = array();
84        return $templateaction;
85    }
86
87
88}
89