diff --git a/core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php b/core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php index b31b9bafb43b8f7234ff6c654bdcd63e75828f0b..9e760262ae8fe549e228cda83f0f9b16533fa078 100644 --- a/core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php +++ b/core/tests/Drupal/FunctionalTests/Theme/OliveroTest.php @@ -27,6 +27,8 @@ class OliveroTest extends BrowserTestBase { */ protected static $modules = [ 'olivero_test', + 'pager_test', + 'dblog', ]; /** @@ -129,4 +131,33 @@ public function testIsUninstallable() { $this->assertSession()->pageTextContains('The Olivero theme has been uninstalled.'); } + /** + * Tests pager attribute is present using pager_test. + */ + public function testPagerAttribute(): void { + // Insert 300 log messages. + $logger = \Drupal::logger('pager_test'); + for ($i = 0; $i < 300; $i++) { + $logger->debug($this->randomString()); + } + + $this->drupalLogin($this->drupalCreateUser(['access site reports'])); + + $this->drupalGet('pager-test/multiple-pagers', ['query' => ['page' => 1]]); + $this->assertSession()->statusCodeEquals(200); + $elements = $this->xpath('//ul[contains(@class, :class)]/li', [':class' => 'pager__items']); + $this->assertNotEmpty($elements, 'Pager found.'); + + // Check all links for pager-test attribute. + foreach ($elements as $element) { + $link = $element->find('css', 'a'); + // Current page does not have a link. + if (empty($link)) { + continue; + } + $this->assertTrue($link->hasAttribute('pager-test'), 'Pager item has attribute pager-test'); + $this->assertTrue($link->hasClass('lizards')); + } + } + } diff --git a/core/themes/olivero/templates/navigation/pager.html.twig b/core/themes/olivero/templates/navigation/pager.html.twig index 29d011513e10c9f039a2bfbab4b57bb62c5396e8..2eb131e52cac4dd98eaa873abd6c797522fe76e5 100644 --- a/core/themes/olivero/templates/navigation/pager.html.twig +++ b/core/themes/olivero/templates/navigation/pager.html.twig @@ -38,7 +38,7 @@ {% if items.first %} {% apply spaceless %} <li class="pager__item pager__item--control pager__item--first"> - <a href="{{ items.first.href }}" class="pager__link" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title', 'class') }}> + <a href="{{ items.first.href }}" title="{{ 'Go to first page'|t }}"{{ items.first.attributes|without('href', 'title').addClass('pager__link') }}> <span class="visually-hidden">{{ 'First page'|t }}</span> {% include "@olivero/../images/pager-first.svg" %} </a> @@ -50,7 +50,7 @@ {% if items.previous %} {% apply spaceless %} <li class="pager__item pager__item--control pager__item--previous"> - <a href="{{ items.previous.href }}" class="pager__link" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel', 'class') }}> + <a href="{{ items.previous.href }}" title="{{ 'Go to previous page'|t }}" rel="prev"{{ items.previous.attributes|without('href', 'title', 'rel').addClass('pager__link') }}> <span class="visually-hidden">{{ 'Previous page'|t }}</span> {% include "@olivero/../images/pager-previous.svg" %} </a> @@ -73,7 +73,7 @@ {% set title = 'Go to page @key'|t({'@key': key}) %} {% endif %} {% if current != key %} - <a href="{{ item.href }}" class="pager__link{{ current == key ? ' is-active' }}" title="{{ title }}"{{ item.attributes|without('href', 'title', 'class') }}> + <a href="{{ item.href }}" title="{{ title }}"{{ item.attributes|without('href', 'title').addClass('pager__link', current == key ? ' is-active') }}> {% endif %} <span class="visually-hidden"> {{ current == key ? 'Current page'|t : 'Page'|t }} @@ -95,7 +95,7 @@ {% if items.next %} {% apply spaceless %} <li class="pager__item pager__item--control pager__item--next"> - <a href="{{ items.next.href }}" class="pager__link" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel', 'class') }}> + <a href="{{ items.next.href }}" title="{{ 'Go to next page'|t }}" rel="next"{{ items.next.attributes|without('href', 'title', 'rel').addClass('pager__link') }}> <span class="visually-hidden">{{ 'Next page'|t }}</span> {% include "@olivero/../images/pager-previous.svg" %} </a> @@ -107,7 +107,7 @@ {% if items.last %} {% apply spaceless %} <li class="pager__item pager__item--control pager__item--last"> - <a href="{{ items.last.href }}" class="pager__link" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title', 'class') }}> + <a href="{{ items.last.href }}" title="{{ 'Go to last page'|t }}"{{ items.last.attributes|without('href', 'title').addClass('pager__link') }}> <span class="visually-hidden">{{ 'Last page'|t }}</span> {% include "@olivero/../images/pager-first.svg" %} </a>