From 8c9b7b282cb7fc2588958f8a1e05b72f14c97b64 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Mon, 4 May 2009 23:57:12 +0000 Subject: [PATCH] BUGFIX: Fixed extraFilter argument for SiteTree::get_by_url() when translatable is enabled git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@76036 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/Translatable.php | 7 ++++--- tests/SiteTreeTest.php | 13 +++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/core/model/Translatable.php b/core/model/Translatable.php index ae4db0092..ce1352670 100755 --- a/core/model/Translatable.php +++ b/core/model/Translatable.php @@ -723,12 +723,13 @@ class Translatable extends DataObjectDecorator { * @return DataObject */ function alternateGetByUrl($urlSegment, $extraFilter, $cache = null, $orderby = null) { - $SQL_URLSegment = Convert::raw2sql($urlSegment); + $filter = sprintf("`SiteTree`.`URLSegment` = '%s'", Convert::raw2sql($urlSegment)); + if($extraFilter) $filter .= " AND $extraFilter"; self::$enable_lang_filter = false; - $record = DataObject::get_one('SiteTree', "`URLSegment` = '{$SQL_URLSegment}'"); + $record = DataObject::get_one('SiteTree', $filter); self::$enable_lang_filter = true; - + return $record; } diff --git a/tests/SiteTreeTest.php b/tests/SiteTreeTest.php index 2f1efe338..2f037407d 100644 --- a/tests/SiteTreeTest.php +++ b/tests/SiteTreeTest.php @@ -206,6 +206,19 @@ class SiteTreeTest extends SapphireTest { $this->assertEquals('Page', $requeriedPage->class); } + + /** + * Test SiteTree::get_by_url() + */ + function testGetByURL() { + // Test basic get by url + $this->assertEquals($this->idFromFixture('Page', 'home'), SiteTree::get_by_url("home")->ID); + + // Test the extraFilter argument + // Note: One day, it would be more appropriate to return null instead of false for queries such as these + $this->assertFalse(SiteTree::get_by_url("home", "1 = 2")); + } + } // We make these extend page since that's what all page types are expected to do