diff --git a/db/seeds/Session.php b/db/seeds/Session.php index c493c208d..e9500c31a 100644 --- a/db/seeds/Session.php +++ b/db/seeds/Session.php @@ -136,6 +136,45 @@ public function run(): void ], ]; + $forcedPlannings = [ + 6 => [ + 'debut' => new \DateTime('2020-09-15 10:00:00')->format('U'), + 'fin' => new \DateTime('2020-09-15 10:40:00')->format('U'), + ], + ]; + + // Une édition passée avec un planning complet (7 talks publiés, une vidéo sur + // deux, des horaires dans un autre ordre que les identifiants) et un talk dont + // la publication est à venir, pour les liens entre talks de la page talk. + $passedEventTalks = [ + 7 => ['titre' => 'Clôture : le futur de PHP', 'youtube_id' => 'videoTalk07', 'debut' => '16:00'], + 8 => ['titre' => 'Keynote d\'ouverture', 'youtube_id' => null, 'debut' => '09:00'], + 9 => ['titre' => 'Tester sans se ruiner', 'youtube_id' => 'videoTalk09', 'debut' => '11:00'], + 10 => ['titre' => 'Migrer une application legacy', 'youtube_id' => null, 'debut' => '12:00'], + 11 => ['titre' => 'Observabilité avec OpenTelemetry', 'youtube_id' => 'videoTalk11', 'debut' => '14:00'], + 12 => ['titre' => 'Le typage statique en pratique', 'youtube_id' => null, 'debut' => '15:00'], + 13 => ['titre' => 'Un talk pas encore publié', 'youtube_id' => 'videoTalk13', 'debut' => '17:00', 'date_publication' => new \DateTime()->modify('+5 days')->format('Y-m-d H:i:s')], + ]; + foreach ($passedEventTalks as $sessionId => $passedEventTalk) { + $sessions[] = [ + 'session_id' => $sessionId, + 'id_forum' => Event::ID_PASSED, + 'date_soumission' => '2020-05-01', + 'titre' => $passedEventTalk['titre'], + 'abstract' => 'Résumé du talk « ' . $passedEventTalk['titre'] . ' ».', + 'genre' => 1, + 'skill' => 0, + 'plannifie' => 1, + 'youtube_id' => $passedEventTalk['youtube_id'], + 'language_code' => 'fr', + 'date_publication' => $passedEventTalk['date_publication'] ?? null, + ]; + $forcedPlannings[$sessionId] = [ + 'debut' => new \DateTime('2020-09-15 ' . $passedEventTalk['debut'])->format('U'), + 'fin' => new \DateTime('2020-09-15 ' . $passedEventTalk['debut'])->modify('+40 minutes')->format('U'), + ]; + } + $sessionsByIds = []; foreach ($sessions as $session) { $sessionsByIds[$session['session_id']] = $session; @@ -158,6 +197,11 @@ public function run(): void } $conferenciers[2]['conferencier_id'] = 2; + foreach ($conferenciers as $index => $conferencier) { + if (isset($passedEventTalks[$conferencier['session_id']])) { + $conferenciers[$index]['conferencier_id'] = 3; + } + } $table = $this->table('afup_conferenciers_sessions'); $table->truncate(); @@ -179,14 +223,6 @@ public function run(): void ->save(); - $forcedPlannings = [ - 6 => [ - 'debut' => new \DateTime('2020-09-15 10:00:00')->format('U'), - 'fin' => new \DateTime('2020-09-15 10:40:00')->format('U'), - ], - ]; - - $i = 1; $plannings = []; foreach ($sessions as $session) { diff --git a/sources/AppBundle/Controller/Website/Talks/ShowAction.php b/sources/AppBundle/Controller/Website/Talks/ShowAction.php index abeff1aab..01db0c1fa 100644 --- a/sources/AppBundle/Controller/Website/Talks/ShowAction.php +++ b/sources/AppBundle/Controller/Website/Talks/ShowAction.php @@ -12,6 +12,7 @@ use AppBundle\Event\Model\Speaker; use AppBundle\Event\Speaker\SpeakerProfileResolver; use AppBundle\Event\Talk\VideoObjectJsonLd; +use AppBundle\Event\Talk\RelatedTalks; use AppBundle\Joindin\JoindinComments; use AppBundle\Subtitles\Parser; use AppBundle\Twig\ViewRenderer; @@ -50,17 +51,37 @@ public function __invoke(int $id, string $slug): Response return $this->redirectToRoute('talks_show', ['id' => $id, 'slug' => $talk->getSlug()], Response::HTTP_MOVED_PERMANENTLY); } - $speakers = $this->speakerRepository->getSpeakersByTalk($talk); + $speakers = iterator_to_array($this->speakerRepository->getSpeakersByTalk($talk), false); // Slug de la page de chaque speaker, par ID de ligne speaker : un seul index, chargé une fois pour tous. $speakerSlugs = []; + // Les autres talks de chaque personne, une fois par personne même si elle a deux lignes speaker sur ce talk. + $speakersTalks = []; /** @var Speaker $speaker */ foreach ($speakers as $speaker) { $identity = $this->speakerProfileResolver->getIdentityForSpeaker($speaker); - if (null !== $identity && null !== $speaker->getId()) { + if (null === $identity) { + continue; + } + if (null !== $speaker->getId()) { $speakerSlugs[$speaker->getId()] = $identity->slug; } + $speakersTalks[$identity->slug] ??= [ + 'identity' => $identity, + 'talks' => array_map( + static fn(array $row): array => ['talk' => $row['talk'], 'event' => $row['event']], + $this->publishedTalkRepository->getSpeakerTalks($identity->speakerIds), + ), + ]; } $event = $this->eventRepository->get($planning->eventId); + if ($event === null) { + throw $this->createNotFoundException(); + } + $relatedTalks = RelatedTalks::build( + $id, + $this->publishedTalkRepository->getEventTalks((int) $event->getId()), + array_values($speakersTalks), + ); $comments = $this->joindinComments->getCommentsFromTalk($talk); $parser = new Parser(); @@ -74,6 +95,7 @@ public function __invoke(int $id, string $slug): Response 'comments' => $comments, 'transcript' => $parsedContent, 'video_object' => $this->videoObjectJsonLd->getData($talk, $planning->start, $parsedContent, $this->generateUrl('talks_show', ['id' => $talk->getId(), 'slug' => $talk->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL)), + 'related_talks' => $relatedTalks, ]); } } diff --git a/sources/AppBundle/Event/Talk/RelatedTalks.php b/sources/AppBundle/Event/Talk/RelatedTalks.php new file mode 100644 index 000000000..da344274c --- /dev/null +++ b/sources/AppBundle/Event/Talk/RelatedTalks.php @@ -0,0 +1,83 @@ + $sameEvent + * @param list}> $bySpeaker + */ + public function __construct( + public ?PublishedTalk $previous, + public ?PublishedTalk $next, + public array $sameEvent, + public array $bySpeaker, + ) {} + + /** + * @param list $eventTalks talks publiés de l'édition, dans l'ordre du planning + * @param list}> $speakersTalks talks publiés de chaque speaker, du plus récent au plus ancien + */ + public static function build(int $talkId, array $eventTalks, array $speakersTalks): self + { + $talks = array_map(static fn(EventTalk $eventTalk): PublishedTalk => $eventTalk->talk, $eventTalks); + $position = array_find_key($talks, static fn(PublishedTalk $talk): bool => $talk->id === $talkId); + + if ($position === null) { + $previous = $next = null; + $others = $talks; + } else { + $previous = $talks[$position - 1] ?? null; + $next = $talks[$position + 1] ?? null; + // On part du talk qui suit le suivant et on boucle sur le début du planning : chaque talk + // de l'édition reçoit ainsi des liens, pas seulement les premiers du planning. + $others = [...array_slice($talks, $position + 2), ...array_slice($talks, 0, max(0, $position - 1))]; + } + + // Tri stable : les vidéos d'abord, l'ordre du planning ensuite. + usort($others, static fn(PublishedTalk $a, PublishedTalk $b): int => $b->hasYoutubeId() <=> $a->hasYoutubeId()); + $sameEvent = array_slice($others, 0, self::LIMIT); + + $linked = [$talkId => true]; + foreach ([$previous, $next, ...$sameEvent] as $talk) { + if (null !== $talk) { + $linked[$talk->id] = true; + } + } + + $bySpeaker = []; + foreach ($speakersTalks as $speakerTalks) { + $selected = []; + foreach ($speakerTalks['talks'] as $candidate) { + if (count($selected) === self::LIMIT) { + break; + } + if (isset($linked[$candidate['talk']->id])) { + continue; + } + $linked[$candidate['talk']->id] = true; + $selected[] = $candidate; + } + + if ($selected !== []) { + $bySpeaker[] = ['identity' => $speakerTalks['identity'], 'talks' => $selected]; + } + } + + return new self($previous, $next, $sameEvent, $bySpeaker); + } +} diff --git a/sources/AppBundle/Twig/FrenchContractionExtension.php b/sources/AppBundle/Twig/FrenchContractionExtension.php new file mode 100644 index 000000000..8934c1633 --- /dev/null +++ b/sources/AppBundle/Twig/FrenchContractionExtension.php @@ -0,0 +1,44 @@ +au(...)), + new TwigFunction('du', $this->du(...)), + ]; + } + + public function au(string $name): string + { + return ($this->elides($name) ? "à l'" : 'au ') . $name; + } + + public function du(string $name): string + { + return ($this->elides($name) ? "de l'" : 'du ') . $name; + } + + /** + * Élision devant une voyelle. Le « h » n'est pas traité : muet ou aspiré, il ne se devine pas. + */ + private function elides(string $name): bool + { + return preg_match('/^[aeiouyàâäéèêëîïôöùûü]/iu', $name) === 1; + } +} diff --git a/templates/site/talks/_related_talk.html.twig b/templates/site/talks/_related_talk.html.twig new file mode 100644 index 000000000..2d083ee9f --- /dev/null +++ b/templates/site/talks/_related_talk.html.twig @@ -0,0 +1,17 @@ +{# Vignette d'un talk lié, sur la page d'un talk : un seul lien (vignette et titre), et en option + une ligne de texte (`subtitle`, par exemple l'édition). Plus légère que _talk_card.html.twig, pour + ne pas multiplier les liens dans les sections de recirculation. #} + + {% if talk.hasYoutubeId %} + + {% else %} + + + + {% endif %} + {{ talk.title }} + {% if subtitle|default(null) %} + {{ subtitle }} + {% endif %} + diff --git a/templates/site/talks/show.html.twig b/templates/site/talks/show.html.twig index 57bafaf3c..840751aec 100644 --- a/templates/site/talks/show.html.twig +++ b/templates/site/talks/show.html.twig @@ -1,5 +1,12 @@ {% extends 'layouts/site.html.twig' %} +{% set breadcrumb = [ + { name: 'Accueil', url: url('home') }, + { name: 'Conférences', url: url('talks_list') }, + { name: event.title, url: url('talks_event', {path: event.path}) }, + { name: talk.title, url: url('talks_show', {id: talk.id, slug: talk.slug}) }, +] %} + {% block title %}{{ talk.title }} - {{ event.title }}{% endblock %} {% block metas %} @@ -25,6 +32,19 @@ {% if video_object %} {% endif %} + + {% endblock %} {% block content %} @@ -35,6 +55,21 @@ {% set event_url = url('talks_event', {path: event.path}) %} {% set speakers_label = speakers|map(speaker => speaker.label)|join(', ') %} + + {% if talk.hasYoutubeId %} {# Scène sombre : le bandeau n'annonce pas la page, il détache le lecteur du fond. #}
@@ -237,6 +272,61 @@ {% endif %}
{% endif %} + + {% if related_talks.previous or related_talks.next or related_talks.sameEvent|length or related_talks.bySpeaker|length %} +
+ {% if related_talks.previous or related_talks.next %} + + {% endif %} + + {% if related_talks.sameEvent|length %} +
+ Aussi {{ au(event.title) }} +
    + {% for related in related_talks.sameEvent %} +
  • {% include 'site/talks/_related_talk.html.twig' with {talk: related} only %}
  • + {% endfor %} +
+ Tous les talks {{ du(event.title) }} +
+ {% endif %} + + {% for speaker_talks in related_talks.bySpeaker %} +
+ Autres talks de {{ speaker_talks.identity.label }} +
    + {% for related in speaker_talks.talks %} +
  • {% include 'site/talks/_related_talk.html.twig' with {talk: related.talk, subtitle: related.event.title} only %}
  • + {% endfor %} +
+ Tous les talks de {{ speaker_talks.identity.label }} +
+ {% endfor %} +
+ {% endif %} {% endblock %} {% block javascripts %} diff --git a/tests/behat/bootstrap/FeatureContext.php b/tests/behat/bootstrap/FeatureContext.php index 14a0c0acd..3d9f52e5e 100644 --- a/tests/behat/bootstrap/FeatureContext.php +++ b/tests/behat/bootstrap/FeatureContext.php @@ -29,6 +29,7 @@ class FeatureContext implements Context use EmailContext; use FormContext; use PdfContext; + use SeoContext; use TimeContext; use WaitContext; diff --git a/tests/behat/bootstrap/SeoContext.php b/tests/behat/bootstrap/SeoContext.php new file mode 100644 index 000000000..a220187d3 --- /dev/null +++ b/tests/behat/bootstrap/SeoContext.php @@ -0,0 +1,71 @@ +minkContext->getSession(); + + preg_match('#^/talks/(\d+)-#', (string) parse_url($session->getCurrentUrl(), PHP_URL_PATH), $matches); + $currentTalkId = $matches[1] ?? null; + + $found = 0; + foreach ($session->getPage()->findAll('css', 'a[href]') as $link) { + $path = (string) parse_url((string) $link->getAttribute('href'), PHP_URL_PATH); + if (preg_match('#^/talks/(\d+)-[^/]+$#', $path, $matches) && $matches[1] !== $currentTalkId) { + ++$found; + } + } + + if ($found < $count) { + throw new ExpectationException( + sprintf('Expected at least %d links to other talks, found %d', $count, $found), + $session->getDriver(), + ); + } + } + + #[Then('the JSON-LD :type should have the following items:')] + public function assertJsonLdHasItems(string $type, TableNode $expectedItems): void + { + $session = $this->minkContext->getSession(); + + $items = null; + foreach ($session->getPage()->findAll('css', 'script[type="application/ld+json"]') as $script) { + $data = json_decode($script->getHtml(), true, flags: JSON_THROW_ON_ERROR); + if (($data['@type'] ?? null) === $type) { + $items = $data['itemListElement'] ?? []; + break; + } + } + + if ($items === null) { + throw new ExpectationException(sprintf('No JSON-LD of type "%s" found', $type), $session->getDriver()); + } + + $actual = array_map( + fn(array $item): array => [ + 'position' => (string) $item['position'], + 'name' => $item['name'], + 'item' => $item['item'], + ], + $items, + ); + + if ($actual !== $expectedItems->getHash()) { + throw new ExpectationException( + sprintf('JSON-LD "%s" items do not match: %s', $type, json_encode($actual, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)), + $session->getDriver(), + ); + } + } +} diff --git a/tests/behat/features/Api/Api.feature b/tests/behat/features/Api/Api.feature index 51d6e834a..4f5ecb3ac 100644 --- a/tests/behat/features/Api/Api.feature +++ b/tests/behat/features/Api/Api.feature @@ -65,7 +65,8 @@ Feature: API pour event Given I am on "/blog/passed/program" Then the response should contain "Révolutionons PHP" And the response should not contain "/talks/6-" - And the response should not contain "Voir la vidéo" + # Les talks de la même édition qui ont une vidéo restent liés + And the response should contain "href=\"https://apachephptest:80/talks/9-tester-sans-se-ruiner\"" @reloadDbWithTestData Scenario: Les speakers sont liés à leur page sur afup.org quand elle existe diff --git a/tests/behat/features/PublicSite/Talks.feature b/tests/behat/features/PublicSite/Talks.feature index 1bd418bda..3f05a0482 100644 --- a/tests/behat/features/PublicSite/Talks.feature +++ b/tests/behat/features/PublicSite/Talks.feature @@ -239,7 +239,7 @@ Feature: Site Public - Talks """ And the texts of "section#evenements-2020 li p" should be, in this order: """ - 1 talk · 0 vidéo + 7 talks · 3 vidéos """ And the response should contain "href=\"/talks/evenements/forum\"" And I should see "2 talks · 2 vidéos" @@ -271,12 +271,15 @@ Feature: Site Public - Talks Then the response status code should be 200 And I should see "Historique des conférences de l'AFUP" in the "h1" element And the response should contain "" - # Les données de test n'ont que 2 talks publiés avec vidéo (le hub en affiche jusqu'à 12) ; - # « Révolutionons PHP » a une vidéo mais une publication à venir. + # Les données de test n'ont que 5 talks publiés avec vidéo (le hub en affiche jusqu'à 12) ; + # « Révolutionons PHP » et « Un talk pas encore publié » ont une vidéo mais une publication à venir. And the texts of "#dernieres-videos article h3" should be, in this order: """ REST ou GraphQL ? Exemples illustrés avec Symfony et API Platform Jouons tous ensemble à un petit jeu + Clôture : le futur de PHP + Observabilité avec OpenTelemetry + Tester sans se ruiner """ 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/1-jouons-tous-ensemble-a-un-petit-jeu\"" @@ -322,3 +325,52 @@ Feature: Site Public - Talks Then the response should not contain "id=\"dernieres-videos\"" When I go to "/talks/?q=&hPP=7&idx=afup_talks&p=0&is_v=1&utm_source=newsletter" Then the response should contain "id=\"dernieres-videos\"" + + @reloadDbWithTestData + Scenario: Fil d'Ariane de la page d'un talk + When I go to "/talks/6-revolutionons-php" + Then I should see "Accueil" in the "nav[aria-label^=Fil]" element + And I should see "Conférences" in the "nav[aria-label^=Fil]" element + And I should see "Un évènement du passé" in the "nav[aria-label^=Fil]" element + And I should see "Révolutionons PHP" in the "nav[aria-label^=Fil] [aria-current=page]" element + And the JSON-LD "BreadcrumbList" should have the following items: + | position | name | item | + | 1 | Accueil | https://apachephptest:80/ | + | 2 | Conférences | https://apachephptest:80/talks/ | + | 3 | Un évènement du passé | https://apachephptest:80/talks/evenements/passed | + | 4 | Révolutionons PHP | https://apachephptest:80/talks/6-revolutionons-php | + + @reloadDbWithTestData + Scenario: Liens vers les autres talks depuis la page d'un talk + When I go to "/talks/6-revolutionons-php" + Then the page should contain at least 7 links to other talks + And I should see "Keynote d'ouverture" in the "a[rel=prev]" element + And I should see "Tester sans se ruiner" in the "a[rel=next]" element + # 3 talks de l'édition, hors voisins, les vidéos d'abord, puis le lien vers la page de l'édition + And I should see "Aussi à l'Un évènement du passé" + And the texts of "section:has(a[href='/talks/evenements/passed']) li" should be, in this order: + """ + Observabilité avec OpenTelemetry + Clôture : le futur de PHP + Migrer une application legacy + """ + And I should see "Tous les talks de l'Un évènement du passé" + And I should not see "Le typage statique en pratique" + # Les autres talks de la personne, du plus récent au plus ancien, puis le lien vers sa page + And I should see "Autres talks de Geoffrey BACHELET" + And the texts of "section:has(a[href='/talks/speakers/geoffrey-bachelet']) li" should be, in this order: + """ + REST ou GraphQL ? Exemples illustrés avec Symfony et API Platform forum + Jouons tous ensemble à un petit jeu forum + """ + And I should see "Tous les talks de Geoffrey BACHELET" + And I should not see "Un talk pas encore publié" + + @reloadDbWithTestData + Scenario: Premier et dernier talks du planning d'une édition + When I go to "/talks/8-keynote-d-ouverture" + Then I should not see "Précédent dans le planning" + And I should see "Révolutionons PHP" in the "a[rel=next]" element + When I go to "/talks/7-cloture-le-futur-de-php" + Then I should see "Le typage statique en pratique" in the "a[rel=prev]" element + And I should not see "Suivant dans le planning" diff --git a/tests/behat/files/admin_talks_export_joind_in.csv b/tests/behat/files/admin_talks_export_joind_in.csv index 338bb4e5b..df6535afe 100644 --- a/tests/behat/files/admin_talks_export_joind_in.csv +++ b/tests/behat/files/admin_talks_export_joind_in.csv @@ -1,2 +1,8 @@ Title,Description,Speaker,Date,Time,Type -"Révolutionons PHP","Hey ! Viens changer PHP avec moi !","Geoffrey Bachelet",2020-09-15,10:00,Talk \ No newline at end of file +"Keynote d'ouverture","Résumé du talk « Keynote d'ouverture ».","John Doe",2020-09-15,09:00,Talk +"Révolutionons PHP","Hey ! Viens changer PHP avec moi !","Geoffrey Bachelet",2020-09-15,10:00,Talk +"Tester sans se ruiner","Résumé du talk « Tester sans se ruiner ».","John Doe",2020-09-15,11:00,Talk +"Migrer une application legacy","Résumé du talk « Migrer une application legacy ».","John Doe",2020-09-15,12:00,Talk +"Observabilité avec OpenTelemetry","Résumé du talk « Observabilité avec OpenTelemetry ».","John Doe",2020-09-15,14:00,Talk +"Le typage statique en pratique","Résumé du talk « Le typage statique en pratique ».","John Doe",2020-09-15,15:00,Talk +"Clôture : le futur de PHP","Résumé du talk « Clôture : le futur de PHP ».","John Doe",2020-09-15,16:00,Talk \ No newline at end of file diff --git a/tests/unit/AppBundle/Event/Talk/RelatedTalksTest.php b/tests/unit/AppBundle/Event/Talk/RelatedTalksTest.php new file mode 100644 index 000000000..d8e5fa635 --- /dev/null +++ b/tests/unit/AppBundle/Event/Talk/RelatedTalksTest.php @@ -0,0 +1,129 @@ +eventTalks([1 => false, 2 => false, 3 => false]), []); + + self::assertSame(1, $related->previous?->id); + self::assertSame(3, $related->next?->id); + } + + public function testFirstAndLastTalksHaveNoPreviousOrNext(): void + { + $eventTalks = $this->eventTalks([1 => false, 2 => false]); + + self::assertNull(RelatedTalks::build(1, $eventTalks, [])->previous); + self::assertNull(RelatedTalks::build(2, $eventTalks, [])->next); + } + + public function testSameEventSkipsNeighboursStartsAfterTheTalkAndPutsVideosFirst(): void + { + // Planning : 1 à 7, 4 courant ; 3 et 5 sont ses voisins. Seuls 1 et 7 ont une vidéo. + $related = RelatedTalks::build(4, $this->eventTalks([1 => true, 2 => false, 3 => false, 4 => false, 5 => false, 6 => false, 7 => true]), []); + + self::assertSame([7, 1, 6], $this->ids($related->sameEvent)); + } + + public function testSameEventIsLimitedToThreeTalks(): void + { + $related = RelatedTalks::build(1, $this->eventTalks(array_fill(1, 9, false)), []); + + self::assertSame([3, 4, 5], $this->ids($related->sameEvent)); + } + + public function testTalkMissingFromThePlanningHasNoNeighboursButStillLinksToItsEvent(): void + { + $related = RelatedTalks::build(99, $this->eventTalks([1 => false, 2 => true]), []); + + self::assertNull($related->previous); + self::assertNull($related->next); + self::assertSame([2, 1], $this->ids($related->sameEvent)); + } + + public function testSpeakerTalksAreLimitedAndNeverRepeatALinkedTalk(): void + { + $alice = $this->identity('alice-martin'); + $bob = $this->identity('bob-durand'); + $event = new PublishedEvent(2, 'Forum PHP 2020', 'forum2020'); + + // 2 est le talk suivant, déjà lié ; 20 est commun à Alice et Bob. + $related = RelatedTalks::build(1, $this->eventTalks([1 => false, 2 => false]), [ + ['identity' => $alice, 'talks' => [ + ['talk' => $this->talk(1), 'event' => $event], + ['talk' => $this->talk(2), 'event' => $event], + ['talk' => $this->talk(20), 'event' => $event], + ['talk' => $this->talk(21), 'event' => $event], + ['talk' => $this->talk(22), 'event' => $event], + ['talk' => $this->talk(23), 'event' => $event], + ]], + ['identity' => $bob, 'talks' => [ + ['talk' => $this->talk(20), 'event' => $event], + ['talk' => $this->talk(30), 'event' => $event], + ]], + ]); + + self::assertCount(2, $related->bySpeaker); + self::assertSame($alice, $related->bySpeaker[0]['identity']); + self::assertSame([20, 21, 22], $this->ids(array_column($related->bySpeaker[0]['talks'], 'talk'))); + self::assertSame($bob, $related->bySpeaker[1]['identity']); + self::assertSame([30], $this->ids(array_column($related->bySpeaker[1]['talks'], 'talk'))); + self::assertSame($event, $related->bySpeaker[1]['talks'][0]['event']); + } + + public function testSpeakerWithoutOtherTalksIsOmitted(): void + { + $related = RelatedTalks::build(1, $this->eventTalks([1 => false]), [ + ['identity' => $this->identity('alice-martin'), 'talks' => [['talk' => $this->talk(1), 'event' => new PublishedEvent(2, 'Forum PHP 2020', 'forum2020')]]], + ]); + + self::assertSame([], $related->bySpeaker); + } + + /** + * @param array $hasVideoById + * + * @return list + */ + private function eventTalks(array $hasVideoById): array + { + $eventTalks = []; + foreach ($hasVideoById as $id => $hasVideo) { + $eventTalks[] = new EventTalk($this->talk($id, $hasVideo), new \DateTimeImmutable('2020-10-01 09:00'), []); + } + + return $eventTalks; + } + + private function talk(int $id, bool $hasVideo = false): PublishedTalk + { + return new PublishedTalk($id, 'Talk ' . $id, $hasVideo ? 'video' . $id : null); + } + + private function identity(string $slug): SpeakerIdentity + { + return new SpeakerIdentity($slug, 'Prénom', 'Nom', [1], new \DateTimeImmutable('2020-10-01')); + } + + /** + * @param list $talks + * + * @return list + */ + private function ids(array $talks): array + { + return array_map(static fn(PublishedTalk $talk): int => $talk->id, $talks); + } +} diff --git a/tests/unit/AppBundle/Twig/FrenchContractionExtensionTest.php b/tests/unit/AppBundle/Twig/FrenchContractionExtensionTest.php new file mode 100644 index 000000000..1f855d73c --- /dev/null +++ b/tests/unit/AppBundle/Twig/FrenchContractionExtensionTest.php @@ -0,0 +1,36 @@ +au($name)); + self::assertSame($expectedDu, $extension->du($name)); + } + + /** + * @return array + */ + public static function names(): array + { + return [ + 'Forum PHP' => ['Forum PHP 2024', 'au Forum PHP 2024', 'du Forum PHP 2024'], + 'PHP Tour' => ['PHP Tour Lyon 2014', 'au PHP Tour Lyon 2014', 'du PHP Tour Lyon 2014'], + 'AFUP Day, élision' => ['AFUP Day 2024 Lyon', "à l'AFUP Day 2024 Lyon", "de l'AFUP Day 2024 Lyon"], + 'voyelle minuscule' => ['apéro PHP', "à l'apéro PHP", "de l'apéro PHP"], + 'voyelle accentuée' => ['Événement en ligne', "à l'Événement en ligne", "de l'Événement en ligne"], + 'h non élidé' => ['Hackathon', 'au Hackathon', 'du Hackathon'], + ]; + } +}