Skip to content
Permalink
Browse files

Add some basic tests for ConfigManifest#relativeOrder

  • Loading branch information...
Hamish Friedlander
Hamish Friedlander committed Aug 27, 2012
1 parent 6009cfa commit 8b6e4f5a9071200c218743b70e37c959efb4d335
Showing with 89 additions and 0 deletions.
  1. +89 −0 tests/core/manifest/ConfigManifestTest.php
@@ -0,0 +1,89 @@
<?php
class ConfigManifestTest_ConfigManifestAccess extends SS_ConfigManifest {
public function relativeOrder($a, $b) {
return parent::relativeOrder($a, $b);
}
}
class ConfigManifestTest extends SapphireTest {
function testRelativeOrder() {
$accessor = new ConfigManifestTest_ConfigManifestAccess(BASE_PATH, true, false);
// A fragment with a fully wildcard before rule
$beforeWildcarded = array(
'module' => 'foo', 'file' => 'alpha', 'name' => '1',
'before' => array(array('module' => '*', 'file' => '*', 'name' => '*'))
);
// A fragment with a fully wildcard before rule and a fully explicit after rule
$beforeWildcardedAfterExplicit = array_merge($beforeWildcarded, array(
'after' => array(array('module' => 'bar', 'file' => 'beta', 'name' => '2'))
));
// A fragment with a fully wildcard before rule and two fully explicit after rules
$beforeWildcardedAfterTwoExplicitRules = array_merge($beforeWildcarded, array(
'after' => array(
array('module' => 'bar', 'file' => 'beta', 'name' => '2'),
array('module' => 'baz', 'file' => 'gamma', 'name' => '3')
)
));
// A fragment with a fully wildcard before rule and a partially explicit after rule
$beforeWildcardedAfterPartialWildcarded = array_merge($beforeWildcarded, array(
'after' => array(array('module' => 'bar', 'file' => 'beta', 'name' => '*'))
));
// Wildcard should match any module
$this->assertEquals($accessor->relativeOrder(
$beforeWildcarded,
array('module' => 'qux', 'file' => 'delta', 'name' => '4')
), 'before');
// Wildcard should match any module even if there is an opposing rule, if opposing rule doesn't match
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterExplicit,
array('module' => 'qux', 'file' => 'delta', 'name' => '4')
), 'before');
// Wildcard should match any module even if there is an opposing rule, if opposing rule doesn't match, no matter how many opposing rules
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterExplicit,
array('module' => 'qux', 'file' => 'delta', 'name' => '4')
), 'before');
// Wildcard should match any module even if there is an opposing rule, if opposing rule doesn't match (even if some portions do)
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterExplicit,
array('module' => 'bar', 'file' => 'beta', 'name' => 'nomatchy')
), 'before');
// When opposing rule matches, wildcard should be ignored
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterExplicit,
array('module' => 'bar', 'file' => 'beta', 'name' => '2')
), 'after');
// When any one of mutiple opposing rule exists, wildcard should be ignored
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterTwoExplicitRules,
array('module' => 'bar', 'file' => 'beta', 'name' => '2')
), 'after');
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterTwoExplicitRules,
array('module' => 'baz', 'file' => 'gamma', 'name' => '3')
), 'after');
// When two opposed wildcard rules, and more specific one doesn't match, other should win
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterPartialWildcarded,
array('module' => 'qux', 'file' => 'delta', 'name' => '4')
), 'before');
// When two opposed wildcard rules, and more specific one does match, more specific one should win
$this->assertEquals($accessor->relativeOrder(
$beforeWildcardedAfterPartialWildcarded,
array('module' => 'bar', 'file' => 'beta', 'name' => 'wildcardmatchy')
), 'after');
}
}

0 comments on commit 8b6e4f5

Please sign in to comment.
You can’t perform that action at this time.