xref: /plugin/struct/_test/ConfigHelperTest.php (revision 8fed17f342cc190557a6ce94d1787f9e2f63cb6c)
1*8fed17f3SAndreas Gohr<?php
2*8fed17f3SAndreas Gohr
3*8fed17f3SAndreas Gohrnamespace dokuwiki\plugin\struct\test;
4*8fed17f3SAndreas Gohr
5*8fed17f3SAndreas Gohr/**
6*8fed17f3SAndreas Gohr * @group plugin_struct
7*8fed17f3SAndreas Gohr * @group plugins
8*8fed17f3SAndreas Gohr *
9*8fed17f3SAndreas Gohr */
10*8fed17f3SAndreas Gohrclass ConfigHelperTest extends StructTest
11*8fed17f3SAndreas Gohr{
12*8fed17f3SAndreas Gohr
13*8fed17f3SAndreas Gohr    public static function filter_testdata()
14*8fed17f3SAndreas Gohr    {
15*8fed17f3SAndreas Gohr        return [
16*8fed17f3SAndreas Gohr            ['a=b', [0 => 'a', 1 => '=', 2 => 'b'], false, ''],
17*8fed17f3SAndreas Gohr            ['a<b', [0 => 'a', 1 => '<', 2 => 'b'], false, ''],
18*8fed17f3SAndreas Gohr            ['a>b', [0 => 'a', 1 => '>', 2 => 'b'], false, ''],
19*8fed17f3SAndreas Gohr            ['a<=b', [0 => 'a', 1 => '<=', 2 => 'b'], false, ''],
20*8fed17f3SAndreas Gohr            ['a>=b', [0 => 'a', 1 => '>=', 2 => 'b'], false, ''],
21*8fed17f3SAndreas Gohr            ['a!=b', [0 => 'a', 1 => '!=', 2 => 'b'], false, ''],
22*8fed17f3SAndreas Gohr            ['a<>b', [0 => 'a', 1 => '<>', 2 => 'b'], false, ''],
23*8fed17f3SAndreas Gohr            ['a!~b', [0 => 'a', 1 => '!~', 2 => 'b'], false, ''],
24*8fed17f3SAndreas Gohr            ['a~b', [0 => 'a', 1 => '~', 2 => 'b'], false, ''],
25*8fed17f3SAndreas Gohr            ['a*~b', [0 => 'a', 1 => '*~', 2 => 'b'], false, ''],
26*8fed17f3SAndreas Gohr            ['a?b', [], '\dokuwiki\plugin\struct\meta\StructException', 'Exception should be thrown on unknown operator']
27*8fed17f3SAndreas Gohr        ];
28*8fed17f3SAndreas Gohr    }
29*8fed17f3SAndreas Gohr
30*8fed17f3SAndreas Gohr    /**
31*8fed17f3SAndreas Gohr     * @dataProvider filter_testdata
32*8fed17f3SAndreas Gohr     *
33*8fed17f3SAndreas Gohr     * @param $input_filter
34*8fed17f3SAndreas Gohr     * @param $expected_filter
35*8fed17f3SAndreas Gohr     * @param string $msg
36*8fed17f3SAndreas Gohr     */
37*8fed17f3SAndreas Gohr    public function test_parseFilter($input_filter, $expected_filter, $expectException, $msg)
38*8fed17f3SAndreas Gohr    {
39*8fed17f3SAndreas Gohr        $confHelper = new mock\helper_plugin_struct_config();
40*8fed17f3SAndreas Gohr        if ($expectException !== false) $this->setExpectedException($expectException);
41*8fed17f3SAndreas Gohr
42*8fed17f3SAndreas Gohr        $actual_filter = $confHelper->parseFilter($input_filter);
43*8fed17f3SAndreas Gohr
44*8fed17f3SAndreas Gohr        $this->assertSame($expected_filter, $actual_filter, $input_filter . ' ' . $msg);
45*8fed17f3SAndreas Gohr    }
46*8fed17f3SAndreas Gohr
47*8fed17f3SAndreas Gohr    public function test_parseSort_asc()
48*8fed17f3SAndreas Gohr    {
49*8fed17f3SAndreas Gohr        /** @var \helper_plugin_struct_config $confHelper */
50*8fed17f3SAndreas Gohr        $confHelper = plugin_load('helper', 'struct_config');
51*8fed17f3SAndreas Gohr        $teststring = "column";
52*8fed17f3SAndreas Gohr
53*8fed17f3SAndreas Gohr        $actual_sort = $confHelper->parseSort($teststring);
54*8fed17f3SAndreas Gohr
55*8fed17f3SAndreas Gohr        $this->assertEquals([$teststring, true], $actual_sort);
56*8fed17f3SAndreas Gohr    }
57*8fed17f3SAndreas Gohr
58*8fed17f3SAndreas Gohr    public function test_parseSort_desc()
59*8fed17f3SAndreas Gohr    {
60*8fed17f3SAndreas Gohr        /** @var \helper_plugin_struct_config $confHelper */
61*8fed17f3SAndreas Gohr        $confHelper = plugin_load('helper', 'struct_config');
62*8fed17f3SAndreas Gohr        $teststring = "^column";
63*8fed17f3SAndreas Gohr
64*8fed17f3SAndreas Gohr        $actual_sort = $confHelper->parseSort($teststring);
65*8fed17f3SAndreas Gohr
66*8fed17f3SAndreas Gohr        $this->assertEquals(['column', false], $actual_sort);
67*8fed17f3SAndreas Gohr    }
68*8fed17f3SAndreas Gohr}
69