From f9ede95e5b901a89f2b0bc912eddfc8d5b10ac74 Mon Sep 17 00:00:00 2001 From: Mateusz Uzdowski Date: Tue, 2 Jul 2013 15:51:53 +1200 Subject: [PATCH] Add configuration system tests for Only and Except combinations. --- docs/en/topics/configuration.md | 5 +- tests/core/manifest/ConfigManifestTest.php | 37 +++++++++++++- .../mysite/_config/multiplerules.yml | 50 +++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 tests/core/manifest/fixtures/configmanifest/mysite/_config/multiplerules.yml diff --git a/docs/en/topics/configuration.md b/docs/en/topics/configuration.md index 580e3167f..f0dc40073 100644 --- a/docs/en/topics/configuration.md +++ b/docs/en/topics/configuration.md @@ -260,7 +260,10 @@ Note than when you have more than one rule for a nested fragment, they're joined FRAGMENT_INCLUDED = (ONLY && ONLY) && !(EXCEPT && EXCEPT) -That is, the fragment will be included if all Only rules match, except if all Except rules match +That is, the fragment will be included if all Only rules match, except if all Except rules match. + +Also, due to YAML limitations, having multiple conditions of the same kind (say, two `EnvVarSet` in one "Only" block) +will result in only the latter coming through. ### The values diff --git a/tests/core/manifest/ConfigManifestTest.php b/tests/core/manifest/ConfigManifestTest.php index f11c022d7..27a2da60f 100644 --- a/tests/core/manifest/ConfigManifestTest.php +++ b/tests/core/manifest/ConfigManifestTest.php @@ -140,6 +140,41 @@ class ConfigManifestTest extends SapphireTest { Config::inst()->unnest(); } + public function testMultipleRules() { + $_ENV['MultilpleRules_EnvVariableSet'] = 1; + define('MultilpleRules_DefinedConstant', 'defined'); + $config = $this->getConfigFixtureValue('MultipleRules'); + + $this->assertFalse( + isset($config['TwoOnlyFail']), + 'Fragment is not included if one of the Only rules fails.' + ); + + $this->assertTrue( + isset($config['TwoOnlySucceed']), + 'Fragment is included if both Only rules succeed.' + ); + + $this->assertTrue( + isset($config['TwoExceptSucceed']), + 'Fragment is included if one of the Except rules matches.' + ); + + $this->assertFalse( + isset($config['TwoExceptFail']), + 'Fragment is not included if both of the Except rules fail.' + ); + + $this->assertFalse( + isset($config['TwoBlocksFail']), + 'Fragment is not included if one block fails.' + ); + + $this->assertTrue( + isset($config['TwoBlocksSucceed']), + 'Fragment is included if both blocks succeed.' + ); + } public function testRelativeOrder() { $accessor = new ConfigManifestTest_ConfigManifestAccess(BASE_PATH, true, false); @@ -221,4 +256,4 @@ class ConfigManifestTest extends SapphireTest { ), 'after'); } -} \ No newline at end of file +} diff --git a/tests/core/manifest/fixtures/configmanifest/mysite/_config/multiplerules.yml b/tests/core/manifest/fixtures/configmanifest/mysite/_config/multiplerules.yml new file mode 100644 index 000000000..459e4e635 --- /dev/null +++ b/tests/core/manifest/fixtures/configmanifest/mysite/_config/multiplerules.yml @@ -0,0 +1,50 @@ +--- +Only: + ConstantDefined: MultilpleRules_UndefinedConstant + EnvVarSet: MultilpleRules_EnvVariableSet +--- +ConfigManifestTest: + MultipleRules: + TwoOnlyFail: "not included - one of the onlies fails" +--- +Only: + ConstantDefined: MultilpleRules_DefinedConstant + EnvVarSet: MultilpleRules_EnvVariableSet +--- +ConfigManifestTest: + MultipleRules: + TwoOnlySucceed: "included - both onlies succeed" +--- +Except: + ConstantDefined: MultilpleRules_UndefinedConstant + EnvVarSet: MultilpleRules_EnvVariableSet +--- +ConfigManifestTest: + MultipleRules: + TwoExceptSucceed: "included - one of the excepts succeeds" +--- +Except: + ConstantDefined: MultilpleRules_DefinedConstant + EnvVarSet: MultilpleRules_EnvVariableSet +--- +ConfigManifestTest: + MultipleRules: + TwoExceptFail: "not included - both excepts fail" +--- +Except: + EnvVarSet: MultilpleRules_EnvVariableSet +Only: + EnvVarSet: MultilpleRules_EnvVariableSet +--- +ConfigManifestTest: + MultipleRules: + TwoBlocksFail: "not included - one block fails" +--- +Except: + ConstantDefined: MultilpleRules_UndefinedConstant +Only: + EnvVarSet: MultilpleRules_EnvVariableSet +--- +ConfigManifestTest: + MultipleRules: + TwoBlocksSucceed: "included - both blocks succeed"