xref: /dokuwiki/_test/tests/Ui/SearchTest.php (revision f9a94e78392d6a178b0e7f29a005688fc44e5cc3)
1<?php
2
3namespace dokuwiki\test\Ui;
4
5class SearchTest extends \DokuWikiTest
6{
7
8    /**
9     * @return array
10     */
11    function dataProvider()
12    {
13        return [
14            [
15                [
16                    'query' => 'foo',
17                    'parsed_str' => '(W+:foo)',
18                    'parsed_ary' => [0 => 'W+:foo',],
19                    'words' => [0 => 'foo',],
20                    'highlight' => [0 => 'foo',],
21                    'and' => [0 => 'foo',],
22                    'phrases' => [],
23                    'ns' => [],
24                    'notns' => [],
25                    'not' => [],
26                ],
27                ':foo',
28                'simple single search word',
29            ],
30            [
31                [
32                    'query' => 'foo @wiki',
33                    'parsed_str' => '(W+:foo)AND(N+:wiki)',
34                    'parsed_ary' => [0 => 'W+:foo', 1 => 'N+:wiki', 2 => 'AND',],
35                    'words' => [0 => 'foo',],
36                    'highlight' => [0 => 'foo',],
37                    'and' => [0 => 'foo',],
38                    'ns' => [0 => 'wiki',],
39                    'phrases' => [],
40                    'notns' => [],
41                    'not' => [],
42                ],
43                ':wiki:foo',
44                'simple word limited to a namespace',
45            ],
46            [
47                [
48                    'query' => 'foo ^wiki',
49                    'parsed_str' => '(W+:foo)ANDNOT(N-:wiki)',
50                    'parsed_ary' => [0 => 'W+:foo', 1 => 'N-:wiki', 2 => 'NOT', 3 => 'AND',],
51                    'words' => [0 => 'foo',],
52                    'highlight' => [0 => 'foo',],
53                    'and' => [0 => 'foo',],
54                    'notns' => [0 => 'wiki',],
55                    'phrases' => [],
56                    'ns' => [],
57                    'not' => [],
58                ],
59                ':foo',
60                'simple word and excluding a namespace',
61            ],
62            [
63                [
64                    'query' => 'foo -bar',
65                    'parsed_str' => '(W+:foo)ANDNOT((W-:bar))',
66                    'parsed_ary' => [0 => 'W+:foo', 1 => 'W-:bar', 2 => 'NOT', 3 => 'AND',],
67                    'words' => [0 => 'foo', 1 => 'bar',],
68                    'highlight' => [0 => 'foo',],
69                    'and' => [0 => 'foo',],
70                    'not' => [0 => 'bar',],
71                    'phrases' => [],
72                    'ns' => [],
73                    'notns' => [],
74                ],
75                ':foo',
76                'one word but not the other',
77            ],
78            [
79                [
80                    'query' => 'wiki:foo',
81                    'parsed_str' => '((W+:wiki)AND(W+:foo))',
82                    'parsed_ary' => [0 => 'W+:wiki', 1 => 'W+:foo', 2 => 'AND',],
83                    'words' => [0 => 'wiki', 1 => 'foo',],
84                    'highlight' => [0 => 'wiki', 1 => 'foo',],
85                    'and' => [0 => 'wiki', 1 => 'foo',],
86                    'phrases' => [],
87                    'ns' => [],
88                    'notns' => [],
89                    'not' => [],
90                ],
91                ':wiki:foo',
92                'pageid with colons should result in that pageid',
93            ],
94            [
95                [
96                    'query' => 'WiKi:Foo',
97                    'parsed_str' => '((W+:wiki)AND(W+:foo))',
98                    'parsed_ary' => [0 => 'W+:wiki', 1 => 'W+:foo', 2 => 'AND',],
99                    'words' => [0 => 'wiki', 1 => 'foo',],
100                    'highlight' => [0 => 'wiki', 1 => 'foo',],
101                    'and' => [0 => 'wiki', 1 => 'foo',],
102                    'phrases' => [],
103                    'ns' => [],
104                    'notns' => [],
105                    'not' => [],
106                ],
107                ':wiki:foo',
108                'uppercased pageid with colons should result in clean pageid',
109            ],
110            [
111                [
112                    'query' => 'Бб:Гг:Rr',
113                    'parsed_str' => '((W+:бб)AND(W+:гг)AND(W+:rr))',
114                    'parsed_ary' => ['W+:бб', 'AND', 'W+:гг', 'AND', 'W+:rr', 'AND'],
115                    'words' => ["бб", "гг", "rr"],
116                    'highlight' => ["бб", "гг", "rr"],
117                    'and' => ["бб", "гг", "rr"],
118                    'phrases' => [],
119                    'ns' => [],
120                    'notns' => [],
121                    'not' => [],
122                ],
123                ':бб:гг:rr',
124                'uppercased utf-8 pageid with colons should result in clean pageid',
125            ],
126            [
127                [
128                    'query' => '"wiki:foo"',
129                    'parsed_str' => '((W_:wiki)AND(W_:foo)AND(P+:wiki:foo))',
130                    'parsed_ary' => [0 => 'W_:wiki', 1 => 'W_:foo', 2 => 'AND', 3 => 'P+:wiki:foo', 4 => 'AND',],
131                    'words' => [0 => 'wiki', 1 => 'foo',],
132                    'phrases' => [0 => 'wiki:foo',],
133                    'highlight' => [0 => 'wiki:foo',],
134                    'ns' => [],
135                    'notns' => [],
136                    'and' => [],
137                    'not' => [],
138                ],
139                ':wiki:foo',
140                'pageid with colons and wrapped in double quotes should result in that pageid as well',
141            ],
142        ];
143    }
144
145    /**
146     * @dataProvider dataProvider
147     *
148     * @param $inputParsedQuery
149     * @param $expectedPageName
150     * @param $msg
151     */
152    function test_simpleshort($inputParsedQuery, $expectedPageName, $msg)
153    {
154        $search = new \dokuwiki\Ui\Search([], [], []);
155
156        $actualPageName = $search->createPagenameFromQuery($inputParsedQuery);
157
158        $this->assertEquals($expectedPageName, $actualPageName, $msg);
159    }
160
161}
162
163
164