Testing code with IP control

Re: Testing code with IP control

by Tim Hunt -
Number of replies: 0
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Again, what makes you think that is_addr_ok is a core function? Your first post in this thread started "We have a complex code using IP control". I assume you want to test your complex code. 

And, I am suggesting you refactor it so that the complex logic ends up in a pure function that is easy to unit test.

Once you know the back-end logic returns the right answer for all combinations of IP address, and restriction configuration, then you only really need two cases in Behat tests to verify that the back-end logic is correctly hooked up to the UI.

  1. You need a configuration where the user's current IP address is allowed; and
  2. configuration where the user's current IP address is blocked.

You can set that up with custom Behat steps to set the configuration relative to the user's current IP address. You don't need to fake the user's current IP address.