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
18 changes: 0 additions & 18 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -3733,12 +3733,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Website/CompanyPublicProfile/ListAction.php',
];
$ignoreErrors[] = [
'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#',
'identifier' => 'foreach.nonIterable',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method getCompanyName\\(\\) on mixed\\.$#',
'identifier' => 'method.nonObject',
Expand Down Expand Up @@ -3775,12 +3769,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Controller\\\\Website\\\\Global\\\\HtmlSitemapAction\\:\\:talks\\(\\) return type has no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Website/Global/HtmlSitemapAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'careers_page_url\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
Expand Down Expand Up @@ -5461,12 +5449,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkRepository\\:\\:getAllPastTalks\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkRepository\\:\\:getAllTalksAndRatingsForUser\\(\\) return type with generic interface CCMBenchmark\\\\Ting\\\\Repository\\\\CollectionInterface does not specify its types\\: T$#',
'identifier' => 'missingType.generics',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Afup\Site\Corporate\Feuille;
use AppBundle\Association\Model\Repository\CompanyMemberRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Talk;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use AppBundle\Site\Entity\Repository\FeuilleRepository;
use AppBundle\Twig\ViewRenderer;
Expand Down Expand Up @@ -90,16 +89,18 @@ private function news(): array
return $news;
}

/**
* @return list<array{name: string, url: string}>
*/
private function talks(): array
{
$talks = [];
$talkList = $this->talkRepository->getAllPastTalks(new \DateTime()->setTime(29, 59, 59));
$talkList = $this->talkRepository->getPublishedTalks(new \DateTimeImmutable()->setTime(23, 59, 59));

/** @var Talk $talk */
foreach ($talkList as $talk) {
foreach ($talkList as $talkId => $talk) {
$url = $this->generateUrl(
'talks_show',
['id' => $talk->getId(), 'slug' => $talk->getSlug()],
['id' => $talkId, 'slug' => $talk->getSlug()],
);

$talks[] = [
Expand Down
27 changes: 23 additions & 4 deletions sources/AppBundle/Event/Model/Repository/TalkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,36 @@ public function getScheduledTalksByEvent(int $eventId): CollectionInterface
return $query->query($this->getCollection(new HydratorSingleObject()));
}

public function getAllPastTalks(\DateTime $dateTime)
/**
* Talks publiés : terminés avant la date donnée et visibles dans l'historique
* (ni clinique, ni présentation des speakers, et planifiés), indexés par
* identifiant pour qu'un talk planifié sur plusieurs créneaux n'apparaisse qu'une fois.
*
* Source commune du plan du site et du sitemap XML : chaque talk renvoyé a une page
* `talks_show` qui répond 200.
*
* @return array<int, Talk>
*/
public function getPublishedTalks(\DateTimeInterface $endedBefore): array
{
$query = $this->getPreparedQuery(
'
SELECT talk.*
FROM afup_sessions AS talk
LEFT JOIN afup_forum_planning afp ON talk.session_id = afp.id_session
INNER JOIN afup_forum_planning afp ON talk.session_id = afp.id_session
WHERE afp.fin <= :date_fin',
)->setParams(['date_fin' => $dateTime->format('U')]);
)->setParams(['date_fin' => $endedBefore->format('U')]);

$publishedTalks = [];
/** @var Talk $talk */
foreach ($query->query($this->getCollection(new HydratorSingleObject())) as $talk) {
$talkId = $talk->getId();
if ($talkId !== null && $talk->isDisplayedOnHistory()) {
$publishedTalks[$talkId] = $talk;
}
}

return $query->query($this->getCollection(new HydratorSingleObject()));
return $publishedTalks;
}

/**
Expand Down
10 changes: 1 addition & 9 deletions sources/AppBundle/Subscriber/SitemapXmlSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Model\Talk;
use AppBundle\Site\Entity\Repository\FeuilleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
Expand Down Expand Up @@ -55,14 +54,7 @@ public function populate(SitemapPopulateEvent $event): void

public function registerTalksUrls(UrlContainerInterface $urls): void
{
/** @var Talk[] $talks */
$talks = $this->talkRepository->getAllPastTalks(new \DateTime());

foreach ($talks as $talk) {
if (!$talk->isDisplayedOnHistory()) {
continue;
}

foreach ($this->talkRepository->getPublishedTalks(new \DateTimeImmutable()) as $talk) {
$url = new UrlConcrete(
$this->urlGenerator->generate(
'talks_show',
Expand Down
37 changes: 37 additions & 0 deletions tests/behat/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,41 @@ public function openMenu(string $text): void

$node->click();
}

#[Then('/^every link matching "(?P<pattern>(?:[^"]|\\")*)" should respond with status (?P<code>\d+)$/')]
public function assertEveryLinkMatchingRespondsWithStatus(string $pattern, int $code): void
{
$session = $this->minkContext->getSession();

$urls = [];
foreach ($session->getPage()->findAll('css', 'a[href]') as $link) {
$href = (string) $link->getAttribute('href');
if (preg_match($pattern, $href)) {
$urls[$href] = true;
}
}

if ($urls === []) {
throw new ExpectationException(
sprintf('No link matching "%s" was found', $pattern),
$session->getDriver(),
);
}

$failures = [];
foreach (array_keys($urls) as $url) {
$this->minkContext->visitPath($url);
$status = $session->getStatusCode();
if ($status !== $code) {
$failures[] = sprintf('%s (%d)', $url, $status);
}
}

if ($failures !== []) {
throw new ExpectationException(
sprintf('%d link(s) matching "%s" did not respond with status %d: %s', count($failures), $pattern, $code, implode(', ', $failures)),
$session->getDriver(),
);
}
}
}
8 changes: 8 additions & 0 deletions tests/behat/features/PublicSite/Sitemaps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ Feature: Site Public - Sitemaps
Scenario: On accède sitemap default
Given I am on "/sitemap.default.xml"
And the response should contain "<loc>https://apachephptest:80/home</loc>"

@reloadDbWithTestData
Scenario: Le plan du site ne lie que des talks publiés
Given I am on "/plan-du-site"
Then the response status code should be 200
And the response should contain "/talks/1-jouons-tous-ensemble-a-un-petit-jeu"
And the response should not contain "/talks/4-une-conf-pour-voter"
And every link matching "#^/talks/\d+-[^/]+$#" should respond with status 200
Loading