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