From 6b1f258c449fdae780f062edd485c59f93c6f69d Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 24 Feb 2010 02:50:47 +0000 Subject: [PATCH] BUGFIX #5073: Fixed CMS version indicator for alpha and beta versions. git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@99789 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/LeftAndMain.php | 29 +++++++++++++++-------------- tests/LeftAndMainTest.php | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php index e1827c91..ed47f71a 100644 --- a/code/LeftAndMain.php +++ b/code/LeftAndMain.php @@ -1089,20 +1089,9 @@ JS; public function CMSVersion() { $sapphireVersionFile = file_get_contents(BASE_PATH . '/sapphire/silverstripe_version'); $cmsVersionFile = file_get_contents(BASE_PATH . '/cms/silverstripe_version'); - - if(strstr($sapphireVersionFile, "/sapphire/trunk")) { - $sapphireVersion = "trunk"; - } else { - preg_match("/sapphire\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $sapphireVersionFile, $matches); - $sapphireVersion = ($matches) ? $matches[1] : null; - } - - if(strstr($cmsVersionFile, "/cms/trunk")) { - $cmsVersion = "trunk"; - } else { - preg_match("/cms\/(?:(?:branches)|(?:tags))(?:\/rc)?\/([A-Za-z0-9._-]+)\/silverstripe_version/", $cmsVersionFile, $matches); - $cmsVersion = ($matches) ? $matches[1] : null; - } + + $sapphireVersion = $this->versionFromVersionFile($sapphireVersionFile); + $cmsVersion = $this->versionFromVersionFile($cmsVersionFile); if($sapphireVersion == $cmsVersion) { return $sapphireVersion; @@ -1111,6 +1100,18 @@ JS; } } + /** + * Return the version from the content of a silverstripe_version file + */ + public function versionFromVersionFile($fileContent) { + if(preg_match('/\/trunk\/silverstripe_version/', $fileContent)) { + return "trunk"; + } else { + preg_match("/\/(?:branches|tags\/rc|tags\/beta|tags\/alpha|tags)\/([A-Za-z0-9._-]+)\/silverstripe_version/", $fileContent, $matches); + return ($matches) ? $matches[1] : null; + } + } + /** * @return array */ diff --git a/tests/LeftAndMainTest.php b/tests/LeftAndMainTest.php index 6835f7c1..295cba3f 100644 --- a/tests/LeftAndMainTest.php +++ b/tests/LeftAndMainTest.php @@ -14,6 +14,25 @@ class LeftAndMainTest extends FunctionalTest { CMSMenu::populate_menu(); } + /** + * Test that CMS versions can be interpreted appropriately + */ + public function testCMSVersion() { + $l = new LeftAndMain(); + $this->assertEquals("2.4", $l->versionFromVersionFile( + '$URL: http://svn.silverstripe.com/open/modules/cms/branches/2.4/silverstripe_version $')); + $this->assertEquals("2.2.0", $l->versionFromVersionFile( + '$URL: http://svn.silverstripe.com/open/modules/cms/tags/2.2.0/silverstripe_version $')); + $this->assertEquals("trunk", $l->versionFromVersionFile( + '$URL: http://svn.silverstripe.com/open/modules/cms/trunk/silverstripe_version $')); + $this->assertEquals("2.4.0-alpha1", $l->versionFromVersionFile( + '$URL: http://svn.silverstripe.com/open/modules/cms/tags/alpha/2.4.0-alpha1/silverstripe_version $')); + $this->assertEquals("2.4.0-beta1", $l->versionFromVersionFile( + '$URL: http://svn.silverstripe.com/open/modules/cms/tags/beta/2.4.0-beta1/silverstripe_version $')); + $this->assertEquals("2.4.0-rc1", $l->versionFromVersionFile( + '$URL: http://svn.silverstripe.com/open/modules/cms/tags/rc/2.4.0-rc1/silverstripe_version $')); + } + /** * Check that all subclasses of leftandmain can be accessed */