| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using Content.Server.Maps;
- using Content.Shared.CCVar;
- using Robust.Shared.Configuration;
- using Robust.Shared.Console;
- namespace Content.IntegrationTests.Tests.Commands;
- [TestFixture]
- public sealed class ForceMapTest
- {
- private const string DefaultMapName = "Nomads";
- private const string BadMapName = "asdf_asd-fa__sdfAsd_f"; // Hopefully no one ever names a map this...
- private const string TestMapEligibleName = "ForceMapTestEligible";
- private const string TestMapIneligibleName = "ForceMapTestIneligible";
- [TestPrototypes]
- private static readonly string TestMaps = @$"
- - type: gameMap
- id: {TestMapIneligibleName}
- mapName: {TestMapIneligibleName}
- mapPath: /Maps/civ/nomads.yml
- minPlayers: 20
- maxPlayers: 80
- stations:
- Empty:
- stationProto: StandardStationArena
- components:
- - type: StationNameSetup
- mapNameTemplate: ""Nomads Test""
- - type: gameMap
- id: {TestMapEligibleName}
- mapName: {TestMapEligibleName}
- mapPath: /Maps/civ/nomads.yml
- minPlayers: 0
- stations:
- Empty:
- stationProto: StandardStationArena
- components:
- - type: StationNameSetup
- mapNameTemplate: ""Nomads Test""
- ";
- [Test]
- public async Task TestForceMapCommand()
- {
- await using var pair = await PoolManager.GetServerClient();
- var server = pair.Server;
- var entMan = server.EntMan;
- var configManager = server.ResolveDependency<IConfigurationManager>();
- var consoleHost = server.ResolveDependency<IConsoleHost>();
- var gameMapMan = server.ResolveDependency<IGameMapManager>();
- await server.WaitAssertion(() =>
- {
- // Make sure we're set to the default map
- Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(DefaultMapName),
- $"Test didn't start on expected map ({DefaultMapName})!");
- // Try changing to a map that doesn't exist
- consoleHost.ExecuteCommand($"forcemap {BadMapName}");
- Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(DefaultMapName),
- $"Forcemap succeeded with a map that does not exist ({BadMapName})!");
- // Try changing to a valid map
- consoleHost.ExecuteCommand($"forcemap {TestMapEligibleName}");
- Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(TestMapEligibleName),
- $"Forcemap failed with a valid map ({TestMapEligibleName})");
- // Try changing to a map that exists but is ineligible
- consoleHost.ExecuteCommand($"forcemap {TestMapIneligibleName}");
- Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(TestMapIneligibleName),
- $"Forcemap failed with valid but ineligible map ({TestMapIneligibleName})!");
- // Try clearing the force-selected map
- consoleHost.ExecuteCommand("forcemap \"\"");
- Assert.That(gameMapMan.GetSelectedMap(), Is.Null,
- $"Running 'forcemap \"\"' did not clear the forced map!");
- });
- // Cleanup
- configManager.SetCVar(CCVars.GameMap, DefaultMapName);
- await pair.CleanReturnAsync();
- }
- }
|