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