Commit c1c87d02 authored by zYne's avatar zYne

added test case for file searching functionality

parent 48a1f48d
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Search_File_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Search_File_TestCase extends Doctrine_UnitTestCase
{
public function prepareData()
{ }
public function prepareTables()
{ }
public function testSearchFileAutoCreatesFileTable()
{
$this->_search = new Doctrine_Search_File();
$this->conn->export->exportClasses(array('FileIndex'));
}
public function testIndexDirectoryIndexesAllFiles()
{
$this->_search->indexDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files');
$resultSet = $this->_search->search('dbms');
$this->assertEqual(count($resultSet), 1);
}
}
...@@ -177,7 +177,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -177,7 +177,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testSearchSupportsAndOperator() public function testSearchSupportsAndOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine AND orm'); $q->query('doctrine AND orm');
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index ' . 'FROM search_test_index '
...@@ -192,7 +192,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -192,7 +192,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testSearchSupportsOrOperator() public function testSearchSupportsOrOperator()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine OR orm'); $q->query('doctrine OR orm');
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index ' . 'FROM search_test_index '
...@@ -203,10 +203,10 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -203,10 +203,10 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
} }
public function testQuerySupportsSingleWordSearch() public function testQuerySupportsSingleWordquery()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine'); $q->query('doctrine');
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index WHERE keyword = ? GROUP BY id ORDER BY relevance'; . 'FROM search_test_index WHERE keyword = ? GROUP BY id ORDER BY relevance';
...@@ -218,7 +218,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -218,7 +218,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testSearchSupportsMixingOfOperators() public function testSearchSupportsMixingOfOperators()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('(doctrine OR orm) AND dbal'); $q->query('(doctrine OR orm) AND dbal');
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index ' . 'FROM search_test_index '
...@@ -233,7 +233,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -233,7 +233,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testSearchSupportsSingleTermWithQuotes() public function testSearchSupportsSingleTermWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("'doctrine orm'"); $q->query("'doctrine orm'");
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index WHERE keyword = ? ' . 'FROM search_test_index WHERE keyword = ? '
...@@ -247,7 +247,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -247,7 +247,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testSearchSupportsSingleLongTermWithQuotes() public function testSearchSupportsSingleLongTermWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("'doctrine orm dbal'"); $q->query("'doctrine orm dbal'");
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index WHERE keyword = ? ' . 'FROM search_test_index WHERE keyword = ? '
...@@ -259,10 +259,10 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -259,10 +259,10 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($q->getSql(), $sql); $this->assertEqual($q->getSql(), $sql);
} }
public function testQuerySupportsMultiWordSearch() public function testQuerySupportsMultiWordquery()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doctrine orm'); $q->query('doctrine orm');
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index ' . 'FROM search_test_index '
...@@ -276,7 +276,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -276,7 +276,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testQuerySupportsMultiWordSearchAndSingleLetterWildcards() public function testQuerySupportsMultiWordSearchAndSingleLetterWildcards()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doct?ine orm'); $q->query('doct?ine orm');
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index ' . 'FROM search_test_index '
...@@ -290,7 +290,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -290,7 +290,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testQuerySupportsMultiWordSearchAndMultiLetterWildcards() public function testQuerySupportsMultiWordSearchAndMultiLetterWildcards()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search('doc* orm'); $q->query('doc* orm');
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index ' . 'FROM search_test_index '
...@@ -304,7 +304,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -304,7 +304,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testSearchSupportsMultipleTermsWithQuotes() public function testSearchSupportsMultipleTermsWithQuotes()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$q->search("doctrine 'orm database'"); $q->query("doctrine 'orm database'");
$sql = 'SELECT COUNT(keyword) AS relevance, id ' $sql = 'SELECT COUNT(keyword) AS relevance, id '
. 'FROM search_test_index ' . 'FROM search_test_index '
...@@ -320,7 +320,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase ...@@ -320,7 +320,7 @@ class Doctrine_Search_Query_TestCase extends Doctrine_UnitTestCase
public function testSearchReturnsFalseForEmptyStrings() public function testSearchReturnsFalseForEmptyStrings()
{ {
$q = new Doctrine_Search_Query('SearchTestIndex'); $q = new Doctrine_Search_Query('SearchTestIndex');
$result = $q->search(' '); $result = $q->query(' ');
$this->assertFalse($result); $this->assertFalse($result);
} }
......
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