diff --git a/composer.json b/composer.json index b49b9d20c..79b512706 100644 --- a/composer.json +++ b/composer.json @@ -94,8 +94,8 @@ "thirdparty/" ], "scripts": { - "lint": "phpcs src/ tests/php", - "lint-clean": "phpcbf src/ tests/php", + "lint": "phpcs src/ tests/php/ tests/behat/src/", + "lint-clean": "phpcbf src/ tests/php/ tests/behat/src/", "php-peg": "php thirdparty/php-peg/cli.php src/View/SSTemplateParser.peg > src/View/SSTemplateParser.php" }, "minimum-stability": "dev", diff --git a/tests/behat/src/CmsFormsContext.php b/tests/behat/src/CmsFormsContext.php index 68477e7a2..a5e41c041 100644 --- a/tests/behat/src/CmsFormsContext.php +++ b/tests/behat/src/CmsFormsContext.php @@ -352,5 +352,4 @@ JS; // Destroy cookie to detach session $this->getMainContext()->getSession()->setCookie('PHPSESSID', null); } - } diff --git a/tests/behat/src/ConfigContext.php b/tests/behat/src/ConfigContext.php new file mode 100644 index 000000000..c3a2dd41f --- /dev/null +++ b/tests/behat/src/ConfigContext.php @@ -0,0 +1,133 @@ +setConfigPath($configPath); + } + + /** + * @return string + */ + public function getConfigPath() + { + return $this->configPath; + } + + /** + * @param string $configPath + * @return $this + */ + public function setConfigPath($configPath) + { + $this->configPath = $configPath; + return $this; + } + + /** + * Clean up all files after scenario + * + * @AfterScenario + * @param AfterScenarioScope $event + */ + public function afterResetAssets(AfterScenarioScope $event) + { + // No files to cleanup + if (empty($this->activatedConfigFiles)) { + return; + } + + foreach ($this->activatedConfigFiles as $configFile) { + if (file_exists($configFile)) { + unlink($configFile); + } + } + $this->activatedConfigFiles = []; + + // Flush + $this->stepIFlush(); + } + + /** + * @When /^(?:|I )go flush the website$/ + */ + public function stepIFlush() + { + $this->getMainContext()->visit('/?flush=all'); + } + + /** + * Setup a config file. The $filename should be a yml filename + * placed in the directory specified by configPaths argument + * to fixture constructor. + * + * @When /^(?:|I )have a config file "([^"]+)"$/ + * @param string $filename + */ + public function stepIHaveConfigFile($filename) + { + // Ensure site is in dev mode + /** @var Kernel $kernel */ + $kernel = Injector::inst()->get(Kernel::class); + assertEquals(Kernel::DEV, $kernel->getEnvironment(), "Site is in dev mode"); + + // Ensure file exists in specified fixture dir + $sourceDir = $this->getConfigPath(); + $sourcePath = "{$sourceDir}/{$filename}"; + assertFileExists($sourcePath, "Config file {$filename} exists"); + + // Get destination + $project = ModuleManifest::config()->get('project') ?: 'mysite'; + $mysite = ModuleLoader::getModule($project); + assertNotNull($mysite, 'Project exists'); + $destPath = $mysite->getResourcePath("_config/{$filename}"); + assertFileNotExists($destPath, "Config file {$filename} hasn't aleady been loaded"); + + // Load + $this->activatedConfigFiles[] = $destPath; + copy($sourcePath, $destPath); + + // Flush website + $this->stepIFlush(); + } +}