Skip to content
Snippets Groups Projects
Select Git revision
  • 355ba7540f336b06e56a446a75c1c58d70377a63
  • main default
  • 35-cgu
  • 34-peertube-support
  • 27-add-autoplay-to-iframe
  • 33-bug-on-youtube-embed-urls
  • RC-Rekall-v1.1-fix_lpo
  • tuleap-140-go-back-to-my-capsules-page-when-i-m-on-capsule-preview-page
  • RC-Rekall-v1.2-fix10
  • RC-Rekall-v1.2-fix9
  • RC-Rekall-v1.2-fix8
  • RC-Rekall-v1.2-fix7
  • RC-Rekall-v1.2-fix6
  • RC-Rekall-v1.2-fix5
  • RC-Rekall-v1.2-fix4
  • RC-Rekall-v1.2-fix3
  • RC-Rekall-v1.2-fix2
  • RC-Rekall-v1.2-fix1
  • RC-Rekall-v1.1-fix-3
  • RC-Rekall-v1.1-fix-2
  • RC-Rekall-v1.1-fix-1
  • RC-Rekall-v1.1-delivered
  • preprod20220209-1535
23 results

BasePageTest.php

Blame
  • BasePageTest.php 1.73 KiB
    <?php
    
    namespace App\Tests\acceptance;
    
    use App\Entity\User;
    use Symfony\Bundle\FrameworkBundle\KernelBrowser;
    use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
    
    abstract class BasePageTest extends WebTestCase
    {
        protected KernelBrowser $client;
        protected ?User $user;
    
        protected function givenUser(string $userName): BasePageTest
        {
            $object_manager = $this->client->getContainer()
                ->get('doctrine')
                ->getManager();
            $user_repository = $object_manager->getRepository(User::class);
            $user = $user_repository
                ->findOneBy(['email' => $userName ]);
    
            if (! $user instanceof User) {
                throw new \Exception("User does not exist.");
            }
    
            $this->user = $user;
    
            return $this;
        }
    
        protected function onPage(string $uri): BasePageTest
        {
            $this->client->request('GET', $uri);
            $this->assertResponseIsSuccessful();
    
            return $this;
        }
    
        protected function clickLink(string $linkText, ?string $errorMessageText): BasePageTest
        {
            $this->client->clickLink($linkText);
            $this->assertResponseIsSuccessful($errorMessageText ?? '');
    
            return $this;
        }
    
        /**
         * @throws \Exception the user is not initialized
         */
        protected function logged(): BasePageTest
        {
            if (null === $this->user) {
                throw new \Exception("User is not initialized.");
            }
            $this->client->loginUser($this->user);
    
            return $this;
        }
    
        protected function setUp(): void
        {
            self::ensureKernelShutdown();
    
            $this->client = static::createClient();
        }
    
        protected function tearDown(): void
        {
            parent::tearDown();
            self::ensureKernelShutdown();
        }
    }