Skip to content
Snippets Groups Projects
Commit 0a4410b1 authored by Camille Simiand's avatar Camille Simiand Committed by Sebastien
Browse files

Display capsule content on homepage + display edit capsule

parent de48e414
No related branches found
No related tags found
3 merge requests!43tuleap-83-access-my-capsules,!42Draft: access-my-capsules-conflicts-fixed,!40Draft: Tuleap 83 access my capsules
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20211215152200 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE capsule (id INT AUTO_INCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, aut_crea VARCHAR(255) NOT NULL, dt_crea DATETIME NOT NULL, aut_maj INT DEFAULT NULL, dt_maj DATETIME DEFAULT NULL, link VARCHAR(255) NOT NULL, edition_link VARCHAR(255) NOT NULL, UNIQUE INDEX index_capsule_nom (nom), UNIQUE INDEX index_capsule_link (link), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DROP TABLE capsule');
}
}
......@@ -30,6 +30,7 @@ class CapsuleController extends AbstractController
return $this->render('capsule/index.html.twig', [
'capsules' => $capsules,
'legacy_url' => $this->getParameter('app.legacy_external_prefix')
]);
}
......
......@@ -102,7 +102,7 @@ class FallbackController extends AbstractController
"{$originalController}{$separator}?{$originalQueryString}";
$url = preg_replace('(^https?:\/\/[^/]+(:\d+)?)', '', $url);
$pattern = '/\/\//i';
$pattern = '/\/+/i';
/** @phpstan-ignore-next-line */
$url = preg_replace($pattern, '/', $url);
......
......@@ -26,8 +26,9 @@ class ProjectController extends AbstractController
chdir('../legacy/');
$capsule_name = $capsule->getName();
$capsule_directory = $capsule->getPreviewLink();
if (file_exists($capsule_name)) {
if (file_exists($capsule_directory)) {
$this->addFlash(
'project_already_exists',
$translator->trans(
......@@ -41,9 +42,9 @@ class ProjectController extends AbstractController
return $this->redirectToRoute('capsule_list');
}
$this->extractZipArchiveInNewCapsuleDirectory($capsule_name);
$this->extractZipArchiveInNewCapsuleDirectory($capsule_directory);
$this->addProjectVideoUrlInXMLProjectFile($capsule_name, $video_url);
$this->addProjectVideoUrlInXMLProjectFile($capsule_directory, $video_url);
$this->addFlash(
'capsule_created_success',
......@@ -71,9 +72,9 @@ class ProjectController extends AbstractController
$zip->close();
}
private function addProjectVideoUrlInXMLProjectFile(string $capsule_name, string $video_url): void
private function addProjectVideoUrlInXMLProjectFile(string $capsule_directory, string $video_url): void
{
$project_xml_file = $capsule_name . "/file/project.xml";
$project_xml_file = $capsule_directory . "/file/project.xml";
$xml_file_content = file_get_contents($project_xml_file);
if (false === $xml_file_content) {
......
......@@ -115,6 +115,7 @@ class LegacyHelper
$curl_handler = new CurlHandle();
try {
$options_array = [
CURLOPT_URL => $url,
CURLOPT_HEADER => false,
......@@ -129,7 +130,7 @@ class LegacyHelper
$curl_handler->setOptions($options_array);
if ($request->getMethod() == 'POST') {
$postParameters = $request->request->all()['create_capsule_form'];
$postParameters = $request->request->all();
if (!is_array($postParameters)) {
throw new Exception();
......@@ -164,13 +165,15 @@ class LegacyHelper
);
}
$curl_handler->close();
$response = new Response($result);
$contentType = $curl_handler->getInfo(CURLINFO_CONTENT_TYPE);
$response->headers->set('Content-Type', $contentType);
return $response;
} finally {
$curl_handler->close();
}
}
public static function getMime(?string $filepath, string $extension): ?string
......
......@@ -51,7 +51,7 @@
<div class="d-flex flex-column flex-md-row justify-content-center align-items-center">
<div class="m-4 ratio ratio-16x9">
<iframe
src="{{ capsule.getEditionLink() }}"
src="{{ legacy_url }}/{{ capsule.getEditionLink() }}"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
......@@ -74,7 +74,7 @@
Delete capsule
</a>
</div>
<a href="/" class="list-item lh-md">
<a href="{{ capsule.getEditionLink() }}" class="list-item lh-md">
<button class="standard-button p-2">
Edit capsule
</button>
......
{% extends 'layout.html.twig' %}
{% block body %}
<iframe src="{{ url }}"
class="w-100 h-100 top-0 start-0 position-absolute border-0"
{# style="width:100%;height:100%;top:0;left:0;position:absolute"#}
{# frameborder="0"#}
webkitallowfullscreen
mozallowfullscreen
allowfullscreen>
</iframe>
{% endblock %}
\ No newline at end of file
......@@ -9,6 +9,7 @@ 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
{
......@@ -69,15 +70,25 @@ class ProjectControllerTest extends WebTestCase
}
/** @phpstan-ignore-next-line */
private function getDOMDocument(): \DOMDocument
private function getDOMDocument(string $capsule_directory): \DOMDocument
{
$dom_xml = new \DOMDocument();
$dom_xml->preserveWhiteSpace = false;
$dom_xml->load(self::XML_FILE_PATH);
$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";
......@@ -93,6 +104,7 @@ class ProjectControllerTest extends WebTestCase
);
$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]);
......@@ -101,11 +113,13 @@ class ProjectControllerTest extends WebTestCase
throw new \Exception("Capsule does not exist.");
}
self::assertInstanceOf(Capsule::class, $capsule_in_db);
$capsule_name_in_db = $capsule_in_db->getName();
$capsule_directory = $capsule_in_db->getPreviewLink();
$dom_xml = $this->getDomDocument();
$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) {
......@@ -114,10 +128,7 @@ class ProjectControllerTest extends WebTestCase
$video_url_in_xml_file = $video_node->getAttribute('url');
$this->assertResponseIsSuccessful('/my_capsules');
$this->assertEquals($video_url, $video_url_in_xml_file);
$this->assertDirectoryExists(self::CAPSULE_NAME);
$this->assertDirectoryIsReadable(self::CAPSULE_NAME);
$this->assertSame(self::CAPSULE_NAME, $capsule_name_in_db);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment