diff --git a/config/routing/talks.yml b/config/routing/talks.yml index 0d4633546..a0504db40 100644 --- a/config/routing/talks.yml +++ b/config/routing/talks.yml @@ -6,7 +6,7 @@ talks_list: section: talks changefreq: monthly -# Avant talks_show (dont l'id est numérique) : /{id}-{slug} ne doit jamais capturer une page speaker. +# Avant talks_show (dont l'id est numérique) : /{id}-{slug} ne doit jamais capturer une page speaker ou événement. talks_speakers: path: /speakers/ defaults: { _controller: AppBundle\Controller\Website\Talks\SpeakerListAction } @@ -19,6 +19,18 @@ talks_speaker: path: /speakers/{slug} defaults: { _controller: AppBundle\Controller\Website\Talks\SpeakerShowAction } +talks_events: + path: /evenements/ + defaults: { _controller: AppBundle\Controller\Website\Talks\EventListAction } + options: + sitemap: + section: talks + changefreq: monthly + +talks_event: + path: /evenements/{path} + defaults: { _controller: AppBundle\Controller\Website\Talks\EventShowAction } + talks_show: path: /{id}-{slug} defaults: { _controller: AppBundle\Controller\Website\Talks\ShowAction } diff --git a/sources/AppBundle/Controller/Website/Talks/EventListAction.php b/sources/AppBundle/Controller/Website/Talks/EventListAction.php new file mode 100644 index 000000000..0a37e4bec --- /dev/null +++ b/sources/AppBundle/Controller/Website/Talks/EventListAction.php @@ -0,0 +1,31 @@ +publishedTalkRepository->getEventSummaries() as $summary) { + $summariesByYear[$summary->getYear()][] = $summary; + } + + return $this->view->render('site/talks/events.html.twig', [ + 'summaries_by_year' => $summariesByYear, + ]); + } +} diff --git a/sources/AppBundle/Controller/Website/Talks/EventShowAction.php b/sources/AppBundle/Controller/Website/Talks/EventShowAction.php new file mode 100644 index 000000000..ff35db55b --- /dev/null +++ b/sources/AppBundle/Controller/Website/Talks/EventShowAction.php @@ -0,0 +1,52 @@ +eventRepository->getByPath($path); + $eventTalks = null !== $event ? $this->publishedTalkRepository->getEventTalks((int) $event->getId()) : []; + + if (null === $event || $eventTalks === []) { + throw $this->createNotFoundException(); + } + + // Slug de la page de chaque speaker, par ID de ligne speaker : un seul index, chargé une fois pour tous. + $speakerSlugs = []; + foreach ($eventTalks as $eventTalk) { + foreach ($eventTalk->speakers as $speaker) { + $identity = $this->speakerProfileResolver->getIdentityByPersonneId($speaker->personneId); + if (null !== $identity) { + $speakerSlugs[$speaker->id] = $identity->slug; + } + } + } + + return $this->view->render('site/talks/event.html.twig', [ + 'event' => $event, + 'event_talks' => $eventTalks, + 'speaker_slugs' => $speakerSlugs, + 'item_list' => $this->eventTalksJsonLd->getData($event, $eventTalks), + ]); + } +} diff --git a/sources/AppBundle/Controller/Website/Talks/ListAction.php b/sources/AppBundle/Controller/Website/Talks/ListAction.php index d1488378a..d47fd207e 100644 --- a/sources/AppBundle/Controller/Website/Talks/ListAction.php +++ b/sources/AppBundle/Controller/Website/Talks/ListAction.php @@ -5,6 +5,7 @@ namespace AppBundle\Controller\Website\Talks; use AppBundle\Antennes\AntenneRepository; +use AppBundle\Event\Talk\PublishedTalkRepository; use AppBundle\Event\Speaker\SpeakerProfileResolver; use AppBundle\Twig\ViewRenderer; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -24,13 +25,14 @@ public function __construct( private readonly string $algoliaFrontendApikey, private readonly AntenneRepository $antennesRepository, private readonly SpeakerProfileResolver $speakerProfileResolver, + private readonly PublishedTalkRepository $publishedTalkRepository, ) {} public function __invoke(Request $request): Response { - $speakerRedirect = $this->redirectSpeakerFacet($request); - if (null !== $speakerRedirect) { - return $speakerRedirect; + $facetRedirect = $this->redirectSpeakerFacet($request) ?? $this->redirectEventFacet($request); + if (null !== $facetRedirect) { + return $facetRedirect; } $title = 'Historique des conférences de l\'AFUP'; @@ -64,10 +66,8 @@ public function __invoke(Request $request): Response */ private function redirectSpeakerFacet(Request $request): ?RedirectResponse { - $labels = $request->query->all('fR')['speakers.label'] ?? null; - $label = is_array($labels) ? $labels[0] ?? null : null; - - if (!is_string($label) || $request->query->all() !== ['fR' => ['speakers.label' => [$label]]]) { + $label = $this->getSingleFacet($request, 'speakers.label'); + if (null === $label) { return null; } @@ -78,4 +78,39 @@ private function redirectSpeakerFacet(Request $request): ?RedirectResponse return $this->redirectToRoute('talks_speaker', ['slug' => $identity->slug], Response::HTTP_MOVED_PERMANENTLY); } + + /** + * L'ancienne URL d'une édition, `/talks/?fR[event.title][0]=…` sans aucun autre paramètre, + * redirige vers sa page si elle a des talks publiés. Une facette combinée à d'autres filtres reste une recherche. + */ + private function redirectEventFacet(Request $request): ?RedirectResponse + { + $title = $this->getSingleFacet($request, 'event.title'); + if (null === $title) { + return null; + } + + foreach ($this->publishedTalkRepository->getEventSummaries() as $summary) { + if ($summary->event->title === $title) { + return $this->redirectToRoute('talks_event', ['path' => $summary->event->path], Response::HTTP_MOVED_PERMANENTLY); + } + } + + return null; + } + + /** + * La valeur de la facette quand la requête n'a aucun autre paramètre que `fR[$facet][0]`. + */ + private function getSingleFacet(Request $request, string $facet): ?string + { + $values = $request->query->all('fR')[$facet] ?? null; + $value = is_array($values) ? $values[0] ?? null : null; + + if (!is_string($value) || $request->query->all() !== ['fR' => [$facet => [$value]]]) { + return null; + } + + return $value; + } } diff --git a/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php b/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php index f371c1726..2bc031555 100644 --- a/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php +++ b/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php @@ -84,7 +84,14 @@ public function getIdentityByLabel(string $label): ?SpeakerIdentity */ public function getIdentityForSpeaker(Speaker $speaker): ?SpeakerIdentity { - $personneId = $speaker->getPersonneId(); + return $this->getIdentityByPersonneId($speaker->getPersonneId()); + } + + /** + * La personne qui a ce id, si elle a au moins un talk publié. + */ + public function getIdentityByPersonneId(?int $personneId): ?SpeakerIdentity + { if (null === $personneId) { return null; } diff --git a/sources/AppBundle/Event/Talk/EventTalk.php b/sources/AppBundle/Event/Talk/EventTalk.php new file mode 100644 index 000000000..84aa7468f --- /dev/null +++ b/sources/AppBundle/Event/Talk/EventTalk.php @@ -0,0 +1,20 @@ + $speakers + */ + public function __construct( + public PublishedTalk $talk, + public \DateTimeImmutable $startsAt, + public array $speakers, + ) {} +} diff --git a/sources/AppBundle/Event/Talk/EventTalksJsonLd.php b/sources/AppBundle/Event/Talk/EventTalksJsonLd.php new file mode 100644 index 000000000..00b9f5075 --- /dev/null +++ b/sources/AppBundle/Event/Talk/EventTalksJsonLd.php @@ -0,0 +1,50 @@ + $eventTalks + * + * @return array + */ + public function getData(Event $event, array $eventTalks): array + { + $items = []; + foreach ($eventTalks as $index => $eventTalk) { + $items[] = [ + '@type' => 'ListItem', + 'position' => $index + 1, + 'url' => $this->urlGenerator->generate( + 'talks_show', + ['id' => $eventTalk->talk->id, 'slug' => $eventTalk->talk->slug], + UrlGeneratorInterface::ABSOLUTE_URL, + ), + 'name' => $eventTalk->talk->title, + ]; + } + + return [ + '@context' => 'https://schema.org', + '@type' => 'ItemList', + 'name' => $event->getTitle() . ' : les talks et vidéos', + 'url' => $this->urlGenerator->generate('talks_event', ['path' => $event->getPath()], UrlGeneratorInterface::ABSOLUTE_URL), + 'numberOfItems' => count($items), + 'itemListElement' => $items, + ]; + } +} diff --git a/sources/AppBundle/Event/Talk/EventTalksSummary.php b/sources/AppBundle/Event/Talk/EventTalksSummary.php new file mode 100644 index 000000000..8e54b88a7 --- /dev/null +++ b/sources/AppBundle/Event/Talk/EventTalksSummary.php @@ -0,0 +1,25 @@ +event->dateStart?->format('Y'); + } +} diff --git a/sources/AppBundle/Event/Talk/PublishedSpeaker.php b/sources/AppBundle/Event/Talk/PublishedSpeaker.php new file mode 100644 index 000000000..307d8a88c --- /dev/null +++ b/sources/AppBundle/Event/Talk/PublishedSpeaker.php @@ -0,0 +1,23 @@ +label = $firstname . ' ' . ('' !== $lastname ? mb_strtoupper($lastname) : ''); + } +} diff --git a/sources/AppBundle/Event/Talk/PublishedTalkRepository.php b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php index 62a06053c..171edc643 100644 --- a/sources/AppBundle/Event/Talk/PublishedTalkRepository.php +++ b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php @@ -20,7 +20,7 @@ { private const string PLANNING_JOIN = ' INNER JOIN ( - SELECT id_session, MIN(debut) AS debut, MIN(fin) AS fin FROM afup_forum_planning GROUP BY id_session + SELECT id_session, MIN(debut) AS debut, MIN(fin) AS fin, MIN(id_salle) AS id_salle FROM afup_forum_planning GROUP BY id_session ) planning ON planning.id_session = talk.session_id'; private const string CONDITIONS = ' @@ -66,6 +66,69 @@ public function getSpeakerAppearances(): array ], $rows); } + /** + * Les talks publiés d'une édition dans l'ordre du planning (créneau, salle), avec leurs speakers. + * + * @return list + */ + public function getEventTalks(int $eventId): array + { + $rows = $this->connection->fetchAllAssociative( + 'SELECT talk.session_id, talk.titre, talk.youtube_id, planning.debut, + speaker.conferencier_id, speaker.prenom, speaker.nom, speaker.personne_id + FROM afup_sessions talk' + . self::PLANNING_JOIN . ' + LEFT JOIN afup_conferenciers_sessions cs ON cs.session_id = talk.session_id + LEFT JOIN afup_conferenciers speaker ON speaker.conferencier_id = cs.conferencier_id + WHERE talk.id_forum = :eventId AND ' . self::CONDITIONS . ' + ORDER BY planning.debut ASC, planning.id_salle ASC, talk.session_id ASC, speaker.conferencier_id ASC', + ['eventId' => $eventId], + ); + + /** @var array}> $talks */ + $talks = []; + foreach ($rows as $row) { + $talkId = self::toInt($row['session_id']); + $talks[$talkId] ??= ['talk' => self::talk($row), 'starts_at' => self::timestamp($row['debut']), 'speakers' => []]; + if (null !== $row['conferencier_id']) { + $talks[$talkId]['speakers'][] = self::speaker($row); + } + } + + return array_values(array_map( + static fn(array $talk): EventTalk => new EventTalk($talk['talk'], $talk['starts_at'], $talk['speakers']), + $talks, + )); + } + + /** + * Les éditions qui ont au moins un talk publié, de la plus récente à la plus ancienne, avec le nombre de + * talks publiés et de vidéos, en une seule requête agrégée. + * + * @return list + */ + public function getEventSummaries(): array + { + $rows = $this->connection->fetchAllAssociative( + "SELECT event.id AS event_id, event.titre AS event_titre, event.path AS event_path, + event.date_debut AS event_date_debut, event.date_fin AS event_date_fin, + COUNT(talk.session_id) AS talk_count, + SUM(talk.youtube_id IS NOT NULL AND talk.youtube_id <> '') AS video_count + FROM afup_sessions talk" + . self::PLANNING_JOIN . ' + INNER JOIN afup_forum event ON event.id = talk.id_forum + WHERE ' . self::CONDITIONS . ' + GROUP BY event.id + ORDER BY event.date_debut DESC, event.id DESC', + ); + + return array_map(static fn(array $row): EventTalksSummary => new EventTalksSummary( + self::event($row), + self::toInt($row['talk_count']), + self::toInt($row['video_count'] ?? 0), + ), $rows); + } + /** * Les talks publiés de ces lignes speaker, avec leur événement, du plus récent au plus ancien. * @@ -115,6 +178,19 @@ private static function talk(array $row): PublishedTalk ); } + /** + * @param array $row + */ + private static function speaker(array $row): PublishedSpeaker + { + return new PublishedSpeaker( + self::toInt($row['conferencier_id']), + self::toString($row['prenom'] ?? ''), + self::toString($row['nom'] ?? ''), + null !== $row['personne_id'] ? self::toInt($row['personne_id']) : null, + ); + } + /** * @param array $row */ diff --git a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php index 50fc30188..e8a68aa87 100644 --- a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php +++ b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php @@ -8,9 +8,8 @@ use AppBundle\Association\Model\CompanyMember; use AppBundle\Association\Model\Repository\CompanyMemberRepository; use AppBundle\Controller\Website\News\ListAction; -use AppBundle\Event\Model\Event; -use AppBundle\Event\Model\Repository\EventRepository; use AppBundle\Event\Model\Repository\TalkRepository; +use AppBundle\Event\Talk\PublishedTalkRepository; use AppBundle\Event\Model\Talk; use AppBundle\Event\Speaker\SpeakerProfileResolver; use AppBundle\Site\Entity\Repository\FeuilleRepository; @@ -28,8 +27,8 @@ class SitemapXmlSubscriber implements EventSubscriberInterface public function __construct( private readonly UrlGeneratorInterface $urlGenerator, private readonly TalkRepository $talkRepository, + private readonly PublishedTalkRepository $publishedTalkRepository, private readonly SpeakerProfileResolver $speakerProfileResolver, - private readonly EventRepository $eventRepository, private readonly ArticleRepository $articleRepository, private readonly CompanyMemberRepository $companyMemberRepository, private readonly FeuilleRepository $feuilleRepository, @@ -105,20 +104,21 @@ public function registerSpeakersUrls(UrlContainerInterface $urls): void } } + /** + * La page de chaque édition ayant au moins un talk publié ; l'index des éditions + * est déclaré par l'option sitemap de sa route. + */ public function registerEventsTalksUrls(UrlContainerInterface $urls): void { - /** @var Event[] $events */ - $events = $this->eventRepository->getAll(); - foreach ($events as $event) { + foreach ($this->publishedTalkRepository->getEventSummaries() as $summary) { $url = new UrlConcrete( $this->urlGenerator->generate( - 'talks_list', - ['fR' => ['event.title' => [$event->getTitle()]]], + 'talks_event', + ['path' => $summary->event->path], UrlGeneratorInterface::ABSOLUTE_URL, ), - $event->getDateEnd(), - UrlConcrete::CHANGEFREQ_DAILY, - 1, + $summary->event->dateEnd, + UrlConcrete::CHANGEFREQ_MONTHLY, ); $urls->addUrl($url, 'talks'); } diff --git a/templates/site/talks/_talk_card.html.twig b/templates/site/talks/_talk_card.html.twig new file mode 100644 index 000000000..3eebf3bea --- /dev/null +++ b/templates/site/talks/_talk_card.html.twig @@ -0,0 +1,14 @@ +{# Carte d'un talk : vignette (ou image par défaut), titre en lien, puis le bloc « details » de l'appelant. #} +{% set talk_url = path('talks_show', {id: talk.id, slug: talk.slug}) %} + diff --git a/templates/site/talks/event.html.twig b/templates/site/talks/event.html.twig new file mode 100644 index 000000000..0f579119d --- /dev/null +++ b/templates/site/talks/event.html.twig @@ -0,0 +1,68 @@ +{% extends 'layouts/site.html.twig' %} + +{% set talk_count = event_talks|length %} +{% set video_count = event_talks|filter(event_talk => event_talk.talk.hasYoutubeId)|length %} +{% set event_dates %} + {%- if event.dateStart|date('Y-m-d') == event.dateEnd|date('Y-m-d') -%} + le {{ event.dateStart|format_date('long') }} + {%- elseif event.dateStart|date('Y-m') == event.dateEnd|date('Y-m') -%} + du {{ event.dateStart|date('j') }} au {{ event.dateEnd|format_date('long') }} + {%- else -%} + du {{ event.dateStart|format_date('long') }} au {{ event.dateEnd|format_date('long') }} + {%- endif -%} +{% endset %} + +{% block title %}{{ event.title }} : les talks et vidéos – AFUP{% endblock %} + +{% block description %}{{ event.title }}, {{ event_dates }}{% if event.placeName %} à {{ event.placeName }}{% endif %} : {{ talk_count }} talk{{ talk_count > 1 ? 's' }}{% if video_count %} dont {{ video_count }} en vidéo{% endif %}, avec leurs speakers.{% endblock %} + +{% block metas %} + {{ parent() }} + +{% endblock %} + +{% block content %} +
+

+ Événements +

+

{{ event.title }} : les talks et vidéos

+

+ {{ event.title }} s'est déroulé {{ event_dates }}{% if event.placeName %} à {{ event.placeName }}{% endif %}. + Retrouvez {{ talk_count > 1 ? 'les ' ~ talk_count ~ ' talks' : 'le talk' }} de cette édition{% if video_count %}, dont {{ video_count }} en vidéo{% endif %}, dans l'ordre du programme. +

+

+ Voir la page de l'édition sur event.afup.org +

+
+ +
+ {{ talk_count > 1 ? 'Les talks' : 'Le talk' }} + +
    + {% for event_talk in event_talks %} +
  1. + {% embed 'site/talks/_talk_card.html.twig' with {talk: event_talk.talk} %} + {% block details %} + {% if event_talk.speakers|length %} +

    + {% for speaker in event_talk.speakers -%} + {%- if speaker_slugs[speaker.id] is defined -%} + {{ speaker.label }} + {%- else -%} + {{ speaker.label }} + {%- endif -%} + {{- not loop.last ? ', ' -}} + {%- endfor %} +

    + {% endif %} +

    + +

    + {% endblock %} + {% endembed %} +
  2. + {% endfor %} +
+
+{% endblock %} diff --git a/templates/site/talks/events.html.twig b/templates/site/talks/events.html.twig new file mode 100644 index 000000000..1e4f5c581 --- /dev/null +++ b/templates/site/talks/events.html.twig @@ -0,0 +1,49 @@ +{% extends 'layouts/site.html.twig' %} + +{% block title %}Événements et conférences : talks et vidéos – AFUP{% endblock %} + +{% block description %}Toutes les éditions des conférences de l'AFUP, année par année : Forum PHP, AFUP Day, PHP Tour… Retrouvez les talks et vidéos de chaque événement.{% endblock %} + +{% block content %} +
+

+ Vidéos +

+

Les événements de l'AFUP et leurs talks

+ + {% if summaries_by_year|length > 1 %} + + {% endif %} +
+ +
+ {% for year, summaries in summaries_by_year %} +
+ {{ year }} +
    + {% for summary in summaries %} +
  • + {{ summary.event.title }} +

    + {{ summary.talkCount }} talk{{ summary.talkCount > 1 ? 's' }} + · {{ summary.videoCount }} vidéo{{ summary.videoCount > 1 ? 's' }} +

    +
  • + {% endfor %} +
+
+ {% else %} +

Aucun événement pour le moment.

+ {% endfor %} +
+{% endblock %} diff --git a/templates/site/talks/show.html.twig b/templates/site/talks/show.html.twig index 24d1ff317..57bafaf3c 100644 --- a/templates/site/talks/show.html.twig +++ b/templates/site/talks/show.html.twig @@ -32,7 +32,7 @@ {% set event_date %} {% if event.dateStart == event.dateEnd %}le {{ event.dateStart|date('d') }}{% else %}les {{ event.dateStart|date('d') }} et {{ event.dateEnd|date('d') }}{% endif %} {{ event.dateEnd|format_date('none', 'MMMM YYYY') }} {% endset %} - {% set event_url = url('talks_list', {"fR": { "event.title" : [ event.title ]}}) %} + {% set event_url = url('talks_event', {path: event.path}) %} {% set speakers_label = speakers|map(speaker => speaker.label)|join(', ') %} {% if talk.hasYoutubeId %} diff --git a/templates/site/talks/speaker.html.twig b/templates/site/talks/speaker.html.twig index 3f8df467c..bb5453e5e 100644 --- a/templates/site/talks/speaker.html.twig +++ b/templates/site/talks/speaker.html.twig @@ -56,23 +56,14 @@
    {% for speaker_talk in profile.talks %} - {% set talk = speaker_talk.talk %} - {% set talk_url = path('talks_show', {id: talk.id, slug: talk.slug}) %}
  • -
    - -
    -

    - {{ talk.title }} -

    + {% embed 'site/talks/_talk_card.html.twig' with {talk: speaker_talk.talk} %} + {% block details %}

    - {{ speaker_talk.event.title }} · + {{ speaker_talk.event.title }} ·

    -
    -
    + {% endblock %} + {% endembed %}
  • {% endfor %}
diff --git a/tests/behat/bootstrap/FeatureContext.php b/tests/behat/bootstrap/FeatureContext.php index dc9c39e4f..b79569754 100644 --- a/tests/behat/bootstrap/FeatureContext.php +++ b/tests/behat/bootstrap/FeatureContext.php @@ -470,4 +470,42 @@ public function assertJsonLdPropertyContains(string $type, string $property, str ); } } + + /** + * Le texte de chaque élément trouvé par le sélecteur CSS, dans l'ordre de la page : ni plus, ni moins. + */ + #[Then('/^the texts of "(?P[^"]+)" should be, in this order:$/')] + public function assertElementTextsInOrder(string $selector, PyStringNode $expectedTexts): void + { + $expected = array_values(array_filter(array_map(trim(...), $expectedTexts->getStrings()))); + $actual = array_map( + static fn(NodeElement $element): string => trim($element->getText()), + $this->minkContext->getSession()->getPage()->findAll('css', $selector), + ); + + if ($expected !== $actual) { + throw new ExpectationException( + sprintf('The texts of "%s" are %s, %s expected', $selector, json_encode($actual, JSON_UNESCAPED_UNICODE), json_encode($expected, JSON_UNESCAPED_UNICODE)), + $this->minkContext->getSession()->getDriver(), + ); + } + } + + /** + * La propriété :key de chaque élément de la liste :property du JSON-LD, dans l'ordre : ni plus, ni moins. + */ + #[Then('the :key of each item of the JSON-LD :type property :property should be, in this order:')] + public function assertJsonLdListValues(string $key, string $type, string $property, PyStringNode $expectedValues): void + { + $items = $this->findJsonLd($type)[$property] ?? null; + $actual = is_array($items) ? array_map(static fn($item): mixed => is_array($item) ? $item[$key] ?? null : null, $items) : null; + $expected = array_values(array_filter(array_map(trim(...), $expectedValues->getStrings()))); + + if ($expected !== $actual) { + throw new ExpectationException( + sprintf('The "%s" of the JSON-LD "%s" property "%s" are %s, %s expected', $key, $type, $property, json_encode($actual, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), json_encode($expected, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)), + $this->minkContext->getSession()->getDriver(), + ); + } + } } diff --git a/tests/behat/features/PublicSite/Sitemaps.feature b/tests/behat/features/PublicSite/Sitemaps.feature index 92f844e72..ddcc6b3e6 100644 --- a/tests/behat/features/PublicSite/Sitemaps.feature +++ b/tests/behat/features/PublicSite/Sitemaps.feature @@ -16,7 +16,10 @@ Feature: Site Public - Sitemaps And the response should contain "https://apachephptest:80/talks/speakers/geoffrey-bachelet" And the response should contain "https://apachephptest:80/talks/speakers/" And the response should not contain "fR%5Bspeakers" - And the response should contain "https://apachephptest:80/talks/?fR%5Bevent.title%5D%5B0%5D=forum" + And the response should contain "https://apachephptest:80/talks/evenements/forum" + And the response should contain "https://apachephptest:80/talks/evenements/passed" + And the response should contain "https://apachephptest:80/talks/evenements/" + And the response should not contain "fR%5Bevent" And the response should contain "https://apachephptest:80/talks/" @reloadDbWithTestData diff --git a/tests/behat/features/PublicSite/Talks.feature b/tests/behat/features/PublicSite/Talks.feature index c7a60975b..fe6f84954 100644 --- a/tests/behat/features/PublicSite/Talks.feature +++ b/tests/behat/features/PublicSite/Talks.feature @@ -113,6 +113,7 @@ Feature: Site Public - Talks And the response should contain "href=\"/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform\"" And the response should contain "href=\"/talks/6-revolutionons-php\"" And I should see "Un évènement du passé" + And the response should contain "href=\"/talks/evenements/passed\"" And the response should contain "https://img.youtube.com/vi/MseSkWbhxV8/hqdefault.jpg" And the response should contain "/images/no_video.jpg" And the response should contain "href=\"https://phpc.social/@ubermuda\"" @@ -165,3 +166,73 @@ Feature: Site Public - Talks And I follow "Voir tous ses talks" Then the url should match "/talks/speakers/geoffrey-bachelet" And I should see "Geoffrey Bachelet" in the "h1" element + + @reloadDbWithTestData + Scenario: Page d'un événement rendue côté serveur + When I go to "/talks/evenements/forum" + Then the response status code should be 200 + And the response should contain "forum : les talks et vidéos – AFUP" + And I should see "forum : les talks et vidéos" in the "h1" element + And I should see "à Paris" + And the response should contain "href=\"https://event.afup.org/forum/\"" + And the texts of "main ol article h3" should be, in this order: + """ + Jouons tous ensemble à un petit jeu + REST ou GraphQL ? Exemples illustrés avec Symfony et API Platform + """ + And I should not see "Révolutionons PHP" + And the response should contain "https://img.youtube.com/vi/QhAToFl_Omo/hqdefault.jpg" + And the response should contain "href=\"/talks/speakers/geoffrey-bachelet\"" + And the JSON-LD "ItemList" should have the following properties: + | name | forum : les talks et vidéos | + | url | https://apachephptest:80/talks/evenements/forum | + | numberOfItems | 2 | + And the "url" of each item of the JSON-LD "ItemList" property "itemListElement" should be, in this order: + """ + https://apachephptest:80/talks/1-jouons-tous-ensemble-a-un-petit-jeu + https://apachephptest:80/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform + """ + + @reloadDbWithTestData + Scenario: Page d'un événement inconnu ou sans talk publié + When I go to "/talks/evenements/evenement-inconnu" + Then the response status code should be 404 + When I go to "/talks/evenements/afup-day-lyon" + Then the response status code should be 404 + + @reloadDbWithTestData + Scenario: Index des événements groupé par année + When I go to "/talks/evenements/" + Then the response status code should be 200 + And I should see "2020" in the "section#evenements-2020 h2" element + And the texts of "section#evenements-2020 li a" should be, in this order: + """ + Un évènement du passé + """ + And the texts of "section#evenements-2020 li p" should be, in this order: + """ + 1 talk · 0 vidéo + """ + And the response should contain "href=\"/talks/evenements/forum\"" + And I should see "2 talks · 2 vidéos" + And I should not see "AFUP Day Lyon" + + @reloadDbWithTestData + Scenario: L'ancienne facette d'un événement redirige vers sa page + Given I do not follow redirects + When I go to "/talks/?fR[event.title][0]=forum" + Then the response status code should be 301 + And the response header "Location" should match "#^(https?://[^/]+)?/talks/evenements/forum$#" + + @reloadDbWithTestData + Scenario: Une facette événement combinée à d'autres paramètres reste une recherche + Given I do not follow redirects + When I go to "/talks/?fR[event.title][0]=forum&p=1" + Then the response status code should be 200 + And I should see "forum les vidéos" + + @reloadDbWithTestData + Scenario: Le bandeau de la page d'un talk renvoie vers la page de son événement + When I go to "/talks/1-jouons-tous-ensemble-a-un-petit-jeu" + Then the response should contain "href=\"https://apachephptest:80/talks/evenements/forum\"" + And the response should not contain "fR%5Bevent.title" diff --git a/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryEventTest.php b/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryEventTest.php new file mode 100644 index 000000000..1514d1824 --- /dev/null +++ b/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryEventTest.php @@ -0,0 +1,117 @@ +connection = self::getContainer()->get(Connection::class); + + $this->connection->insert('afup_forum', ['id' => 1, 'titre' => 'Forum PHP 2019', 'path' => 'forumphp2019', 'date_debut' => '2019-10-24', 'date_fin' => '2019-10-25', 'nb_places' => 100]); + $this->connection->insert('afup_forum', ['id' => 2, 'titre' => 'AFUP Day 2021', 'path' => 'afupday2021', 'date_debut' => '2021-05-28', 'date_fin' => '2021-05-28', 'nb_places' => 100]); + $this->connection->insert('afup_forum', ['id' => 3, 'titre' => 'Forum PHP 2018', 'path' => 'forumphp2018', 'date_debut' => '2018-10-25', 'date_fin' => '2018-10-26', 'nb_places' => 100]); + $this->connection->insert('afup_forum', ['id' => 4, 'titre' => 'Sans talk publié', 'path' => 'sanstalk', 'date_debut' => '2020-10-25', 'date_fin' => '2020-10-26', 'nb_places' => 100]); + + foreach ([10 => 'Alice', 11 => 'Bob', 12 => 'Chloé'] as $speakerId => $firstname) { + $this->connection->insert('afup_conferenciers', ['conferencier_id' => $speakerId, 'id_forum' => 1, 'prenom' => $firstname, 'nom' => 'Martin', 'email' => $speakerId . '@example.com']); + } + + // Les créneaux sont dans un autre ordre que les identifiants ; deux talks partagent un créneau dans deux salles. + $this->insertTalk(100, 1, 'Clôture', strtotime('2019-10-25 17:00:00'), room: 1, speakerIds: [10], youtubeId: 'video100'); + $this->insertTalk(101, 1, 'Keynote', strtotime('2019-10-24 09:00:00'), room: 1, speakerIds: [12, 11]); + $this->insertTalk(102, 1, 'Salle 2', strtotime('2019-10-24 10:00:00'), room: 2, speakerIds: [10], youtubeId: 'video102'); + $this->insertTalk(103, 1, 'Salle 1', strtotime('2019-10-24 10:00:00'), room: 1, speakerIds: []); + $this->insertTalk(104, 1, 'Clinique', strtotime('2019-10-24 11:00:00'), type: Talk::TYPE_CLINIC, youtubeId: 'video104'); + $this->insertTalk(105, 1, 'Présentation des speakers', strtotime('2019-10-24 11:00:00'), type: Talk::TYPE_SPEAKER_INTRODUCTIONS); + $this->insertTalk(106, 1, 'Non planifié', strtotime('2019-10-24 11:00:00'), scheduled: false); + $this->insertTalk(107, 1, 'Publication à venir', strtotime('2019-10-24 11:00:00'), publishedOn: '+1 day', youtubeId: 'video107'); + $this->insertTalk(108, 1, 'Sans créneau', null); + $this->insertTalk(109, 1, 'Créneau pas encore terminé', time() - 600, slotEnd: time() + 600); + $this->insertTalk(200, 2, 'AFUP Day', strtotime('2021-05-28 10:00:00'), youtubeId: ''); + $this->insertTalk(300, 3, 'Forum 2018', strtotime('2018-10-25 10:00:00'), youtubeId: 'video300', publishedOn: '-1 day'); + $this->insertTalk(400, 4, 'Non planifié', strtotime('2020-10-25 10:00:00'), scheduled: false); + } + + public function testEventTalksFollowThePlanning(): void + { + $eventTalks = new PublishedTalkRepository($this->connection)->getEventTalks(1); + + self::assertSame( + [ + [101, 'Keynote', '2019-10-24 09:00', [11, 12], null], + [103, 'Salle 1', '2019-10-24 10:00', [], null], + [102, 'Salle 2', '2019-10-24 10:00', [10], 'video102'], + [100, 'Clôture', '2019-10-25 17:00', [10], 'video100'], + ], + array_map(static fn(EventTalk $eventTalk): array => [ + $eventTalk->talk->id, + $eventTalk->talk->title, + $eventTalk->startsAt->format('Y-m-d H:i'), + array_map(static fn(PublishedSpeaker $speaker): int => $speaker->id, $eventTalk->speakers), + $eventTalk->talk->youtubeId, + ], $eventTalks), + ); + self::assertSame([], new PublishedTalkRepository($this->connection)->getEventTalks(4)); + } + + public function testEventSummariesCountPublishedTalksAndVideos(): void + { + self::assertSame( + [ + ['afupday2021', 1, 0, 2021], + ['forumphp2019', 4, 2, 2019], + ['forumphp2018', 1, 1, 2018], + ], + array_map(static fn(EventTalksSummary $summary): array => [ + $summary->event->path, + $summary->talkCount, + $summary->videoCount, + $summary->getYear(), + ], new PublishedTalkRepository($this->connection)->getEventSummaries()), + ); + } + + /** + * @param list $speakerIds + */ + private function insertTalk(int $id, int $eventId, string $title, ?int $slotStart, int $type = Talk::TYPE_FULL_LONG, int $room = 1, array $speakerIds = [], ?string $youtubeId = null, bool $scheduled = true, ?string $publishedOn = null, ?int $slotEnd = null): void + { + $this->connection->insert('afup_sessions', [ + 'session_id' => $id, + 'id_forum' => $eventId, + 'date_soumission' => '2019-01-01', + 'titre' => $title, + 'abstract' => '', + 'genre' => $type, + 'plannifie' => (int) $scheduled, + 'youtube_id' => $youtubeId, + 'date_publication' => null !== $publishedOn ? date('Y-m-d H:i:s', (int) strtotime($publishedOn)) : null, + ]); + + foreach ($speakerIds as $speakerId) { + $this->connection->insert('afup_conferenciers_sessions', ['session_id' => $id, 'conferencier_id' => $speakerId]); + } + + if (null !== $slotStart) { + $this->connection->insert('afup_forum_planning', ['id_session' => $id, 'debut' => $slotStart, 'fin' => $slotEnd ?? $slotStart + 2400, 'id_forum' => $eventId, 'id_salle' => $room]); + } + } +} diff --git a/tests/unit/AppBundle/Event/Talk/EventTalksJsonLdTest.php b/tests/unit/AppBundle/Event/Talk/EventTalksJsonLdTest.php new file mode 100644 index 000000000..07991d79f --- /dev/null +++ b/tests/unit/AppBundle/Event/Talk/EventTalksJsonLdTest.php @@ -0,0 +1,61 @@ +setTitle('Forum PHP 2025')->setPath('forumphp2025'); + + self::assertSame([ + '@context' => 'https://schema.org', + '@type' => 'ItemList', + 'name' => 'Forum PHP 2025 : les talks et vidéos', + 'url' => 'https://afup.org/talks/evenements/forumphp2025', + 'numberOfItems' => 2, + 'itemListElement' => [ + ['@type' => 'ListItem', 'position' => 1, 'url' => 'https://afup.org/talks/12-keynote-d-ouverture', 'name' => 'Keynote d\'ouverture'], + ['@type' => 'ListItem', 'position' => 2, 'url' => 'https://afup.org/talks/7-cloture', 'name' => 'Clôture'], + ], + ], self::jsonLd()->getData($event, [self::eventTalk(12, 'Keynote d\'ouverture'), self::eventTalk(7, 'Clôture')])); + } + + public function testEncodedJsonCannotCloseTheScriptTag(): void + { + $event = new Event()->setTitle('')->setPath('x'); + + $json = json_encode(self::jsonLd()->getData($event, [self::eventTalk(1, '')]), PersonJsonLd::JSON_FLAGS); + + self::assertIsString($json); + self::assertStringNotContainsString('<', $json); + self::assertSame('', json_decode($json, true)['itemListElement'][0]['name']); + } + + private static function jsonLd(): EventTalksJsonLd + { + $routes = new RouteCollection(); + $routes->add('talks_show', new Route('/talks/{id}-{slug}')); + $routes->add('talks_event', new Route('/talks/evenements/{path}')); + + return new EventTalksJsonLd(new UrlGenerator($routes, new RequestContext(host: 'afup.org', scheme: 'https'))); + } + + private static function eventTalk(int $id, string $title): EventTalk + { + return new EventTalk(new PublishedTalk($id, $title), new \DateTimeImmutable(), []); + } +}