setName('Role'); $role->setIsAdmin(true); $this->em->persist($role); $user = new User(); $user->setFirstName('John'); $user->setLastName('Doe'); $user->setUsername('john.doe'); $user->setEmail('john.doe@email.com'); $user->setRole($role); $encoder = static::getContainer()->get('security.encoder_factory')->getEncoder($user); $user->setPassword($encoder->encodePassword('mautic', null)); $this->em->persist($user); $this->em->flush(); $this->em->clear(); // Login newly created non-admin user $this->loginUser($user->getUserIdentifier()); $this->client->setServerParameter('PHP_AUTH_USER', $user->getUserIdentifier()); $this->client->setServerParameter('PHP_AUTH_PW', 'mautic'); $this->client->request(Request::METHOD_GET, '/s/logout'); $clientResponse = $this->client->getResponse(); Assert::assertSame(Response::HTTP_OK, $clientResponse->getStatusCode()); Assert::assertStringContainsString( 'login', $clientResponse->getContent() ); } }