mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-10 09:42:29 +00:00
[MIRROR] Unit Tests Door/Airlock Access Working [MDB IGNORE] (#18568)
* Unit Tests Door/Airlock Access Working (#72461) I screwed up with my access changes (on my local, I made sure I could still open doors rather than be kept out of places), and #72458 fixes that. However, let's also add a unit test to prevent that regression again. We just do five different access "checks", and see if all five different scenarios should work as intended. As you can see, this PR will not pass unit tests. This is supposed to happen, because at the time of this PR is opened, we will be in a regression state that the aforementioned PR fixes. When the aforementioned PR is merged, it should clear CI without any difficulties (I know this because I ran the unit test myself) * Unit Tests Door/Airlock Access Working Co-authored-by: san7890 <the@san7890.com>
This commit is contained in:
@@ -629,3 +629,22 @@
|
||||
|
||||
/obj/machinery/door/airlock/glass_large/narsie_act()
|
||||
return
|
||||
|
||||
/// Subtype used in unit tests to ensure instant airlock opening/closing. Pretty much just excises everything that would delay the process or is un-needed for the sake of the test (sleeps, icon animations).
|
||||
/obj/machinery/door/airlock/instant
|
||||
|
||||
// set_density on both open and close procs has a check and return builtin.
|
||||
|
||||
/obj/machinery/door/airlock/instant/open(forced = FALSE)
|
||||
operating = TRUE
|
||||
SEND_SIGNAL(src, COMSIG_AIRLOCK_OPEN, forced)
|
||||
set_density(FALSE)
|
||||
operating = FALSE
|
||||
return TRUE
|
||||
|
||||
/obj/machinery/door/airlock/instant/close(forced = FALSE, force_crush = FALSE)
|
||||
operating = TRUE
|
||||
SEND_SIGNAL(src, COMSIG_AIRLOCK_CLOSE, forced)
|
||||
set_density(TRUE)
|
||||
operating = FALSE
|
||||
return TRUE
|
||||
|
||||
@@ -104,6 +104,7 @@
|
||||
#include "create_and_destroy.dm"
|
||||
#include "dcs_get_id_from_elements.dm"
|
||||
#include "designs.dm"
|
||||
#include "door_access.dm"
|
||||
#include "dragon_expiration.dm"
|
||||
#include "drink_icons.dm"
|
||||
#include "dummy_spawn.dm"
|
||||
|
||||
42
code/modules/unit_tests/door_access.dm
Normal file
42
code/modules/unit_tests/door_access.dm
Normal file
@@ -0,0 +1,42 @@
|
||||
/// Tests to make sure door access works correctly.
|
||||
/datum/unit_test/door_access_check
|
||||
|
||||
/datum/unit_test/door_access_check/Run()
|
||||
var/mob/living/carbon/human/subject = allocate(/mob/living/carbon/human/consistent, run_loc_floor_bottom_left)
|
||||
var/obj/machinery/door/airlock/instant/door = allocate(/obj/machinery/door/airlock/instant, run_loc_floor_bottom_left, EAST) //special subtype that just flips the density var on open() and close(), akin to a real airlock.
|
||||
|
||||
// First, test that someone without any access can open a door that doesn't have any access requirements. Let's test it via using the bumpopen() proc, called when someone bumps into the door.
|
||||
door.bumpopen(subject)
|
||||
TEST_ASSERT_EQUAL(door.density, FALSE, "Subject failed to open access-free airlock!")
|
||||
door.close() // close it here as well
|
||||
|
||||
// Alright, now let's test that someone with access can open a door that requires access when only req_access is set.
|
||||
subject.equipOutfit(/datum/outfit/job/assistant/consistent) // set up the outfit here to ensure the last check is pure.
|
||||
var/obj/item/card/id/advanced/keycard = subject.wear_id
|
||||
|
||||
// Test two accesses at once just to make sure the script hasn't changed on us.
|
||||
keycard.access = list(ACCESS_ENGINEERING, ACCESS_MAINT_TUNNELS)
|
||||
door.req_access = list(ACCESS_ENGINEERING, ACCESS_MAINT_TUNNELS)
|
||||
door.bumpopen(subject)
|
||||
TEST_ASSERT_EQUAL(door.density, FALSE, "Subject with valid access failed to open airlock access-locked behind req_access!")
|
||||
door.close()
|
||||
|
||||
// Okay, now let's edit the req_access on the door to make sure the subject can't open it with the requirements of req_access (must have all accesses required on keycard to open door).
|
||||
door.req_access = list(ACCESS_ENGINEERING, ACCESS_MAINT_TUNNELS, ACCESS_CARGO)
|
||||
door.bumpopen(subject)
|
||||
TEST_ASSERT_EQUAL(door.density, TRUE, "Subject with invalid access succeeded in opening airlock access-locked behind req_access!")
|
||||
door.close() // included for completeness, will early return if the door is already closed.
|
||||
|
||||
// Alright, now to test req_one_access. The two systems should be mutually exclusive, so we'll reset the access on the keycard and the door before we continue..
|
||||
door.req_access = null
|
||||
door.req_one_access = list(ACCESS_ENGINEERING, ACCESS_MAINT_TUNNELS)
|
||||
keycard.access = list(ACCESS_MAINT_TUNNELS)
|
||||
door.bumpopen(subject)
|
||||
TEST_ASSERT_EQUAL(door.density, FALSE, "Subject with valid access failed to open airlock access-locked behind req_one_access!")
|
||||
door.close()
|
||||
|
||||
// Now, let's test req_one_access with an invalid access. The keycard is still on ACCESS_MAINT_TUNNELS from last step.
|
||||
door.req_one_access = list(ACCESS_ENGINEERING, ACCESS_CARGO)
|
||||
door.bumpopen(subject)
|
||||
TEST_ASSERT_EQUAL(door.density, TRUE, "Subject with invalid access succeeded in opening airlock access-locked behind req_one_access!")
|
||||
door.close()
|
||||
Reference in New Issue
Block a user