[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/Ui/ -> Search_createPagenameFromQuery.test.php (source)

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