Skip to content
Snippets Groups Projects
Commit d6acaf52 authored by Fabrice Gangler's avatar Fabrice Gangler :art:
Browse files

test: check footer links, in particular aria-current attribute

parent 7114d5ff
No related branches found
No related tags found
No related merge requests found
<?php
/*
* This file is part of the Comptoir-du-Libre software.
* <https://gitlab.adullact.net/Comptoir/comptoir-du-libre>
*
* Copyright (c) ADULLACT <https://adullact.org>
* Association des Développeurs et Utilisateurs de Logiciels Libres
* pour les Administrations et les Collectivités Territoriales
*
* Comptoir-du-Libre is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU Affero General Public License
* along with this software. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>.
*/
declare(strict_types=1);
namespace App\Tests\Functional;
use App\Tests\Functional\TestHelperTrait;
use Symfony\Component\DomCrawler\Crawler;
use function PHPUnit\Framework\isNull;
trait TestHelperFooterTrait
{
use TestHelperTrait;
/**
* @param Crawler $crawler
* @param string $locale
* @param string|null $currentPageUrl default is NULL
* @return void
*/
public function checkFooter(
Crawler $crawler,
string $locale = 'en',
null|string $currentPageUrl = null ,
): void {
$footerMainNavLinks = [
'/en/' => 'Home',
'/en/pages/contact' => 'Contact',
'/en/pages/about' => 'About',
'/en/pages/legal' => 'Legal',
'/en/pages/accessibility' => 'Accessibility',
'/en/pages/opendata' => 'Open Data',
];
if ($locale === 'fr') {
$footerMainNavLinks = [
'/fr/' => 'Accueil',
'/fr/pages/contact' => 'Contact',
'/fr/pages/about' => 'À Propos',
'/fr/pages/legal' => 'Mentions légales',
'/fr/pages/accessibility' => 'Accessibilité : non conforme',
'/fr/pages/opendata' => 'Données ouvertes',
];
}
// Check the number of items in footer main nav
$footerMainNavCssSelector = "footer#page_footer nav > ul";
$this->assertEquals(
expected: count($footerMainNavLinks),
actual: $crawler->filter("$footerMainNavCssSelector > li")->count(),
message: 'Number of links in footer main nav is different from expected.'
);
// Check each links in footer main nav
foreach ($footerMainNavLinks as $url => $linkText) {
$linkSelector = "$footerMainNavCssSelector a[href='$url']";
$this->checkAttribute(
crawler: $crawler,
cssFilter: "$linkSelector",
attributesExpected: [ '_text' => "$linkText", 'href' => "$url" ],
);
if ($currentPageUrl === $url) {
$this->assertEquals(
expected: 'page',
actual: $crawler->filter("$linkSelector")->attr('aria-current'),
message: "Footer: missing [ aria-current ] attribut" .
"\n- current page: $currentPageUrl\n- footer link: $url --> $linkText",
);
} else {
$this->assertNull(
actual: $crawler->filter("$linkSelector")->attr('aria-current'),
message: "Footer: not allowed [ aria-current ] attribut" .
"\n- current page: $currentPageUrl\n- footer link: $url --> $linkText",
);
}
}
}
}
......@@ -124,37 +124,6 @@ public function checkRedirectionToNewUrl(
$this->assertResponseStatusCodeSame(Response::HTTP_OK); // HTTP status code = 200
}
/**
* @todo FIXME
*/
public function checkFooter(Crawler $crawler, bool $displayVersion = false): void
{
$version = '';
if ($displayVersion === true) {
$version = ' major.minor.patch';
}
$footerExpectedLink1 = [
'_name' => 'a',
'_text' => "Comptoir$version",
'href' => 'https://gitlab.adullact.net/Comptoir/comptoir-du-libre'
];
$footerExpectedLink2 = [
'_name' => 'a',
'_text' => 'Adullact',
'href' => 'https://adullact.org'
];
$footerExpectedLink3 = [
'_name' => 'a',
'_text' => 'GNU AGPL v3',
'href' => 'https://www.gnu.org/licenses/agpl-3.0.html'
];
// $this->checkAttribute($crawler, '#footer_link-to-repository', $footerExpectedLink1);
// $this->checkAttribute($crawler, '#footer_link-to-creator-website', $footerExpectedLink2);
// $this->checkAttribute($crawler, '#footer_link-to-license', $footerExpectedLink3);
dump("------------------> TODO fix checkFooter()");
}
/**
* @todo refactor
* @group refactor
......@@ -348,6 +317,9 @@ public function commonCheckerUserCanLoginV2(
$this->assertSelectorTextSame('.connected_user_email', "$mail");
}
/**
* @todo no used yet
*/
public function commonCheckerUserCanLogout(
string $mail,
string $locale = 'en',
......@@ -364,11 +336,13 @@ public function commonCheckerUserCanLogout(
$this->assertResponseHasHeader("Location");
$this->assertResponseHeaderSame("Location", "http://localhost/$locale/");
$crawler = $kernelBrowser->request('GET', '/');
$crawler = $kernelBrowser->request('GET', "/$locale/");
$this->assertResponseStatusCodeSame(Response::HTTP_OK); // HTTP status code = 200
$this->assertSelectorNotExists('.connected_user_email');
$this->assertSelectorTextNotContains('body', "$mail");
$this->checkFooter($crawler, false);
// HTML content checks footer
$this->checkFooter(crawler: $crawler, locale: $locale, currentPageUrl: "/$locale/");
}
/// ///////////////////////////////////////////////////////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment