MINOR remove sort direction when running canSortBy. Also added test coverage for this. (from r96428) (from r98138)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102610 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-04-13 02:16:50 +00:00
parent 10537d5133
commit 9b650a4e6c
2 changed files with 9 additions and 0 deletions

View File

@ -455,6 +455,8 @@ class SQLQuery {
* "false" more often that is strictly necessary.
*/
function canSortBy($fieldName) {
$fieldName = preg_replace('/(\s+?)(A|DE)SC$/', '', $fieldName);
$sql = $this->sql();
$selects = $this->select;

View File

@ -50,6 +50,13 @@ class SQLQueryTest extends SapphireTest {
$this->assertEquals("SELECT Name, Meta FROM MyTable WHERE (Name = 'Name') AND (Meta = 'Test')", $query->sql());
}
function testCanSortBy() {
$query = new SQLQuery();
$query->select("Name","Meta")->from("MyTable")->where("Name", "Name")->where("Meta", "Test");
$this->assertTrue($query->canSortBy('Name ASC'));
$this->assertTrue($query->canSortBy('Name'));
}
function testSelectWithChainedFilterParameters() {
$query = new SQLQuery();
$query->select(array("Name","Meta"))->from("MyTable");