xref: /dokuwiki/_test/tests/inc/fulltext_query.test.php (revision 44156e1168f2abc50ff19edd70a709fa29827817)
1*44156e11SMichael Große<?php
2*44156e11SMichael Große
3*44156e11SMichael Große// must be run within Dokuwiki
4*44156e11SMichael Großeif (!defined('DOKU_INC')) {
5*44156e11SMichael Große    die();
6*44156e11SMichael Große}
7*44156e11SMichael Große
8*44156e11SMichael Große/**
9*44156e11SMichael Große * Test cases for the link index
10*44156e11SMichael Große *
11*44156e11SMichael Große * @author Michael Große <grosse@cosmocode.de>
12*44156e11SMichael Große *
13*44156e11SMichael Große * @group  fulltext
14*44156e11SMichael Große */
15*44156e11SMichael Großeclass fulltext_query_test extends DokuWikiTest
16*44156e11SMichael Große{
17*44156e11SMichael Große    public function test_parse_query()
18*44156e11SMichael Große    {
19*44156e11SMichael Große        $Indexer = idx_get_indexer();
20*44156e11SMichael Große        $inputQuery = 'test -baz "foo bar" @abc ^def';
21*44156e11SMichael Große
22*44156e11SMichael Große        $actualParsedQuery = ft_queryParser($Indexer, $inputQuery);
23*44156e11SMichael Große
24*44156e11SMichael Große        $expectedParsedQuery = [
25*44156e11SMichael Große            'query' => 'test -baz "foo bar" @abc ^def',
26*44156e11SMichael Große            'parsed_str' => '(W+:test)ANDNOT((W-:baz))AND((W_:foo)AND(W_:bar)AND(P+:foo bar))AND(N+:abc)ANDNOT(N-:def)',
27*44156e11SMichael Große            'parsed_ary' => [
28*44156e11SMichael Große                'W+:test',
29*44156e11SMichael Große                'W-:baz',
30*44156e11SMichael Große                'NOT',
31*44156e11SMichael Große                'AND',
32*44156e11SMichael Große                'W_:foo',
33*44156e11SMichael Große                'W_:bar',
34*44156e11SMichael Große                'AND',
35*44156e11SMichael Große                'P+:foo bar',
36*44156e11SMichael Große                'AND',
37*44156e11SMichael Große                'AND',
38*44156e11SMichael Große                'N+:abc',
39*44156e11SMichael Große                'AND',
40*44156e11SMichael Große                'N-:def',
41*44156e11SMichael Große                'NOT',
42*44156e11SMichael Große                'AND',
43*44156e11SMichael Große            ],
44*44156e11SMichael Große            'words' => [
45*44156e11SMichael Große                'test',
46*44156e11SMichael Große                'baz',
47*44156e11SMichael Große                'foo',
48*44156e11SMichael Große                'bar',
49*44156e11SMichael Große            ],
50*44156e11SMichael Große            'highlight' => [
51*44156e11SMichael Große                'test',
52*44156e11SMichael Große                'foo bar',
53*44156e11SMichael Große            ],
54*44156e11SMichael Große            'and' => [
55*44156e11SMichael Große                'test',
56*44156e11SMichael Große            ],
57*44156e11SMichael Große            'phrases' => [
58*44156e11SMichael Große                'foo bar',
59*44156e11SMichael Große            ],
60*44156e11SMichael Große            'ns' => [
61*44156e11SMichael Große                'abc',
62*44156e11SMichael Große            ],
63*44156e11SMichael Große            'notns' => [
64*44156e11SMichael Große                'def',
65*44156e11SMichael Große            ],
66*44156e11SMichael Große            'not' => [
67*44156e11SMichael Große                'baz',
68*44156e11SMichael Große            ],
69*44156e11SMichael Große        ];
70*44156e11SMichael Große        $this->assertEquals($expectedParsedQuery, $actualParsedQuery);
71*44156e11SMichael Große    }
72*44156e11SMichael Große
73*44156e11SMichael Große    public function test_unparse_query()
74*44156e11SMichael Große    {
75*44156e11SMichael Große        $input = [
76*44156e11SMichael Große            'and' => [
77*44156e11SMichael Große                'test',
78*44156e11SMichael Große            ],
79*44156e11SMichael Große            'not' => [
80*44156e11SMichael Große                'baz'
81*44156e11SMichael Große            ],
82*44156e11SMichael Große            'phrases' => [
83*44156e11SMichael Große                'foo bar',
84*44156e11SMichael Große            ],
85*44156e11SMichael Große            'ns' => [
86*44156e11SMichael Große                'abc',
87*44156e11SMichael Große            ],
88*44156e11SMichael Große            'notns' => [
89*44156e11SMichael Große                'def'
90*44156e11SMichael Große            ],
91*44156e11SMichael Große        ];
92*44156e11SMichael Große
93*44156e11SMichael Große        $actualQuery = ft_queryUnparser_simple(
94*44156e11SMichael Große            $input['and'],
95*44156e11SMichael Große            $input['not'],
96*44156e11SMichael Große            $input['phrases'],
97*44156e11SMichael Große            $input['ns'],
98*44156e11SMichael Große            $input['notns']
99*44156e11SMichael Große        );
100*44156e11SMichael Große
101*44156e11SMichael Große        $expectedQuery = 'test -baz "foo bar" @abc ^def';
102*44156e11SMichael Große        $this->assertEquals($expectedQuery, $actualQuery);
103*44156e11SMichael Große    }
104*44156e11SMichael Große}
105