Skip to content
Snippets Groups Projects
Commit fc4b2c3f authored by Camille Simiand's avatar Camille Simiand
Browse files

Add functional tests

parent b930b393
No related branches found
No related tags found
1 merge request!44tuleap-80-duplicate-a-capsule
<?xml version="1.0"?>
<!DOCTYPE rekall>
<project>
<video url="https://youtu.be/Ssm_mm8zyS0"/>
<document key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d">
<meta ctg="Rekall-&gt;Author" cnt=""/>
<meta ctg="Rekall-&gt;Date/Time" cnt="2015:08:31 18:06:16"/>
<meta ctg="Rekall-&gt;Import Date" cnt="2015:08:31 18:06:16"/>
<meta ctg="Rekall User Infos-&gt;User Name" cnt=""/>
<meta ctg="Rekall-&gt;Location Name" cnt="48.867359621322265, 2.3618561655447228"/>
<meta ctg="Rekall-&gt;Location GPS" cnt="48.867359621322265, 2.3618561655447228"/>
<meta ctg="Rekall User Infos-&gt;User IP" cnt="127.0.0.1"/>
<meta ctg="Rekall-&gt;Comments" cnt=""/>
<meta ctg="Rekall-&gt;Keywords" cnt=""/>
<meta ctg="Rekall-&gt;Group" cnt=""/>
<meta ctg="Rekall-&gt;Visibility" cnt=""/>
<meta ctg="Rekall-&gt;Type" cnt="rekall/marker"/>
<meta ctg="Rekall-&gt;Flag" cnt="Marker"/>
<meta ctg="Rekall-&gt;Name" cnt="New note"/>
</document>
<tag key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d" timeStart="0" timeEnd="10" version="0"/>
</project>
tests/files_for_tests/image_for_test.jpeg

5.46 KiB

