1<?php
2/**
3 * tests or the class helper_plugin_publish of the publish plugin
4 *
5 * @group plugin_publish
6 * @group plugins
7 */
8class helper_plugin_publish_test extends DokuWikiTest {
9
10    public function setUp(): void
11    {
12        parent::setUp();
13    }
14
15    protected $pluginsEnabled = array('publish',);
16
17
18    /**
19     * Testdata for @see helper_plugin_publish_test::test_in_namespace
20     *
21     * @return array
22     */
23    public function in_namespace_testdata() {
24        return array(
25            array("de:sidebar en:sidebar", 'de:sidebar', true, ''),
26            array("de:sidebar en:sidebar", 'en:sidebar', true, ''),
27            array("de:sidebar en:sidebar", 'en:sidebar:', true, ''),
28            array("de:sidebar en:sidebar", 'en:sidebar:start', true, ''),
29            array("de:sidebar en:sidebar", 'en:sidebar:namespace:start', true, ''),
30            array("de:sidebar en:sidebar", 'en:', false, ''),
31            array("de:sidebar en:sidebar", '', false, ''),
32            array("", 'foo:bar', true, ''),
33        );
34    }
35
36    /**
37     * @dataProvider in_namespace_testdata
38     *
39     * @param $namespace_list
40     * @param $id
41     * @param $result
42     * @param $msg
43     */
44    public function test_in_namespace($namespace_list, $id, $result, $msg) {
45
46        /** @var helper_plugin_publish $helper */
47        $helper = plugin_load('helper', 'publish');
48        $this->assertSame($helper->in_namespace($namespace_list,$id),$result,$msg);
49    }
50
51    /**
52     * Testdata for @see helper_plugin_publish_test::test_in_sub_namespace
53     *
54     * @return array
55     */
56    public function in_sub_namespace_testdata() {
57        return array(
58            array("de:sidebar en:sidebar", 'de:sidebar', true, ''),
59            array("de:sidebar en:sidebar", 'en:sidebar', true, ''),
60            array("de:sidebar en:sidebar", 'en:sidebar:', true, ''),
61            array("de:sidebar en:sidebar", 'en:sidebar:start', true, ''),
62            array("de:sidebar en:sidebar", 'en:sidebar:namespace:start', true, ''),
63            array("de:sidebar en:sidebar", 'en:', true, ''),
64            array("de:sidebar en:sidebar", '', false, ''),
65            array("", 'foo:bar', true, ''),
66        );
67    }
68
69    /**
70     * @dataProvider in_sub_namespace_testdata
71     *
72     * @param $namespace_list
73     * @param $id
74     * @param $result
75     * @param $msg
76     */
77    public function test_in_sub_namespace($namespace_list, $id, $result, $msg) {
78
79        /** @var helper_plugin_publish $helper */
80        $helper = plugin_load('helper', 'publish');
81        $this->assertSame($helper->is_dir_valid($namespace_list,$id),$result,$msg);
82    }
83
84    public function test_isActive() {
85        global $conf;
86
87        $conf['plugin']['publish']['no_apr_namespaces'] = 'de:sidebar en:sidebar';
88
89        /** @var helper_plugin_publish $helper */
90        $helper = plugin_load('helper', 'publish');
91
92        $this->assertFalse($helper->isActive('de:sidebar'), 'de:sidebar is still listed as active');
93        $this->assertFalse($helper->isActive('en:sidebar'), 'en:sidebar is still listed as active');
94    }
95
96}
97