Commit 82f3ae52 authored by zYne's avatar zYne

new tests for search query language

parent 5b611b53
...@@ -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,26 +106,37 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -106,26 +106,37 @@ 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); $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);
}
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,8 +146,8 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -135,8 +146,8 @@ 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); $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);
}
/**
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