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

Add functional tests

parent 7f1b2a13
No related branches found
No related tags found
1 merge request!48tuleap-133-change-the-video-url-of-a-capsule
...@@ -46,12 +46,7 @@ class ProjectControllerTest extends WebTestCase ...@@ -46,12 +46,7 @@ class ProjectControllerTest extends WebTestCase
{ {
parent::tearDown(); parent::tearDown();
$capsule_repository = $this->object_manager->getRepository(Capsule::class); $capsule = $this->getLastCapsuleInDb();
$capsule = $capsule_repository->findOneBy(['name' => self::CAPSULE_NAME]);
if (! $capsule instanceof Capsule) {
throw new \Exception("Capsule does not exist.");
}
$this->deleteCapsuleDirectoryAndInDatabase($capsule); $this->deleteCapsuleDirectoryAndInDatabase($capsule);
} }
...@@ -234,6 +229,40 @@ class ProjectControllerTest extends WebTestCase ...@@ -234,6 +229,40 @@ class ProjectControllerTest extends WebTestCase
$this->deleteCapsuleDirectoryAndInDatabase($duplicated_capsule_in_db); $this->deleteCapsuleDirectoryAndInDatabase($duplicated_capsule_in_db);
} }
public function testVideoUrlNodeAttributeInXMLFileShouldBeUpdatedWhenUserEditVideoUrl(): void
{
$capsule = $this->createCapsule();
$crawler = $this->client->request('GET', '/capsule/' . $capsule->getId() . '/edit_video_url');
$this->assertResponseIsSuccessful();
$this->client->enableProfiler();
$submit_button = $crawler->selectButton('Save');
$this->form = $submit_button->form();
$new_video_url = "https://youtu.be/tQwVKr8rCYw";
$this->form['edit_video_url_form[new_video_url]'] = $new_video_url;
$this->client->submit($this->form);
$this->client->followRedirect();
$this->assertResponseIsSuccessful('/my_capsules');
$capsule_directory = $capsule->getLinkPath();
$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($new_video_url, $video_url_in_xml_file);
}
private function assertAllFilesOfFileDirectoryAreSameExceptPasswordOne( private function assertAllFilesOfFileDirectoryAreSameExceptPasswordOne(
string $parent_capsule_directory, string $parent_capsule_directory,
string $duplicated_capsule_directory string $duplicated_capsule_directory
...@@ -254,7 +283,7 @@ class ProjectControllerTest extends WebTestCase ...@@ -254,7 +283,7 @@ class ProjectControllerTest extends WebTestCase
} }
} }
private function createCapsule(): void private function createCapsule(): Capsule
{ {
$crawler = $this->client->request('GET', '/create'); $crawler = $this->client->request('GET', '/create');
$this->assertResponseIsSuccessful(); $this->assertResponseIsSuccessful();
...@@ -285,6 +314,8 @@ class ProjectControllerTest extends WebTestCase ...@@ -285,6 +314,8 @@ class ProjectControllerTest extends WebTestCase
null, null,
['override' => true] ['override' => true]
); );
return $capsule;
} }
private function deleteCapsuleDirectoryAndInDatabase(Capsule $capsule): void private function deleteCapsuleDirectoryAndInDatabase(Capsule $capsule): void
...@@ -298,4 +329,16 @@ class ProjectControllerTest extends WebTestCase ...@@ -298,4 +329,16 @@ class ProjectControllerTest extends WebTestCase
$this->object_manager->remove($capsule_to_delete); $this->object_manager->remove($capsule_to_delete);
$this->object_manager->flush(); $this->object_manager->flush();
} }
private function getLastCapsuleInDb(): Capsule
{
$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.");
}
return $capsule;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment