Fixed tests

This commit is contained in:
Elvinas L. 2015-10-06 18:59:39 +03:00
parent ee6b250a46
commit 19c754bf9a

View File

@ -40,26 +40,36 @@ class FulltextFilterTest extends SapphireTest {
}
public function testGenerateQuery() {
// Test if columns have table identifier
$filter1 = new FulltextFilter('SearchFields', 'SilverStripe');
$filter1->setModel('FulltextFilterTest_DataObject');
$query1 = FulltextFilterTest_DataObject::get()->dataQuery();
$filter1->apply($query1);
$this->assertNotEquals('"ColumnA", "ColumnB"', $filter1->getDbName());
$this->assertNotEquals(
array("MATCH (\"ColumnA\", \"ColumnB\") AGAINST ('SilverStripe')"),
$query1->query()->getWhere()
);
// Test SearchFields
$filter1 = new FulltextFilter('SearchFields', 'SilverStripe');
$filter1->setModel('FulltextFilterTest_DataObject');
$query1 = FulltextFilterTest_DataObject::get()->dataQuery();
$filter1->apply($query1);
$this->assertEquals('"ColumnA", "ColumnB"', $filter1->getDbName());
$this->assertEquals('"FulltextFilterTest_DataObject"."ColumnA", "FulltextFilterTest_DataObject"."ColumnB"', $filter1->getDbName());
$this->assertEquals(
array("MATCH (\"ColumnA\", \"ColumnB\") AGAINST ('SilverStripe')"),
array("MATCH (\"FulltextFilterTest_DataObject\".\"ColumnA\", \"FulltextFilterTest_DataObject\".\"ColumnB\") AGAINST ('SilverStripe')"),
$query1->query()->getWhere()
);
// Test Other searchfields
$filter2 = new FulltextFilter('OtherSearchFields', 'SilverStripe');
$filter2->setModel('FulltextFilterTest_DataObject');
$query2 = FulltextFilterTest_DataObject::get()->dataQuery();
$filter2->apply($query2);
$this->assertEquals('"ColumnC", "ColumnD"', $filter2->getDbName());
$this->assertEquals('"FulltextFilterTest_DataObject"."ColumnC", "FulltextFilterTest_DataObject"."ColumnD"', $filter2->getDbName());
$this->assertEquals(
array("MATCH (\"ColumnC\", \"ColumnD\") AGAINST ('SilverStripe')"),
array("MATCH (\"FulltextFilterTest_DataObject\".\"ColumnC\", \"FulltextFilterTest_DataObject\".\"ColumnD\") AGAINST ('SilverStripe')"),
$query2->query()->getWhere()
);
@ -102,4 +112,4 @@ class FulltextFilterTest_DataObject extends DataObject implements TestOnly {
"MySQLDatabase" => "ENGINE=MyISAM",
);
}
}