From 708b5a2ad8801f11f25d210ac55b2fdb556abb34 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 19 Mar 2013 09:47:41 +0100 Subject: [PATCH] Remove cmsworkflow tests, no longer supported in 3.x --- _config.php | 2 +- .../CMSWorkflowSiteConfigController.php | 28 --- .../CMSWorkflowSiteConfigDecorator.php | 187 ------------------ .../CMSWorkflowSiteConfigDecoratorTest.php | 124 ------------ code/cmsworkflow/_manifest_exclude | 0 5 files changed, 1 insertion(+), 340 deletions(-) delete mode 100644 code/cmsworkflow/CMSWorkflowSiteConfigController.php delete mode 100644 code/cmsworkflow/CMSWorkflowSiteConfigDecorator.php delete mode 100644 code/cmsworkflow/CMSWorkflowSiteConfigDecoratorTest.php delete mode 100644 code/cmsworkflow/_manifest_exclude diff --git a/_config.php b/_config.php index 25eb54e..4d1ae17 100644 --- a/_config.php +++ b/_config.php @@ -5,7 +5,7 @@ Member::add_extension('FileUploadRole'); SiteTree::add_extension('FrameworkTestSiteTreeExtension'); if(class_exists('SiteTreeCMSWorkflow')) { - Object::add_extension('SiteConfig', 'CMSWorkflowSiteConfigDecorator'); + SiteConfig::add_extension('CMSWorkflowSiteConfigDecorator'); CMSWorkflowSiteConfigDecorator::apply_active_config(); } diff --git a/code/cmsworkflow/CMSWorkflowSiteConfigController.php b/code/cmsworkflow/CMSWorkflowSiteConfigController.php deleted file mode 100644 index 98d8ed9..0000000 --- a/code/cmsworkflow/CMSWorkflowSiteConfigController.php +++ /dev/null @@ -1,28 +0,0 @@ -CMS Workflow has been set to $whichStep

"; - - // rebuild the database schema - Director::redirect("dev/build?flush=1"); - - return true; - } - - -} \ No newline at end of file diff --git a/code/cmsworkflow/CMSWorkflowSiteConfigDecorator.php b/code/cmsworkflow/CMSWorkflowSiteConfigDecorator.php deleted file mode 100644 index 5850071..0000000 --- a/code/cmsworkflow/CMSWorkflowSiteConfigDecorator.php +++ /dev/null @@ -1,187 +0,0 @@ - - * STEP = threestep - * OTHERCONFIG = value - * ... - * - * - * The STEP config can be either twostep or threestep where twostep is the default - * - */ -class CMSWorkflowSiteConfigDecorator extends DataExtension { - - static $config_file_path = ''; - - static $step_config = "twostep" ; - - static $default_config = "STEP = twostep"; - - /** - * @TODO: add javascript that instantly appends "(active)" to the links - "Set to Two-Step" and "Set to Three-Step" - */ - function updateCMSFields(&$fields) { - $twoStepActive = ""; - $threeStepActive = ""; - $whichStep = self::get_step_config(); - - if($whichStep == 'threestep') { - $threeStepActive = "(active)"; - } - else { - $twoStepActive = "(active)"; - } - - $fields->addFieldToTab("Root.Main", new HeaderField("WorkflowHeader", "CMS Workflow Configuration")); - - $fields->addFieldToTab("Root.Main", new LiteralField("WorkflowTwoStepLink", '

Set to Two Step ' . $twoStepActive . '

')); - - $fields->addFieldToTab("Root.Main", new LiteralField("WorkflowThreeStepLink", '

Set to Three Step ' . $threeStepActive . '

