Skip to content
This repository
Browse code

Add some basic tests for ConfigManifest#relativeOrder

  • Loading branch information...
commit 8b6e4f5a9071200c218743b70e37c959efb4d335 1 parent 6009cfa
Hamish Friedlander authored August 27, 2012
89  tests/core/manifest/ConfigManifestTest.php
... ...
@@ -0,0 +1,89 @@
  1
+<?php
  2
+
  3
+class ConfigManifestTest_ConfigManifestAccess extends SS_ConfigManifest {
  4
+	public function relativeOrder($a, $b) {
  5
+		return parent::relativeOrder($a, $b);
  6
+	}
  7
+}
  8
+
  9
+class ConfigManifestTest extends SapphireTest {
  10
+
  11
+	function testRelativeOrder() {
  12
+		$accessor = new ConfigManifestTest_ConfigManifestAccess(BASE_PATH, true, false);
  13
+
  14
+		// A fragment with a fully wildcard before rule
  15
+		$beforeWildcarded = array(
  16
+			'module' => 'foo', 'file' => 'alpha', 'name' => '1',
  17
+			'before' => array(array('module' => '*', 'file' => '*', 'name' => '*'))
  18
+		);
  19
+		// A fragment with a fully wildcard before rule and a fully explicit after rule
  20
+		$beforeWildcardedAfterExplicit = array_merge($beforeWildcarded, array(
  21
+			'after' => array(array('module' => 'bar', 'file' => 'beta', 'name' => '2'))
  22
+		));
  23
+		// A fragment with a fully wildcard before rule and two fully explicit after rules
  24
+		$beforeWildcardedAfterTwoExplicitRules = array_merge($beforeWildcarded, array(
  25
+			'after' => array(
  26
+				array('module' => 'bar', 'file' => 'beta', 'name' => '2'),
  27
+				array('module' => 'baz', 'file' => 'gamma', 'name' => '3')
  28
+			)
  29
+		));
  30
+		// A fragment with a fully wildcard before rule and a partially explicit after rule
  31
+		$beforeWildcardedAfterPartialWildcarded = array_merge($beforeWildcarded, array(
  32
+			'after' => array(array('module' => 'bar', 'file' => 'beta', 'name' => '*'))
  33
+		));
  34
+
  35
+		// Wildcard should match any module
  36
+		$this->assertEquals($accessor->relativeOrder(
  37
+			$beforeWildcarded,
  38
+			array('module' => 'qux', 'file' => 'delta', 'name' => '4')
  39
+		), 'before');
  40
+
  41
+		// Wildcard should match any module even if there is an opposing rule, if opposing rule doesn't match
  42
+		$this->assertEquals($accessor->relativeOrder(
  43
+			$beforeWildcardedAfterExplicit,
  44
+			array('module' => 'qux', 'file' => 'delta', 'name' => '4')
  45
+		), 'before');
  46
+
  47
+		// Wildcard should match any module even if there is an opposing rule, if opposing rule doesn't match, no matter how many opposing rules
  48
+		$this->assertEquals($accessor->relativeOrder(
  49
+			$beforeWildcardedAfterExplicit,
  50
+			array('module' => 'qux', 'file' => 'delta', 'name' => '4')
  51
+		), 'before');
  52
+
  53
+		// Wildcard should match any module even if there is an opposing rule, if opposing rule doesn't match (even if some portions do)
  54
+		$this->assertEquals($accessor->relativeOrder(
  55
+			$beforeWildcardedAfterExplicit,
  56
+			array('module' => 'bar', 'file' => 'beta', 'name' => 'nomatchy')
  57
+		), 'before');
  58
+
  59
+		// When opposing rule matches, wildcard should be ignored
  60
+		$this->assertEquals($accessor->relativeOrder(
  61
+			$beforeWildcardedAfterExplicit,
  62
+			array('module' => 'bar', 'file' => 'beta', 'name' => '2')
  63
+		), 'after');
  64
+
  65
+		// When any one of mutiple opposing rule exists, wildcard should be ignored
  66
+		$this->assertEquals($accessor->relativeOrder(
  67
+			$beforeWildcardedAfterTwoExplicitRules,
  68
+			array('module' => 'bar', 'file' => 'beta', 'name' => '2')
  69
+		), 'after');
  70
+
  71
+		$this->assertEquals($accessor->relativeOrder(
  72
+			$beforeWildcardedAfterTwoExplicitRules,
  73
+			array('module' => 'baz', 'file' => 'gamma', 'name' => '3')
  74
+		), 'after');
  75
+
  76
+		// When two opposed wildcard rules, and more specific one doesn't match, other should win
  77
+		$this->assertEquals($accessor->relativeOrder(
  78
+			$beforeWildcardedAfterPartialWildcarded,
  79
+			array('module' => 'qux', 'file' => 'delta', 'name' => '4')
  80
+		), 'before');
  81
+
  82
+		// When two opposed wildcard rules, and more specific one does match, more specific one should win
  83
+		$this->assertEquals($accessor->relativeOrder(
  84
+			$beforeWildcardedAfterPartialWildcarded,
  85
+			array('module' => 'bar', 'file' => 'beta', 'name' => 'wildcardmatchy')
  86
+		), 'after');
  87
+	}
  88
+
  89
+}

0 notes on commit 8b6e4f5

Please sign in to comment.
Something went wrong with that request. Please try again.