Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use AppBundle\Joindin\JoindinTalk;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;

final class JoindinAction extends AbstractController
{
Expand All @@ -20,10 +21,14 @@ public function __invoke(int $id, string $slug): RedirectResponse
{
$talk = $this->talkRepository->get($id);

if (null === $talk || $talk->getSlug() != $slug || !$talk->isDisplayedOnHistory()) {
if (null === $talk || !$talk->isDisplayedOnHistory()) {
throw $this->createNotFoundException();
}

if ($talk->getSlug() !== $slug) {
return $this->redirectToRoute('talks_joindin', ['id' => $id, 'slug' => $talk->getSlug()], Response::HTTP_MOVED_PERMANENTLY);
}

$stub = $this->joindinTalk->getStubFromTalk($talk);

if (null === $stub) {
Expand Down
9 changes: 7 additions & 2 deletions sources/AppBundle/Controller/Website/Talks/ShowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ public function __invoke(int $id, string $slug): Response
{
$talk = $this->talkRepository->get($id);

if (null === $talk || $talk->getSlug() != $slug || !$talk->isDisplayedOnHistory()) {
if (null === $talk || !$talk->isDisplayedOnHistory()) {
throw $this->createNotFoundException();
}

$speakers = $this->speakerRepository->getSpeakersByTalk($talk);
$planning = $this->planningRepository->getByTalk($talk);
if ($planning === null) {
throw $this->createNotFoundException();
}

if ($talk->getSlug() !== $slug) {
return $this->redirectToRoute('talks_show', ['id' => $id, 'slug' => $talk->getSlug()], Response::HTTP_MOVED_PERMANENTLY);
}

$speakers = $this->speakerRepository->getSpeakersByTalk($talk);
$event = $this->eventRepository->get($planning->eventId);
$comments = $this->joindinComments->getCommentsFromTalk($talk);

Expand Down
24 changes: 24 additions & 0 deletions tests/behat/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Hook\AfterScenario;
use Behat\Hook\BeforeScenario;
use Behat\Mink\Driver\BrowserKitDriver;
use Behat\Mink\Driver\PantherDriver;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ExpectationException;
Expand Down Expand Up @@ -50,6 +52,28 @@ public function beforeScenarioReloadDatabase(): void
$this->databaseManager->reloadDatabase();
}

#[When('I do not follow redirects')]
public function doNotFollowRedirects(): void
{
$driver = $this->minkContext->getSession()->getDriver();

if (!$driver instanceof BrowserKitDriver) {
throw new \LogicException('This step requires a non-@javascript scenario.');
}

$driver->getClient()->followRedirects(false);
}

#[AfterScenario]
public function restoreFollowRedirects(): void
{
$driver = $this->minkContext->getSession()->getDriver();

if ($driver instanceof BrowserKitDriver) {
$driver->getClient()->followRedirects(true);
}
}

#[Then('simulate the Paybox callback')]
public function simulateThePayboxCallback(): void
{
Expand Down
32 changes: 32 additions & 0 deletions tests/behat/features/PublicSite/Talks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,35 @@ Feature: Site Public - Talks
When I go to "/talks/?q=&hPP=7&idx=afup_talks&p=0&fR[event.title][0]=AFUP Day 2019 Lyon&fR[speakers.label][0]=Un Speaker"
Then I should see "Les vidéos de Un Speaker"
And the response should contain "<link rel=\"canonical\" href=\"https://apachephptest:80/talks/?fR%5Bspeakers.label%5D%5B0%5D=Un%20Speaker\" />"

@reloadDbWithTestData
Scenario: Un talk avec le bon slug répond 200
Given I do not follow redirects
When I go to "/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform"
Then the response status code should be 200

@reloadDbWithTestData
Scenario: Un talk avec un mauvais slug redirige en 301 vers le slug courant
Given I do not follow redirects
When I go to "/talks/2-mauvais-slug"
Then the response status code should be 301
And the response header "Location" should match "#^(https?://[^/]+)?/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform$#"

@reloadDbWithTestData
Scenario: Le lien joind.in d'un talk avec un mauvais slug redirige en 301 vers le slug courant
Given I do not follow redirects
When I go to "/talks/2-mauvais-slug/joindin"
Then the response status code should be 301
And the response header "Location" should match "#^(https?://[^/]+)?/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform/joindin$#"

@reloadDbWithTestData
Scenario: Un talk inexistant ou non publié répond 404, quel que soit le slug
Given I do not follow redirects
When I go to "/talks/999999-mauvais-slug"
Then the response status code should be 404
When I go to "/talks/999999-mauvais-slug/joindin"
Then the response status code should be 404
When I go to "/talks/4-mauvais-slug"
Then the response status code should be 404
When I go to "/talks/4-mauvais-slug/joindin"
Then the response status code should be 404
Loading