')); - } - - /** - * Apply two step (config) or three step workflow config. - * Two step config is already set in the module so SiteConfig::WorkflowStepConfig is twostep we don't need to do anything - */ - static function apply_active_config() { - $whichStep = self::get_step_config(); - - if($whichStep == 'threestep') { - // remove two-step decorators - Object::remove_extension('WorkflowRequest', 'WorkflowTwoStepRequest'); - Object::remove_extension('SiteTree', 'SiteTreeCMSTwoStepWorkflow'); - Object::remove_extension('SiteConfig', 'SiteConfigTwoStepWorkflow'); - - // add three-step decorators - Object::add_extension('WorkflowRequest', 'WorkflowThreeStepRequest'); - Object::add_extension('SiteTree', 'SiteTreeCMSThreeStepWorkflow'); - Object::add_extension('LeftAndMain', 'LeftAndMainCMSThreeStepWorkflow'); - Object::add_extension('SiteConfig', 'SiteConfigThreeStepWorkflow'); - } - - } - - /** - * Get STEP config variable from file self::get_config_file_path() - * @return string | the value of the config variable - */ - static function get_step_config() { - $config = self::get_config_content(); - $value = self::get_config($config, "STEP"); - - return $value; - } - - /** - * Set Get STEP config varial from file self::get_config_file_path() - */ - static function set_step_config($val) { - $config = self::get_config_content(); - $newContent = self::set_config($config, "STEP", $val); - self::write_config_file($newContent); - } - - /** - * Config file path for frameworktest - two step and three step testing - */ - static function get_config_file_path() { - if (self::$config_file_path) { - return self::$config_file_path; - } else { - return dirname(__FILE__) . "/CMSWorkflow_Config.cfg"; - } - } - - /** - * Config file path for frameworktest - two step and three step testing - * @return file handler - */ - static function get_config_file($mode = "r+") { - $path = self::get_config_file_path(); - - // create if not existing - if(!file_exists($path)) { - $file = fopen($path, "w"); - // default config - fwrite($file, self::$default_config); - fclose($file); - } - - return fopen($path, $mode); - } - - /** - * Config file path for frameworktest - two step and three step testing - * @return file handler - */ - static function write_config_file($content) { - $file = self::get_config_file(); - - // clear the file first - ftruncate($file, 0); - - fwrite($file, $content); - fclose($file); - } - - /** - * Config file path for frameworktest - two step and three step testing - * @return string - */ - static function get_config_content() { - $file = self::get_config_file(); - - $content = null; - while(!@feof($file)) { - $content .= @fread($file, 10); - } - - fclose($file); - - return $content; - } - - /** - * - * @param content from the file return from self::get_config_file - * @param config variable - */ - static function get_config($content, $var) { - $pattern = "/$var\s*=\s*([\w_]*)/"; - preg_match($pattern, $content, $matches); - - if(count($matches) < 2) return false; - - return $matches[1]; - } - - /** - * @param content from the file return from self::get_config_file - * @param config variable - * @param value of the config variable - * @return string | new content - */ - static function set_config($content, $var, $value) { - $pattern = "/$var\s*=\s*([\w_]*)/"; - $replaced = preg_replace($pattern, "$var = $value", $content); - - // if there varial is not found in the config a new a new one - if(preg_match($pattern, $content) == 0) { - if (trim($replaced) == "") { - $replaced = self::$default_config; - } - else { - $newConfig = "$var = $value"; - $replaced = trim($replaced) . "\n" . $newConfig; - } - } - return $replaced; - } - - -} \ No newline at end of file diff --git a/code/cmsworkflow/CMSWorkflowSiteConfigDecoratorTest.php b/code/cmsworkflow/CMSWorkflowSiteConfigDecoratorTest.php deleted file mode 100644 index df47984..0000000 --- a/code/cmsworkflow/CMSWorkflowSiteConfigDecoratorTest.php +++ /dev/null @@ -1,124 +0,0 @@ -workflowConfigPath = dirname(__FILE__) . "/CMSWorkflow_Config.cfg"; - CMSWorkflowSiteConfigDecorator::$config_file_path = $this->workflowConfigPath; - } - - function testGetConfigFile() { - $file = CMSWorkflowSiteConfigDecorator::get_config_file(); - $content = $this->readFile($this->workflowConfigPath); - - // the size and the content of the initial config file are the same CMSWorkflowSiteConfigDecorator::$default_config's - $workflowDefaultConfig = CMSWorkflowSiteConfigDecorator::$default_config; - $this->assertEquals($workflowDefaultConfig, $content); - - fclose($file); - } - - function testGetConfigContent() { - $content = CMSWorkflowSiteConfigDecorator::get_config_content(); - $content2 = $this->readFile($this->workflowConfigPath); - - $this->assertEquals($content, $content2); - } - - function testWriteConfigFile() { - CMSWorkflowSiteConfigDecorator::write_config_file("New workflow config"); - $content = $this->readFile($this->workflowConfigPath); - $this->assertEquals("New workflow config", $content); - - CMSWorkflowSiteConfigDecorator::write_config_file("New workflow config two"); - $content = $this->readFile($this->workflowConfigPath); - $this->assertEquals("New workflow config two", $content); - - CMSWorkflowSiteConfigDecorator::write_config_file("Config three"); - $content = $this->readFile($this->workflowConfigPath); - $this->assertEquals("Config three", $content); - } - - function testGetConfig() { - $content = "STEP = twostep\nTESTCONFIG = test"; - - $value = CMSWorkflowSiteConfigDecorator::get_config($content, "STEP"); - $this->assertEquals("twostep", $value); - - $value = CMSWorkflowSiteConfigDecorator::get_config($content, "TESTCONFIG"); - $this->assertEquals("test", $value); - - $value = CMSWorkflowSiteConfigDecorator::get_config($content, "NOTEXISTING"); - $this->assertEquals("", $value); - } - - function testWriteConfig() { - $content = "STEP = twostep\nTESTCONFIG = test"; - - $newContent = CMSWorkflowSiteConfigDecorator::set_config($content, "STEP", 'threestep'); - $this->assertEquals("STEP = threestep\nTESTCONFIG = test", $newContent); - - $newContent = CMSWorkflowSiteConfigDecorator::set_config($content, "TESTCONFIG", ''); - $this->assertEquals("STEP = twostep\nTESTCONFIG = ", $newContent); - - $newContent = CMSWorkflowSiteConfigDecorator::set_config($content, "NEWCONFIG", 'newstuff'); - $this->assertEquals("STEP = twostep\nTESTCONFIG = test\nNEWCONFIG = newstuff", $newContent); - } - - function testGetStepConfig() { - $value = CMSWorkflowSiteConfigDecorator::get_step_config(); - $this->assertEquals("twostep", $value); - } - - function testSetStepConfig() { - CMSWorkflowSiteConfigDecorator::set_step_config("threestep"); - $content = $this->readFile($this->workflowConfigPath); - $this->assertEquals("STEP = threestep", $content); - - CMSWorkflowSiteConfigDecorator::set_step_config(""); - $content = $this->readFile($this->workflowConfigPath); - $this->assertEquals("STEP = ", $content); - - CMSWorkflowSiteConfigDecorator::set_step_config("twostep"); - $content = $this->readFile($this->workflowConfigPath); - $this->assertEquals("STEP = twostep", $content); - } - - function tearDown() { - // delete the config file before begin the test - $path = CMSWorkflowSiteConfigDecorator::get_config_file_path(); - if(file_exists($path)) { - unlink(CMSWorkflowSiteConfigDecorator::get_config_file_path()); - } - - // Remove custom CMSWorkflow config file path - CMSWorkflowSiteConfigDecorator::$config_file_path = ''; - } - - /** - * Read the whole content of a (text) file. - * Having this method so that we can avoid relying on CMSWorkflowSiteConfigDecorator::get_config_content() - * @return string - content of the file - */ - private function readFile($path) { - // create if not existing - if(!file_exists($path)) { - return array(null, null); - } - - $file = fopen($path, 'r'); - - $content = null; - while(!feof($file)) { - $content .= fread($file, 10); - } - - fclose($file); - - return $content; - } - - -} \ No newline at end of file diff --git a/code/cmsworkflow/_manifest_exclude b/code/cmsworkflow/_manifest_exclude deleted file mode 100644 index e69de29..0000000