Commit 82f3ae52 authored by zYne's avatar zYne

new tests for search query language

parent 5b611b53
...@@ -35,7 +35,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -35,7 +35,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function prepareTables() public function prepareTables()
{ {
$this->tables = array('SearchTest', 'SearchTestIndex'); $this->tables = array('SearchTest', 'SearchTestIndex');
parent::prepareTables(); parent::prepareTables();
} }
public function prepareData() public function prepareData()
...@@ -63,7 +63,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -63,7 +63,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->tokenizeClause('doctrine AND orm'); $ret = $q->tokenizeClause('doctrine AND orm');
$this->assertEqual($ret, array('doctrine', 'orm')); $this->assertEqual($ret, array('doctrine', 'orm'));
} }
...@@ -91,7 +91,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -91,7 +91,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->tokenizeClause('doctrine OR orm dbal AND database OR rdbms'); $ret = $q->tokenizeClause('doctrine OR orm dbal AND database OR rdbms');
print_r($ret);
$expected = array(array('doctrine', 'orm'), 'dbal', array('database', 'rdbms')); $expected = array(array('doctrine', 'orm'), 'dbal', array('database', 'rdbms'));
$this->assertEqual($ret, $expected); $this->assertEqual($ret, $expected);
...@@ -106,27 +106,38 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -106,27 +106,38 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($ret, $expected); $this->assertEqual($ret, $expected);
} }
/**
public function testParseClauseSupportsAndOperator() public function testParseClauseSupportsAndOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('doctrine AND orm'); $ret = $q->parseClause('doctrine AND orm');
$sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?) ' $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)) '
. 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql);
}
public function testParseClauseSupportsMixingOfOperatorsAndParenthesis()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('((doctrine OR orm) AND dbal) OR database');
$sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) '
. 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'
. ' OR keyword = ?';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
public function testParseClauseSupportsMixingOfOperators3() public function testParseClauseSupportsMixingOfOperators3()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('doctrine OR orm AND dbal'); $ret = $q->parseClause('doctrine OR orm AND dbal');
$sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) ' $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) '
. 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
...@@ -135,9 +146,9 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -135,9 +146,9 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('(doctrine OR orm) AND dbal'); $ret = $q->parseClause('(doctrine OR orm) AND dbal');
$sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) ' $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) '
. 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
...@@ -145,13 +156,26 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -145,13 +156,26 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('(doctrine OR orm) dbal'); $ret = $q->parseClause('(doctrine OR orm) dbal');
print $ret;
$sql = 'search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?) ' $sql = '(search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) '
. 'AND search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?)'; . 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql);
}
public function testParseClauseSupportsMixingOfOperatorsAndDeeplyNestedParenthesis()
{
$q = new Doctrine_Search_Query('SearchTestIndex');
$ret = $q->parseClause('(((doctrine OR orm) AND dbal) OR database) AND rdbms');
$sql = '((search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ? OR keyword = ?)) '
. 'AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))'
. ' OR keyword = ?) AND (search_test_id IN (SELECT search_test_id FROM search_test_index WHERE keyword = ?))';
$this->assertEqual($ret, $sql); $this->assertEqual($ret, $sql);
} }
/**
public function testSearchSupportsAndOperator() public function testSearchSupportsAndOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment