Index: binaries/data/mods/public/simulation/components/tests/test_Auras.js
===================================================================
--- binaries/data/mods/public/simulation/components/tests/test_Auras.js	(révision 18600)
+++ binaries/data/mods/public/simulation/components/tests/test_Auras.js	(copie de travail)
@@ -4,72 +4,141 @@ Engine.LoadComponentScript("interfaces/A
 Engine.LoadComponentScript("interfaces/AuraManager.js");
 Engine.LoadComponentScript("interfaces/TechnologyManager.js");
 Engine.LoadComponentScript("Auras.js");
 Engine.LoadComponentScript("AuraManager.js");
 
-var playerEnt1 = 5;
-var auraEnt = 20;
-var targetEnt = 30;
-
-AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
-	GetPlayerByID: function() { return playerEnt1; },
-	GetNumPlayers: function() { return 2; },
+let playerID = 1;
+let playerEnt = 10;
+let auraEnt = 20;
+let targetEnt = 30;
+let template = { "Identity" : { "Classes" : { "_string" : "CorrectClass OtherClass" } } };
+
+function testAuras(name, test_function)
+{
+	ResetState();
+
+	AddMock(SYSTEM_ENTITY, IID_PlayerManager, {
+		GetPlayerByID: () => playerEnt,
+		GetNumPlayers: () => 2,
+	});
+
+	AddMock(SYSTEM_ENTITY, IID_RangeManager, {
+		CreateActiveQuery: (ent, minRange, maxRange, players, iid, flags) => 1,
+		EnableActiveQuery: id => {},
+		ResetActiveQuery: id => {},
+		DisableActiveQuery: id => {},
+		DestroyActiveQuery: id => {},
+		GetEntityFlagMask: identifier => {},
+	});
+
+	AddMock(SYSTEM_ENTITY, IID_DataTemplateManager, {
+		GetAuraTemplate: name => {
+			switch(name)
+			{
+			case "test_global":
+				return {
+					"type": "global",
+					"affects": ["CorrectClass"],
+					"modifications": [{ "value": "Component/Value", "add": 10 }],
+					"auraName": "name",
+					"auraDescription": "description"
+				};
+			case "test_range":
+				return {
+					"type": "range",
+					"radius": 40,
+					"affects": ["CorrectClass"],
+					"modifications": [{ "value": "Component/Value", "add": 10 }],
+					"auraName": "name",
+					"auraDescription": "description"
+				};
+			case "test_garrisonedUnits":
+				return {
+					"type": "garrisonedUnits",
+					"affects": ["CorrectClass"],
+					"modifications": [{ "value": "Component/Value", "add": 10 }],
+					"auraName": "name",
+					"auraDescription": "description"
+				};
+			case "test_garrison":
+				return {
+					"type": "garrison",
+					"affects": ["CorrectClass"],
+					"modifications": [{ "value": "Component/Value", "add": 10 }],
+					"auraName": "name",
+					"auraDescription": "description"
+				};
+			case "test_formation":
+				return {
+					"type": "formation",
+					"affects": ["CorrectClass"],
+					"modifications": [{ "value": "Component/Value", "add": 10 }],
+					"auraName": "name",
+					"auraDescription": "description"
+				};
+			default:
+				return {};
+			}
+		}
+	});
+
+	AddMock(playerEnt, IID_Player, {
+		IsAlly: id => id == 1,
+		IsEnemy: id => id != 1,
+		GetPlayerID: () => 1,
+	});
+
+	AddMock(targetEnt, IID_Identity, {
+		GetClassesList: () => ["CorrectClass", "OtherClass"],
+	});
+
+	AddMock(auraEnt, IID_Position, {
+		GetPosition2D: () => new Vector2D(),
+	});
+
+	AddMock(targetEnt, IID_Position, {
+		GetPosition2D: () => new Vector2D(),
+	});
+
+	AddMock(auraEnt, IID_Ownership, {
+		GetOwner: () => 1,
+	});
+
+	ConstructComponent(SYSTEM_ENTITY, "AuraManager", {});
+	let cmpAuras = ConstructComponent(auraEnt, "Auras", { _string: name });
+
+	test_function(name, cmpAuras);
+}
+
+testAuras("test_global", (name, cmpAuras) => { cmpAuras.OnRangeUpdate({ "tag": 1, "added": [targetEnt], "removed": [] });
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 11);
+	TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 1, playerID, template), 11);
+});
+
+testAuras("test_range", (name, cmpAuras) => { cmpAuras.OnRangeUpdate({ "tag": 1, "added": [targetEnt], "removed": [] });
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 11);
+	TS_ASSERT_EQUALS(ApplyValueModificationsToTemplate("Component/Value", 1, playerID, template), 1);
+	cmpAuras.OnRangeUpdate({ "tag": 1, "added": [], "removed": [targetEnt] });
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 1);
+});
+
+testAuras("test_garrisonedUnits", (name, cmpAuras) => { cmpAuras.OnGarrisonedUnitsChanged({ "added" : [targetEnt], "removed": [] });
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 11);
+	cmpAuras.OnGarrisonedUnitsChanged({ "added" : [], "removed": [targetEnt] });
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 1);
+});
+
+testAuras("test_garrison", (name, cmpAuras) => {
+	TS_ASSERT_EQUALS(cmpAuras.HasGarrisonAura(), true);
+	cmpAuras.ApplyGarrisonBonus(targetEnt);
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 11);
+	 cmpAuras.RemoveGarrisonBonus(targetEnt);
+	 TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 1);
+});
+
+testAuras("test_formation", (name, cmpAuras) => {
+	TS_ASSERT_EQUALS(cmpAuras.HasFormationAura(), true);
+	cmpAuras.ApplyFormationBonus([targetEnt]);
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 11);
+	cmpAuras.RemoveFormationBonus([targetEnt]);
+	TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 1);
 });
-
-AddMock(SYSTEM_ENTITY, IID_RangeManager, {
-	CreateActiveQuery: function(ent, minRange, maxRange, players, iid, flags) {
-		return 1;
-	},
-	EnableActiveQuery: function(id) { },
-	ResetActiveQuery: function(id) { if (mode == 0) return []; else return [enemy]; },
-	DisableActiveQuery: function(id) { },
-	GetEntityFlagMask: function(identifier) { },
-});
-
-AddMock(SYSTEM_ENTITY, IID_DataTemplateManager, {
-	GetAuraTemplate: function(name) {
-		if (name == "test1")
-			return {
-				"type": "global",
-				"affects": ["CorrectClass"],
-				"modifications": [ { "value": "Component/Value", "add": 1 } ],
-				"auraName": "name",
-				"auraDescription": "description"
-			};
-		return {};
-	},
-});
-
-AddMock(playerEnt1, IID_Player, {
-	IsAlly: function(id) { return id == 1; },
-	IsEnemy: function(id) { return id != 1; },
-	GetPlayerID: function() { return 1; },
-});
-
-AddMock(targetEnt, IID_Identity, {
-	GetClassesList: function() { return ["CorrectClass"]; },
-});
-
-AddMock(auraEnt, IID_Position, {
-	GetPosition2D: function() { return new Vector2D(); },
-});
-
-AddMock(targetEnt, IID_Position, {
-	// target ent at 20m distance from aura ent
-	GetPosition2D: function() { return new Vector2D(); },
-});
-
-AddMock(targetEnt, IID_Ownership, {
-	GetOwner: function() { return 1; },
-});
-
-AddMock(auraEnt, IID_Ownership, {
-	GetOwner: function() { return 1; },
-});
-
-ConstructComponent(SYSTEM_ENTITY, "AuraManager", {});
-var auras = ConstructComponent(auraEnt, "Auras", {_string: "test1"});
-
-// send the rangeManager message
-auras.OnRangeUpdate({"tag": 1, "added": [30], "removed": []});
-
-TS_ASSERT_EQUALS(ApplyValueModificationsToEntity("Component/Value", 1, targetEnt), 2);
