I'd like to be able to create a simple test or a type of test to have a user login (I have a helper for that) as a certain role (right now I have an admin and normal user role) then check all possible URLs (probably 5-7 controllers, each with it's own new/edit methods) starting from the root page and just make sure the http response is correct or that it is not giving off any errors.
What's the best way to implement this without having to write a function/test for every one of the pages? Or is there not one?
You can probably write a functional test which just surfs around the website.
/** @test */
public function it_lets_the_users_with_a_role_of_member_to_visit_only_specific_pages()
{
// call your login helper here before visiting the pages.
$this->visit('/pageone')
->see('Some text on the page')
->visit('/pagetwo')
->see('Some text on the page')
->visit('/pagethree')
->see('Some text on the page')
->visit('/pagefour')
->see('Some text on the page');
}
@Ruffles Any ideas on what I can do to randomly pick an url from a list? If I have PostController, I would have something like /posts/ but I'd like to be able to view a post like /posts/12 but I wouldn't be able to know if the ID exists and I would prefer not to hard code it.
You can use TestDummy for that (which is included by default with the model factories). $faker->randomElement($arrayOfIds) will return you a random ID.
@Ruffles Well, couldn't I use rand() as well for that? I guess I was wondering if I could either query the database for a list of IDs or to just check the current page and see which IDs are showing.
Sure, you can do that but it may be different than querying the DB for a list of IDs with lists('id') and just passing that to randomElement(). I usually do it with faker whenever I need a random existing ID from the DB.