diff --git a/docs/testing/testing-cheatsheet.md b/docs/testing/testing-cheatsheet.md index c8c4cf47..507007f9 100644 --- a/docs/testing/testing-cheatsheet.md +++ b/docs/testing/testing-cheatsheet.md @@ -87,7 +87,7 @@ public function testClientReadPageAction_authenticated(): void // Add needed database values to correctly display the page $clientRow = $this->insertFixturesWithAttributes(['user_id' => $userId, 'client_status_id' => $clientStatusId], - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userId); $request = $this->createRequest('GET', $this->urlFor('client-read-page', ['client_id' => '1'])); @@ -382,7 +382,7 @@ public function testNoteListAction( ['is_main' => 0, 'client_id' => $clientRow['id'], 'user_id' => $userLinkedToNoteRow['id']], new NoteFixture() ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $authenticatedUserRow['id']); // Make request $request = $this->createJsonRequest('GET', $this->urlFor('note-list'))->withQueryParams(['client_id' => '1']); diff --git a/tests/Integration/Authentication/LoginPageActionTest.php b/tests/Integration/Authentication/LoginPageActionTest.php index dfd5a475..e1d3f61a 100644 --- a/tests/Integration/Authentication/LoginPageActionTest.php +++ b/tests/Integration/Authentication/LoginPageActionTest.php @@ -40,7 +40,7 @@ public function testLoginPageActionAlreadyLoggedIn(): void { // Insert authenticated user $userId = $this->insertFixturesWithAttributes([], new UserFixture())['id']; - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userId); // Prepare route to test the case when the user clicks on a login link with a redirect route $requestRouteAfterLogin = $this->urlFor('client-read-page', ['client_id' => '1']); diff --git a/tests/Integration/Client/ClientListActionTest.php b/tests/Integration/Client/ClientListActionTest.php index 4e9b524c..05006f81 100644 --- a/tests/Integration/Client/ClientListActionTest.php +++ b/tests/Integration/Client/ClientListActionTest.php @@ -66,7 +66,7 @@ public function testClientListPageActionAuthorization(): void ); $request = $this->createRequest('GET', $this->urlFor('client-list-page')); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userRow['id']); $response = $this->app->handle($request); diff --git a/tests/Integration/Client/ClientReadPageActionTest.php b/tests/Integration/Client/ClientReadPageActionTest.php index 11491d5d..579a243a 100644 --- a/tests/Integration/Client/ClientReadPageActionTest.php +++ b/tests/Integration/Client/ClientReadPageActionTest.php @@ -45,7 +45,7 @@ public function testClientReadPageActionAuthenticated(): void ); $request = $this->createRequest('GET', $this->urlFor('client-read-page', ['client_id' => $clientRow['id']])); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $clientRow['user_id']); $response = $this->app->handle($request); diff --git a/tests/Integration/Client/ClientUpdateActionTest.php b/tests/Integration/Client/ClientUpdateActionTest.php index cabb9803..54eb6973 100644 --- a/tests/Integration/Client/ClientUpdateActionTest.php +++ b/tests/Integration/Client/ClientUpdateActionTest.php @@ -90,7 +90,7 @@ public function testClientSubmitUpdateActionAuthorization( $this->insertFixturesWithAttributes(['id' => $requestData['client_status_id']], new ClientStatusFixture()); } - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $authenticatedUserRow['id']); $request = $this->createJsonRequest( @@ -186,8 +186,8 @@ public function testClientSubmitUpdateActionInvalid(array $requestBody, array $j $requestBody ); - // Simulate logged-in user with logged-in user id - $this->container->get(SessionInterface::class)->set('user_id', $clientRow['user_id']); + // Simulate logged-in user by setting the user_id session variable + $this->container->get(SessionInterface::class)->set('user_id', $userId); $response = $this->app->handle($request); // Assert 200 OK @@ -247,7 +247,7 @@ public function testClientSubmitUpdateActionUnchangedContent(): void ); // Simulate logged-in user - $this->container->get(SessionInterface::class)->set('user_id', $clientRow['user_id']); + $this->container->get(SessionInterface::class)->set('user_id', $userId); $request = $this->createJsonRequest( 'PUT', diff --git a/tests/Integration/Dashboard/DashboardPageActionTest.php b/tests/Integration/Dashboard/DashboardPageActionTest.php index 5110a6ea..fe1fedd2 100644 --- a/tests/Integration/Dashboard/DashboardPageActionTest.php +++ b/tests/Integration/Dashboard/DashboardPageActionTest.php @@ -39,7 +39,7 @@ public function testDashboardPageActionAuthenticated(): void // A dashboard panel is for the status "action pending" and its id is retrieved by the code $this->insertFixturesWithAttributes(['name' => 'Action pending'], new ClientStatusFixture()); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $loggedInUserId); $request = $this->createRequest('GET', $this->urlFor('home-page')); diff --git a/tests/Integration/Dashboard/DashboardTogglePanelActionTest.php b/tests/Integration/Dashboard/DashboardTogglePanelActionTest.php index e4dca25a..90f908f4 100644 --- a/tests/Integration/Dashboard/DashboardTogglePanelActionTest.php +++ b/tests/Integration/Dashboard/DashboardTogglePanelActionTest.php @@ -35,7 +35,7 @@ public function testDashboardTogglePanelActionAuthenticated(): void // Insert linked and authenticated user $userId = $this->insertFixturesWithAttributes([], new UserFixture())['id']; - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userId); $request = $this->createJsonRequest( diff --git a/tests/Integration/Note/NoteListActionTest.php b/tests/Integration/Note/NoteListActionTest.php index f985e953..6ec2e935 100644 --- a/tests/Integration/Note/NoteListActionTest.php +++ b/tests/Integration/Note/NoteListActionTest.php @@ -88,7 +88,7 @@ public function testNoteListActionAuthorization( new NoteFixture() ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $authenticatedUserRow['id']); // Make request $request = $this->createJsonRequest('GET', $this->urlFor('note-list'))->withQueryParams(['client_id' => '1']); diff --git a/tests/Integration/Note/NoteReadPageActionTest.php b/tests/Integration/Note/NoteReadPageActionTest.php index 6fada8cf..ab771e73 100644 --- a/tests/Integration/Note/NoteReadPageActionTest.php +++ b/tests/Integration/Note/NoteReadPageActionTest.php @@ -46,7 +46,7 @@ public function testNoteReadPageActionAuthenticated(): void new UserFixture() )['id']; - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userId); // *Test request on NOT existing note diff --git a/tests/Integration/User/PasswordChangeSubmitActionTest.php b/tests/Integration/User/PasswordChangeSubmitActionTest.php index 17ed5d57..2c027df5 100644 --- a/tests/Integration/User/PasswordChangeSubmitActionTest.php +++ b/tests/Integration/User/PasswordChangeSubmitActionTest.php @@ -150,7 +150,7 @@ public function testChangePasswordSubmitActionInvalid(array $requestBody, array $this->urlFor('change-password-submit', ['user_id' => $userRow['id']]), $requestBody ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userRow['id']); $response = $this->app->handle($request); // Assert 200 OK diff --git a/tests/Integration/User/UserCreateActionTest.php b/tests/Integration/User/UserCreateActionTest.php index 17f0d1d8..2cc2900a 100644 --- a/tests/Integration/User/UserCreateActionTest.php +++ b/tests/Integration/User/UserCreateActionTest.php @@ -75,7 +75,7 @@ public function testUserSubmitCreateAuthorization( $this->urlFor('user-create-submit'), $requestData ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $authenticatedUserRow['id']); $response = $this->app->handle($request); // Assert status code @@ -165,7 +165,7 @@ public function testUserSubmitCreateInvalid(array $requestBody, array $jsonRespo $this->urlFor('user-create-submit'), $requestBody ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userRow['id']); $response = $this->app->handle($request); // Assert 422 Unprocessable Entity, which means validation error if request body contains user_role_id @@ -190,7 +190,7 @@ public function testUserSubmitCreateEmailAlreadyExists(): void $this->addUserRoleId(['user_role_id' => UserRole::ADMIN]), new UserFixture() ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $adminRow['id']); $existingEmail = 'email@address.com'; diff --git a/tests/Integration/User/UserFetchActivityActionTest.php b/tests/Integration/User/UserFetchActivityActionTest.php index bd73ec56..10233457 100644 --- a/tests/Integration/User/UserFetchActivityActionTest.php +++ b/tests/Integration/User/UserFetchActivityActionTest.php @@ -46,7 +46,7 @@ public function testUserListActivityFetchAction(): void // Insert user activity to cover most possible code with this test $this->insertFixturesWithAttributes(['user_id' => $userId], new UserActivityFixture()); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userId); $request = $this->createJsonRequest('GET', $this->urlFor('user-get-activity')) @@ -78,7 +78,7 @@ public function testUserListActivityFetchActionWithoutQueryParams(): void $this->addUserRoleId(['user_role_id' => UserRole::NEWCOMER]), new UserFixture() )['id']; - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userId); $request = $this->createJsonRequest('GET', $this->urlFor('user-get-activity')); diff --git a/tests/Integration/User/UserListActionTest.php b/tests/Integration/User/UserListActionTest.php index 78116c93..866a6433 100644 --- a/tests/Integration/User/UserListActionTest.php +++ b/tests/Integration/User/UserListActionTest.php @@ -48,7 +48,7 @@ public function testUserListAuthorization( // Change user attributes to user data $this->insertUserFixturesWithAttributes($userRow, $authenticatedUserRow); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $authenticatedUserRow['id']); // Make request $request = $this->createJsonRequest('GET', $this->urlFor('user-list')); diff --git a/tests/Integration/User/UserListPageActionTest.php b/tests/Integration/User/UserListPageActionTest.php index 7455d1ae..3e089b4c 100644 --- a/tests/Integration/User/UserListPageActionTest.php +++ b/tests/Integration/User/UserListPageActionTest.php @@ -42,7 +42,7 @@ public function testUserListPageActionAuthenticatedUnauthorized(): void new UserFixture() ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userRow['id']); $request = $this->createRequest('GET', $this->urlFor('user-list-page')); @@ -67,7 +67,7 @@ public function testUserListPageActionAuthenticatedAuthorized(): void new UserFixture() ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userRow['id']); $request = $this->createRequest('GET', $this->urlFor('user-list-page')); diff --git a/tests/Integration/User/UserReadPageActionTest.php b/tests/Integration/User/UserReadPageActionTest.php index 1218e193..40f2fbe0 100644 --- a/tests/Integration/User/UserReadPageActionTest.php +++ b/tests/Integration/User/UserReadPageActionTest.php @@ -40,7 +40,7 @@ public function testClientReadPageActionAuthorization( // Insert tested and authenticated user $this->insertUserFixturesWithAttributes($userData, $authenticatedUserData); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $authenticatedUserData['id']); $request = $this->createRequest('GET', $this->urlFor('user-read-page', ['user_id' => $userData['id']])); diff --git a/tests/Integration/User/UserUpdateActionTest.php b/tests/Integration/User/UserUpdateActionTest.php index 3fddab4f..75676e4e 100644 --- a/tests/Integration/User/UserUpdateActionTest.php +++ b/tests/Integration/User/UserUpdateActionTest.php @@ -66,7 +66,7 @@ public function testUserSubmitUpdateAuthorization( $this->urlFor('user-update-submit', ['user_id' => $userToChangeRow['id']]), $requestData ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $authenticatedUserRow['id']); $response = $this->app->handle($request); // Assert status code @@ -131,6 +131,7 @@ public function testUserSubmitUpdateInvalid(array $requestBody, array $jsonRespo { // Insert user that is allowed to change content (advisor owner) $userRow = $this->insertFixturesWithAttributes( + // Replace user_role_id enum case with database id with AuthorizationTestTrait function addUserRoleId() $this->addUserRoleId(['user_role_id' => UserRole::ADVISOR]), new UserFixture() ); @@ -140,7 +141,7 @@ public function testUserSubmitUpdateInvalid(array $requestBody, array $jsonRespo $this->urlFor('user-update-submit', ['user_id' => $userRow['id']]), $requestBody ); - // Simulate logged-in user with logged-in user id + // Simulate logged-in user by setting the user_id session variable $this->container->get(SessionInterface::class)->set('user_id', $userRow['id']); $response = $this->app->handle($request); // Assert 200 OK diff --git a/tests/Provider/User/UserUpdateProvider.php b/tests/Provider/User/UserUpdateProvider.php index 4b335eaf..b2d7fce0 100644 --- a/tests/Provider/User/UserUpdateProvider.php +++ b/tests/Provider/User/UserUpdateProvider.php @@ -3,12 +3,10 @@ namespace App\Test\Provider\User; use App\Domain\User\Enum\UserRole; -use App\Test\Traits\FixtureTestTrait; use Fig\Http\Message\StatusCodeInterface; class UserUpdateProvider { - use FixtureTestTrait; /** * @return array[]