Welcome Guest, Not a member yet? Register   Sign In
phpunit testing routes only available after login
#10

(This post was last modified: 08-07-2023, 03:22 AM by dgvirtual.)

(08-07-2023, 02:25 AM)kenjis Wrote: Yes, we can test only one request and the response at a time.
When the page gets redirected, the browser will send a new request and gets the page you see.

So if you want to test the page, you need to send another request in the test.
You need to do what the browser normally does in the test code.
To actually do this is tedious because you must write the code to make the state like the session state, etc., the same. Therefore, I don't recommend it.
Thanks @kenjis.

I must have discovered a bug in CI4... when run through tests the function in the code being tested uri_string() (and the underlying Services::request()->getPath(); ) somehow omits the last segment of the uri. Same function when used in the test itself returns the full uri...

Code in test:
PHP Code:
$route route_to('invoice_add'); //(resolves to invoices/add);
$result $this->call('post'$route$postArray); 
The route resolves correctly (and I get the page I want to test). However, I have a breadcrumbs library that uses uri_string() to determine what breadcrumbs to show, so it shows the breadcrumb for invoices/ page.
==

Donatas G.
Reply


Messages In This Thread
RE: phpunit testing routes only available after login - by dgvirtual - 08-07-2023, 02:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB