mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-02 14:18:46 +02:00
Merge pull request #3509 from tractorcow/pr/3364
Added tests that check comparisonClause()
This commit is contained in:
commit
e37d9223ee
@ -10,6 +10,7 @@ class DataQueryTest extends SapphireTest {
|
||||
'DataQueryTest_C',
|
||||
'DataQueryTest_D',
|
||||
'DataQueryTest_E',
|
||||
'DataQueryTest_F',
|
||||
);
|
||||
|
||||
|
||||
@ -165,6 +166,58 @@ class DataQueryTest extends SapphireTest {
|
||||
|
||||
$query = $query->distinct(true);
|
||||
$this->assertContains('SELECT DISTINCT', $query->sql(), 'Query contains distinct');
|
||||
}
|
||||
|
||||
public function testComparisonClauseInt() {
|
||||
DB::query("INSERT INTO \"DataQueryTest_F\" (\"SortOrder\") VALUES (2)");
|
||||
$query = new DataQuery('DataQueryTest_F');
|
||||
$query->where(DB::getConn()->comparisonClause('"SortOrder"', '2'));
|
||||
$this->assertGreaterThan(0, $query->count(), "Couldn't find SortOrder");
|
||||
$this->resetDBSchema(true);
|
||||
}
|
||||
|
||||
public function testComparisonClauseDateFull() {
|
||||
DB::query("INSERT INTO \"DataQueryTest_F\" (\"MyDate\") VALUES ('1988-03-04 06:30')");
|
||||
$query = new DataQuery('DataQueryTest_F');
|
||||
$query->where(DB::getConn()->comparisonClause('"MyDate"', '1988-03-04%'));
|
||||
$this->assertGreaterThan(0, $query->count(), "Couldn't find MyDate");
|
||||
$this->resetDBSchema(true);
|
||||
}
|
||||
|
||||
public function testComparisonClauseDateStartsWith() {
|
||||
DB::query("INSERT INTO \"DataQueryTest_F\" (\"MyDate\") VALUES ('1988-03-04 06:30')");
|
||||
$query = new DataQuery('DataQueryTest_F');
|
||||
$query->where(DB::getConn()->comparisonClause('"MyDate"', '1988%'));
|
||||
$this->assertGreaterThan(0, $query->count(), "Couldn't find MyDate");
|
||||
$this->resetDBSchema(true);
|
||||
}
|
||||
|
||||
public function testComparisonClauseDateStartsPartial() {
|
||||
DB::query("INSERT INTO \"DataQueryTest_F\" (\"MyDate\") VALUES ('1988-03-04 06:30')");
|
||||
$query = new DataQuery('DataQueryTest_F');
|
||||
$query->where(DB::getConn()->comparisonClause('"MyDate"', '%03-04%'));
|
||||
$this->assertGreaterThan(0, $query->count(), "Couldn't find MyDate");
|
||||
$this->resetDBSchema(true);
|
||||
}
|
||||
|
||||
public function testComparisonClauseTextCaseInsensitive() {
|
||||
DB::query("INSERT INTO \"DataQueryTest_F\" (\"MyString\") VALUES ('HelloWorld')");
|
||||
$query = new DataQuery('DataQueryTest_F');
|
||||
$query->where(DB::getConn()->comparisonClause('"MyString"', 'helloworld'));
|
||||
$this->assertGreaterThan(0, $query->count(), "Couldn't find MyString");
|
||||
$this->resetDBSchema(true);
|
||||
}
|
||||
|
||||
public function testComparisonClauseTextCaseSensitive() {
|
||||
DB::query("INSERT INTO \"DataQueryTest_F\" (\"MyString\") VALUES ('HelloWorld')");
|
||||
$query = new DataQuery('DataQueryTest_F');
|
||||
$query->where(DB::getConn()->comparisonClause('"MyString"', 'HelloWorld', false, false, true));
|
||||
$this->assertGreaterThan(0, $query->count(), "Couldn't find MyString");
|
||||
|
||||
$query2 = new DataQuery('DataQueryTest_F');
|
||||
$query2->where(DB::getConn()->comparisonClause('"MyString"', 'helloworld', false, false, true));
|
||||
$this->assertEquals(0, $query2->count(), "Found mystring. Shouldn't be able too.");
|
||||
$this->resetDBSchema(true);
|
||||
}
|
||||
|
||||
}
|
||||
@ -229,3 +282,12 @@ class DataQueryTest_E extends DataQueryTest_C implements TestOnly {
|
||||
|
||||
private static $default_sort = '"DataQueryTest_E"."SortOrder" ASC';
|
||||
}
|
||||
|
||||
class DataQueryTest_F extends DataObject implements TestOnly {
|
||||
|
||||
private static $db = array(
|
||||
'SortOrder' => 'Int',
|
||||
'MyDate' => 'SS_Datetime',
|
||||
'MyString' => 'Text'
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user