ForceMapTest.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using Content.Server.Maps;
  2. using Content.Shared.CCVar;
  3. using Robust.Shared.Configuration;
  4. using Robust.Shared.Console;
  5. namespace Content.IntegrationTests.Tests.Commands;
  6. [TestFixture]
  7. public sealed class ForceMapTest
  8. {
  9. private const string DefaultMapName = "Nomads";
  10. private const string BadMapName = "asdf_asd-fa__sdfAsd_f"; // Hopefully no one ever names a map this...
  11. private const string TestMapEligibleName = "ForceMapTestEligible";
  12. private const string TestMapIneligibleName = "ForceMapTestIneligible";
  13. [TestPrototypes]
  14. private static readonly string TestMaps = @$"
  15. - type: gameMap
  16. id: {TestMapIneligibleName}
  17. mapName: {TestMapIneligibleName}
  18. mapPath: /Maps/civ/nomads.yml
  19. minPlayers: 20
  20. maxPlayers: 80
  21. stations:
  22. Empty:
  23. stationProto: StandardStationArena
  24. components:
  25. - type: StationNameSetup
  26. mapNameTemplate: ""Nomads Test""
  27. - type: gameMap
  28. id: {TestMapEligibleName}
  29. mapName: {TestMapEligibleName}
  30. mapPath: /Maps/civ/nomads.yml
  31. minPlayers: 0
  32. stations:
  33. Empty:
  34. stationProto: StandardStationArena
  35. components:
  36. - type: StationNameSetup
  37. mapNameTemplate: ""Nomads Test""
  38. ";
  39. [Test]
  40. public async Task TestForceMapCommand()
  41. {
  42. await using var pair = await PoolManager.GetServerClient();
  43. var server = pair.Server;
  44. var entMan = server.EntMan;
  45. var configManager = server.ResolveDependency<IConfigurationManager>();
  46. var consoleHost = server.ResolveDependency<IConsoleHost>();
  47. var gameMapMan = server.ResolveDependency<IGameMapManager>();
  48. await server.WaitAssertion(() =>
  49. {
  50. // Make sure we're set to the default map
  51. Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(DefaultMapName),
  52. $"Test didn't start on expected map ({DefaultMapName})!");
  53. // Try changing to a map that doesn't exist
  54. consoleHost.ExecuteCommand($"forcemap {BadMapName}");
  55. Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(DefaultMapName),
  56. $"Forcemap succeeded with a map that does not exist ({BadMapName})!");
  57. // Try changing to a valid map
  58. consoleHost.ExecuteCommand($"forcemap {TestMapEligibleName}");
  59. Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(TestMapEligibleName),
  60. $"Forcemap failed with a valid map ({TestMapEligibleName})");
  61. // Try changing to a map that exists but is ineligible
  62. consoleHost.ExecuteCommand($"forcemap {TestMapIneligibleName}");
  63. Assert.That(gameMapMan.GetSelectedMap()?.ID, Is.EqualTo(TestMapIneligibleName),
  64. $"Forcemap failed with valid but ineligible map ({TestMapIneligibleName})!");
  65. // Try clearing the force-selected map
  66. consoleHost.ExecuteCommand("forcemap \"\"");
  67. Assert.That(gameMapMan.GetSelectedMap(), Is.Null,
  68. $"Running 'forcemap \"\"' did not clear the forced map!");
  69. });
  70. // Cleanup
  71. configManager.SetCVar(CCVars.GameMap, DefaultMapName);
  72. await pair.CleanReturnAsync();
  73. }
  74. }