public function test_search()
 {
     // prepare some data
     $this->loadSchemaJSON('pageschema');
     $this->saveData('syntax', 'pageschema', array('singlepage' => 'wiki:dokuwiki', 'multipage' => array('wiki:dokuwiki', 'wiki:syntax', 'wiki:welcome'), 'singletitle' => 'wiki:dokuwiki', 'multititle' => array('wiki:dokuwiki', 'wiki:syntax', 'wiki:welcome')));
     // make sure titles for some pages are known (not for wiki:welcome)
     $title = new Title('wiki:dokuwiki');
     $title->setTitle('DokuWiki Overview');
     $title = new Title('wiki:syntax');
     $title->setTitle('DokuWiki Foobar Syntax');
     // search
     $search = new Search();
     $search->addSchema('pageschema');
     $search->addColumn('singlepage');
     $search->addColumn('multipage');
     $search->addColumn('singletitle');
     $search->addColumn('multititle');
     /** @var Value[][] $result */
     $result = $search->execute();
     // no titles:
     $this->assertEquals('wiki:dokuwiki', $result[0][0]->getValue());
     $this->assertEquals(array('wiki:dokuwiki', 'wiki:syntax', 'wiki:welcome'), $result[0][1]->getValue());
     // titles as JSON:
     $this->assertEquals('["wiki:dokuwiki","DokuWiki Overview"]', $result[0][2]->getValue());
     $this->assertEquals(array('["wiki:dokuwiki","DokuWiki Overview"]', '["wiki:syntax","DokuWiki Foobar Syntax"]', '["wiki:welcome",null]'), $result[0][3]->getValue());
     // search single with title
     $single = clone $search;
     $single->addFilter('singletitle', 'Overview', '*~', 'AND');
     $result = $single->execute();
     $this->assertTrue(is_array($result));
     $this->assertEquals(1, count($result));
     // search multi with title
     $multi = clone $search;
     $multi->addFilter('multititle', 'Foobar', '*~', 'AND');
     $result = $multi->execute();
     $this->assertTrue(is_array($result));
     $this->assertEquals(1, count($result));
     // search single with page
     $single = clone $search;
     $single->addFilter('singletitle', 'wiki:dokuwiki', '*~', 'AND');
     $result = $single->execute();
     $this->assertTrue(is_array($result));
     $this->assertEquals(1, count($result));
     // search multi with page
     $multi = clone $search;
     $multi->addFilter('multititle', 'welcome', '*~', 'AND');
     $result = $multi->execute();
     $this->assertTrue(is_array($result));
     $this->assertEquals(1, count($result));
 }
 public function test_wildcard()
 {
     $search = new mock\Search();
     $search->addSchema('schema2', 'alias');
     $search->addColumn('*');
     $this->assertEquals(4, count($search->getColumns()));
     $search = new mock\Search();
     $search->addSchema('schema2', 'alias');
     $search->addColumn('schema2.*');
     $this->assertEquals(4, count($search->getColumns()));
     $search = new mock\Search();
     $search->addSchema('schema2', 'alias');
     $search->addColumn('alias.*');
     $this->assertEquals(4, count($search->getColumns()));
     $search = new mock\Search();
     $search->addSchema('schema2', 'alias');
     $search->addColumn('nope.*');
     $this->assertEquals(0, count($search->getColumns()));
 }
 public function test_filter()
 {
     $this->loadSchemaJSON('decimal');
     $this->waitForTick();
     $this->saveData('page1', 'decimal', array('field' => '5000'));
     $this->saveData('page2', 'decimal', array('field' => '5000.001'));
     $this->saveData('page3', 'decimal', array('field' => '900.5'));
     $this->saveData('page4', 'decimal', array('field' => '1.5'));
     $search = new Search();
     $search->addSchema('decimal');
     $search->addColumn('%pageid%');
     $search->addColumn('field');
     $search->addFilter('field', '800', '>', 'AND');
     $search->addSort('field', true);
     /** @var Value[][] $result */
     $result = $search->execute();
     $this->assertEquals(3, count($result));
     $this->assertEquals('page3', $result[0][0]->getValue());
     $this->assertEquals('page1', $result[1][0]->getValue());
     $this->assertEquals('page2', $result[2][0]->getValue());
 }