<?xml version="1.0"?>
<!DOCTYPE rekall>
<project>
<video url="https://youtu.be/dQw4w9WgXcQ"/>
<document key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d">
<meta ctg="Rekall-&gt;Author" cnt=""/>
<meta ctg="Rekall-&gt;Date/Time" cnt="2015:08:31 18:06:16"/>
<meta ctg="Rekall-&gt;Import Date" cnt="2015:08:31 18:06:16"/>
<meta ctg="Rekall User Infos-&gt;User Name" cnt=""/>
<meta ctg="Rekall-&gt;Location Name" cnt="48.867359621322265, 2.3618561655447228"/>
<meta ctg="Rekall-&gt;Location GPS" cnt="48.867359621322265, 2.3618561655447228"/>
<meta ctg="Rekall User Infos-&gt;User IP" cnt="127.0.0.1"/>
<meta ctg="Rekall-&gt;Comments" cnt=""/>
<meta ctg="Rekall-&gt;Keywords" cnt=""/>
<meta ctg="Rekall-&gt;Group" cnt=""/>
<meta ctg="Rekall-&gt;Visibility" cnt=""/>
<meta ctg="Rekall-&gt;Type" cnt="rekall/marker"/>
<meta ctg="Rekall-&gt;Flag" cnt="Marker"/>
<meta ctg="Rekall-&gt;Name" cnt="New note"/>
</document>
<tag key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d" timeStart="0" timeEnd="10" version="0"/>
<edition key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d" metadataKey="Rekall-&gt;Name" metadataValue="First note" version="0"/>
<edition key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d" metadataKey="Rekall-&gt;Comments" metadataValue="This is a note for tests purpose." version="0"/>
<edition key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d" metadataKey="Rekall-&gt;Link" metadataValue="https://youtu.be/dQw4w9WgXcQ" version="0"/>
<edition key="marker-1f10323d5f4a1c119e777e59c2f00dcc650e750d" metadataKey="Rekall-&gt;Author" metadataValue="Rick Astley" version="0"/>
<document key="marker-45f08bfa88924f466539f2ae41b509f7823929db">
<meta ctg="Rekall-&gt;Author" cnt=""/>
<meta ctg="Rekall-&gt;Date/Time" cnt="2022:01:21 14:09:09"/>
<meta ctg="Rekall-&gt;Import Date" cnt="2022:01:21 14:09:09"/>
<meta ctg="Rekall-&gt;Location Name" cnt=""/>
<meta ctg="Rekall-&gt;Location GPS" cnt=""/>
<meta ctg="Rekall User Infos-&gt;User Name" cnt=""/>
<meta ctg="Rekall User Infos-&gt;User IP" cnt="192.168.176.3"/>
<meta ctg="Rekall-&gt;Comments" cnt=""/>
<meta ctg="Rekall-&gt;Type" cnt="rekall/marker"/>
<meta ctg="Rekall-&gt;Flag" cnt="Marker"/>
<meta ctg="Rekall-&gt;Name" cnt="New note"/>
<meta ctg="key" cnt="marker-45f08bfa88924f466539f2ae41b509f7823929db"/>
</document>
<tag key="marker-45f08bfa88924f466539f2ae41b509f7823929db" timeStart="0" timeEnd="15" version="0"/>
<edition key="marker-45f08bfa88924f466539f2ae41b509f7823929db" metadataKey="Rekall-&gt;Name" metadataValue="Second note" version="0"/>
<edition key="marker-45f08bfa88924f466539f2ae41b509f7823929db" metadataKey="Rekall-&gt;Author" metadataValue="Bob" version="0"/>
<edition key="marker-45f08bfa88924f466539f2ae41b509f7823929db" metadataKey="Rekall-&gt;Comments" metadataValue="Empty" version="0"/>
<tag key="marker-45f08bfa88924f466539f2ae41b509f7823929db" timeStart="30" timeEnd="75" version="0"/>
<edition key="marker-45f08bfa88924f466539f2ae41b509f7823929db" metadataKey="Rekall-&gt;Link" metadataValue="http://undefined" version="0"/>
<tag key="marker-45f08bfa88924f466539f2ae41b509f7823929db" timeStart="30" timeEnd="75" version="0"/>
<edition key="marker-45f08bfa88924f466539f2ae41b509f7823929db" metadataKey="Rekall-&gt;Highlight" metadataValue="true" version="0"/>
<document>
<meta ctg="Rekall-&gt;Author" cnt=""/>
<meta ctg="File-&gt;File Access Date/Time" cnt="2022:01:21 15:10:38"/>
<meta ctg="File-&gt;File Creation Date/Time" cnt="2022:01:21 15:10:38"/>
<meta ctg="File-&gt;File Modification Date/Time" cnt="2022:01:21 15:10:38"/>
<meta ctg="Rekall-&gt;Date/Time" cnt="2022:01:21 15:10:38"/>
<meta ctg="Rekall-&gt;Import Date" cnt="2022:01:21 14:10:39"/>
<meta ctg="Rekall-&gt;Location Name" cnt=""/>
<meta ctg="Rekall-&gt;Location GPS" cnt=""/>
<meta ctg="Rekall User Infos-&gt;User Name" cnt=""/>
<meta ctg="Rekall User Infos-&gt;User IP" cnt="192.168.176.3"/>
<meta ctg="Rekall-&gt;Comments" cnt=""/>
<meta ctg="File-&gt;Hash" cnt="2B0F9FA5055C514A9464616416A1EA63A72FD88B"/>
<meta ctg="Rekall-&gt;Flag" cnt="File"/>
<meta ctg="File-&gt;Thumbnail" cnt=""/>
<meta ctg="File-&gt;Owner" cnt="www-data"/>
<meta ctg="File-&gt;MIME Type" cnt="image/jpeg"/>
<meta ctg="File-&gt;File Type" cnt="image/jpeg"/>
<meta ctg="Rekall-&gt;Type" cnt="image/jpeg"/>
<meta ctg="File-&gt;File Name" cnt="image_for_test.jpeg"/>
<meta ctg="File-&gt;Extension" cnt="jpeg"/>
<meta ctg="File-&gt;Basename" cnt="image_for_test"/>
<meta ctg="Rekall-&gt;Name" cnt="image_for_test"/>
<meta ctg="Rekall-&gt;Extension" cnt="JPEG"/>
<meta ctg="Rekall-&gt;Folder" cnt=""/>
<meta ctg="Rekall-&gt;File Size" cnt="5591"/>
<meta ctg="Rekall-&gt;File Size (MB)" cnt="0.0053319931030273"/>
<meta ctg="key" cnt="/image_for_test.jpeg"/>
</document>
<tag key="/image_for_test.jpeg" timeStart="0" timeEnd="15" version="0"/>
</project>
......@@ -17,6 +17,7 @@ class ProjectControllerTest extends WebTestCase
private Form $form;
private const TEST_DIR_PATH = __DIR__ . '/../../legacy/';
private const CAPSULE_NAME = 'TestCapsuleName';
private const TEST_FILES_DIRECTORY = "../tests/files_for_tests/";
protected function setUp(): void
{
......@@ -39,32 +40,20 @@ class ProjectControllerTest extends WebTestCase
}
$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);
$detached_last_capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
$capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
if (! $detached_last_capsule instanceof Capsule) {
if (! $capsule instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$last_capsule = $this->object_manager->merge($detached_last_capsule);
$this->object_manager->remove($last_capsule);
$this->object_manager->flush();
$this->deleteCapsuleDirectoryAndInDatabase($capsule);
}
/** @phpstan-ignore-next-line */
......@@ -94,6 +83,14 @@ class ProjectControllerTest extends WebTestCase
public function testProjectDirectoryWithCorrespondingXMLFileIsCreatedWhenCapsuleCreationIsSuccessful(): void
{
$crawler = $this->client->request('GET', '/create');
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Create a capsule');
$this->form = $submit_button->form();
$video_url = "https://TestUrl";
$this->form['create_capsule_form[name]'] = self::CAPSULE_NAME;
$this->form['create_capsule_form[video_url]'] = $video_url;
......@@ -137,11 +134,7 @@ class ProjectControllerTest extends WebTestCase
public function testProjectDirectoryWithCorrespondingPasswordFileIsCreatedWhenCapsuleCreationIsSuccessful(): 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->createCapsule();
$this->assertResponseRedirects(
'/my_capsules',
......@@ -159,7 +152,6 @@ class ProjectControllerTest extends WebTestCase
throw new \Exception("Capsule does not exist.");
}
$capsule_name_in_db = $capsule_in_db->getName();
$capsule_directory = $capsule_in_db->getLinkPath();
$this->assertDirectoryExists($capsule_directory);
......@@ -175,4 +167,135 @@ class ProjectControllerTest extends WebTestCase
"The password should be saved in projectPassword.txt file"
);
}
public function testDuplicatedDirectoryDuplicatedFilesFromParentWhenCapsuleDuplicationIsSuccessful(): void
{
$duplicated_capsule_name = 'duplicated ' . self::CAPSULE_NAME;
$this->createCapsule();
$capsule_repository = $this->object_manager->getRepository(Capsule::class);
$parent_capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
if (! $parent_capsule instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$parent_capsule_directory = $parent_capsule->getLinkPath();
$crawler = $this->client->request('GET', '/capsule/duplicate/' . $parent_capsule->getId());
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Validate');
$this->form = $submit_button->form();
$this->form['duplicate_capsule_form[name]'] = $duplicated_capsule_name;
$this->client->submit($this->form);
$this->assertResponseRedirects(
'/my_capsules',
302,
'Once the capsule is duplicated, the user should be redirected to its capsules lists'
);
$this->client->followRedirect();
$this->assertResponseIsSuccessful('/my_capsules');
$capsule_repository = $this->object_manager->getRepository(Capsule::class);
$duplicated_capsule_in_db = $capsule_repository->findOneBy(['name' => $duplicated_capsule_name]);
if (! $duplicated_capsule_in_db instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$duplicated_capsule_directory = $duplicated_capsule_in_db->getLinkPath();
$this->assertDirectoryExists($duplicated_capsule_directory);
$this->assertDirectoryIsReadable($duplicated_capsule_directory);
$this->assertXmlFileEqualsXmlFile(
$this->getXmlFilePath($duplicated_capsule_directory),
$this->getXmlFilePath($duplicated_capsule_directory)
);
$this->assertAllFilesOfFileDirectoryAreSameExceptPasswordOne(
$parent_capsule_directory,
$duplicated_capsule_directory
);
$password_file_path = $this->getPasswordFilePath($duplicated_capsule_directory);
$password = file_get_contents($password_file_path, true);
$this->assertTrue(false !== $password, "The projectPassword.txt should be readable");
$this->assertSame(
$duplicated_capsule_in_db->getPassword(),
$password,
"The password should be saved in projectPassword.txt file"
);
$this->deleteCapsuleDirectoryAndInDatabase($duplicated_capsule_in_db);
}
private function assertAllFilesOfFileDirectoryAreSameExceptPasswordOne(
string $parent_capsule_directory,
string $duplicated_capsule_directory
): void {
$parent_capsule_files = scandir($parent_capsule_directory . "/file/");
if (! is_array($parent_capsule_files)) {
return;
}
foreach ($parent_capsule_files as $key => $file) {
if ($file === "projectPassword.txt" || is_dir($file)) {
return;
}
$this->assertFileExists($duplicated_capsule_directory . "/file/" . $file);
$this->assertFileEquals($file, $duplicated_capsule_directory . "/file/" . $file);
}
}
private function createCapsule(): void
{
$crawler = $this->client->request('GET', '/create');
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Create a capsule');
$this->form = $submit_button->form();
$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);
$capsule_repository = $this->object_manager->getRepository(Capsule::class);
$capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
if (! $capsule instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$capsule_directory_path = $capsule->getLinkPath();
$file_system = new Filesystem();
$file_system->mirror(
self::TEST_FILES_DIRECTORY,
$capsule_directory_path . '/file/',
null,
['override' => true]
);
}
private function deleteCapsuleDirectoryAndInDatabase(Capsule $capsule): void
{
$file_system = new Filesystem();
$capsule_directory_path = $capsule->getLinkPath();
$file_system->remove(self::TEST_DIR_PATH . $capsule_directory_path);
$capsule_to_delete = $this->object_manager->merge($capsule);
$this->object_manager->remove($capsule_to_delete);
$this->object_manager->flush();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment