[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Tests the indexing functionality of the indexer
   4   *
   5   * @author Michael Hamann <michael@content-space.de>
   6   */
   7  class indexer_indexing_test extends DokuWikiTest {
   8      public function setUp() : void {
   9          parent::setUp();
  10          saveWikiText('testpage', 'Foo bar baz.', 'Test initialization');
  11          saveWikiText('notfound', 'Foon barn bazn.', 'Test initialization');
  12          idx_addPage('testpage');
  13          idx_addPage('notfound');
  14      }
  15  
  16      public function test_words() {
  17          $indexer = idx_get_indexer();
  18          $query = array('baz', 'foo');
  19          $this->assertEquals(array('baz' => array('testpage' => 1), 'foo' => array('testpage' => 1)), $indexer->lookup($query));
  20      }
  21  
  22      public function test_numerically_identical_words() {
  23          $indexer = idx_get_indexer();
  24          $indexer->addPageWords('testpage', '0x1 002');
  25          $indexer->addPageWords('notfound', '0x2');
  26          $query = array('001', '002');
  27          $this->assertEquals(array('001' => array(), '002' => array('testpage' => 1)), $indexer->lookup($query));
  28      }
  29  
  30      public function test_meta() {
  31          $indexer = idx_get_indexer();
  32          $indexer->addMetaKeys('testpage', 'testkey', 'testvalue');
  33          $indexer->addMetaKeys('notfound', 'testkey', 'notvalue');
  34          $query = 'testvalue';
  35          $this->assertEquals(array('testpage'), $indexer->lookupKey('testkey', $query));
  36      }
  37  
  38      public function test_numerically_identical_meta_values() {
  39          $indexer = idx_get_indexer();
  40          $indexer->addMetaKeys('testpage', 'numkey', array('0001', '01'));
  41          $indexer->addMetaKeys('notfound', 'numkey', array('00001', '000001'));
  42          $query = array('001', '01');
  43          $this->assertEquals(array('001' => array(), '01' => array('testpage')), $indexer->lookupKey('numkey', $query));
  44      }
  45  
  46      public function test_numeric_twice() {
  47          $indexer = idx_get_indexer();
  48          $indexer->addPageWords('testpage', '| 1010 | Dallas |');
  49          $query = array('1010');
  50          $this->assertEquals(array('1010' => array('testpage' => 1)), $indexer->lookup($query));
  51          $indexer->addPageWords('notfound', '| 1010 | Dallas |');
  52          $this->assertEquals(array('1010' => array('testpage' => 1, 'notfound' => 1)), $indexer->lookup($query));
  53      }
  54  
  55      public function test_numeric_twice_meta() {
  56          $indexer = idx_get_indexer();
  57          $indexer->addMetaKeys('testpage', 'onezero', array('1010'));
  58          $indexer->addMetaKeys('notfound', 'onezero', array('1010'));
  59          $query = '1010';
  60          $this->assertEquals(array('notfound', 'testpage'), $indexer->lookupKey('onezero', $query));
  61      }
  62  
  63      public function test_numeric_zerostring_meta() {
  64          $indexer = idx_get_indexer();
  65          $indexer->addMetaKeys('zero1', 'zerostring', array('0'));
  66          $indexer->addMetaKeys('zero2', 'zerostring', array('0'));
  67          $indexer->addMetaKeys('0', 'zerostring', array('zero'));
  68  
  69          $query = '0';
  70          $result = $indexer->lookupKey('zerostring', $query);
  71          sort($result);
  72          $this->assertEquals(array('zero1', 'zero2'), $result);
  73  
  74          $query = 'zero';
  75          $result = $indexer->lookupKey('zerostring', $query);
  76          sort($result);
  77          $this->assertEquals(array('0'), $result);
  78      }
  79  }