Skip to content
Snippets Groups Projects
Select Git revision
  • 4528fb118ad0ac4c44190e9fff84a8fdd623dcca
  • demo_ci_gitlab_pages default
  • demo_gitlab_ci
  • 5-images-in-annotations
  • 5-final-images
  • 5-chpk-images-in-annot
  • tetras-main protected
  • 5-rebase-images-in-annot
  • 5-wip-images-in-annot
  • tmp
  • 1-edit-annotations-on-videos
  • 5-old-images-in-annotations
  • old_demo_ci_gitlab_pages
  • images_annotations
  • wip
  • devsetup
  • wip-annot-video-ui
  • wip-annotations-on-videos
  • master
  • v0.4.0_react16
  • wip-debugging-annotations
21 results

jest.config.js

Blame
  • Forked from IIIF / Mirador / Mirador annotations
    Source project has a limited visibility.
    ProjectControllerTest.php 4.43 KiB
    <?php
    
    namespace App\Tests\functional;
    
    use App\Entity\Capsule;
    use App\Entity\User;
    use Doctrine\Persistence\ObjectManager;
    use Symfony\Bundle\FrameworkBundle\KernelBrowser;
    use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
    use Symfony\Component\DomCrawler\Form;
    use Symfony\Component\Filesystem\Filesystem;
    use Symfony\Config\TwigExtra\StringConfig;
    
    class ProjectControllerTest extends WebTestCase
    {
        private KernelBrowser $client;
        private ObjectManager $object_manager;
        private Form $form;
        private const TEST_DIR_PATH = __DIR__ . '/../../legacy/';
        private const CAPSULE_NAME = 'TestCapsuleName';
        private const CAPSULE_DIR_PATH = self::TEST_DIR_PATH . self::CAPSULE_NAME;
        private const XML_FILE_PATH = self::CAPSULE_DIR_PATH . '/file/project.xml';
    
        protected function setUp(): void
        {
            chdir(self::TEST_DIR_PATH);
    
            self::ensureKernelShutdown();
            $this->client = static::createClient();
    
            $this->object_manager = $this->client->getContainer()
                ->get('doctrine')
                ->getManager();
    
            $verified_user = $this->object_manager
                ->getRepository(User::class)
                ->findOneBy(['email' => 'defaultUser@localhost.com'])
            ;
    
            if (! $verified_user instanceof User) {
                throw new \Exception("User does not exist.");
            }
    
            $this->client->loginUser($verified_user);
    
            $crawler = $this->client->request('GET', '/create');
            $this->assertResponseIsSuccessful();
    
            $this->client->enableProfiler();
    
            $submit_button = $crawler->selectButton('Create a capsule');
            $this->form = $submit_button->form();
        }
    
        protected function tearDown(): void
        {
            parent::tearDown();
            $file_system = new Filesystem();
            $file_system->remove(self::TEST_DIR_PATH . self::CAPSULE_NAME);
    
            $capsule_repository = $this->object_manager->getRepository(Capsule::class);
            $last_capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
    
            if (! $last_capsule instanceof Capsule) {
                throw new \Exception("Capsule does not exist.");
            }
    
            $this->object_manager->remove($last_capsule);
            $this->object_manager->flush();
        }
    
        /** @phpstan-ignore-next-line */
        private function getDOMDocument(string $capsule_directory): \DOMDocument
        {
            $dom_xml = new \DOMDocument();
            $dom_xml->preserveWhiteSpace = false;
            $dom_xml->load($this->createXmlFilePath($capsule_directory));
    
            return $dom_xml;
        }
    
        private function createCapsuleDirPath(string $capsule_directory): string
        {
            return self::TEST_DIR_PATH . $capsule_directory;
        }
    
        private function createXmlFilePath(string $capsule_directory): string
        {
            return $this->createCapsuleDirPath($capsule_directory) . '/file/project.xml';
        }
    
        public function testProjectDirectoryWithCorrespondingXMLFileIsCreatedWhenCapsuleCreationIsSuccessful(): void
        {
            $video_url = "https://TestUrl";
            $this->form['create_capsule_form[name]'] = self::CAPSULE_NAME;
            $this->form['create_capsule_form[video_url]'] = $video_url;
    
            $this->client->submit($this->form);
    
            $this->assertResponseRedirects(
                '/my_capsules',
                302,
                'Once the capsule is created, the user should be redirected to its capsules lists'
            );
    
            $this->client->followRedirect();
            $this->assertResponseIsSuccessful('/my_capsules');
    
            $capsule_repository = $this->object_manager->getRepository(Capsule::class);
            $capsule_in_db = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
    
            if (! $capsule_in_db instanceof Capsule) {
                throw new \Exception("Capsule does not exist.");
            }
    
            $capsule_name_in_db = $capsule_in_db->getName();
            $capsule_directory = $capsule_in_db->getPreviewLink();
    
            $this->assertDirectoryExists($capsule_directory);
            $this->assertDirectoryIsReadable($capsule_directory);
    
            $dom_xml = self::getDomDocument($capsule_directory);
            $video_node = $dom_xml->getElementsByTagName('video')->item(0);
    
            if ($video_node === null) {
                throw new \Exception("Video node could not be found in XML project file");
            }
    
            $video_url_in_xml_file = $video_node->getAttribute('url');
    
            $this->assertEquals($video_url, $video_url_in_xml_file);
            $this->assertSame(self::CAPSULE_NAME, $capsule_name_in_db);
        }
    }