From 52682a4684523f82879027a490a5c07e14e43886 Mon Sep 17 00:00:00 2001 From: Imanol Eguskiza Date: Mon, 19 Feb 2024 08:41:50 +0100 Subject: [PATCH] EWPP-3916: Update tasks tests. --- ...cl+twig-component-tabs+4.0.0-beta-2.patch} | 0 tests/src/Kernel/MenuLocalTasksTest.php | 51 ++++++++----------- tests/src/PatternAssertions/TabsAssert.php | 4 +- 3 files changed, 22 insertions(+), 33 deletions(-) rename patches/{@ecl+twig-component-tabs+4.0.0-beta-1.patch => @ecl+twig-component-tabs+4.0.0-beta-2.patch} (100%) diff --git a/patches/@ecl+twig-component-tabs+4.0.0-beta-1.patch b/patches/@ecl+twig-component-tabs+4.0.0-beta-2.patch similarity index 100% rename from patches/@ecl+twig-component-tabs+4.0.0-beta-1.patch rename to patches/@ecl+twig-component-tabs+4.0.0-beta-2.patch diff --git a/tests/src/Kernel/MenuLocalTasksTest.php b/tests/src/Kernel/MenuLocalTasksTest.php index e27366a21..a1190f44d 100644 --- a/tests/src/Kernel/MenuLocalTasksTest.php +++ b/tests/src/Kernel/MenuLocalTasksTest.php @@ -5,7 +5,7 @@ namespace Drupal\Tests\oe_theme\Kernel; use Drupal\Core\Url; -use Symfony\Component\DomCrawler\Crawler; +use Drupal\Tests\oe_theme\PatternAssertions\TabsAssert; /** * Tests that Drupal local tasks are properly rendered. @@ -54,36 +54,25 @@ public function testMenuLocalTasks(): void { ]; $html = $this->renderRoot($render); - $crawler = new Crawler($html); - - // Assert wrapper contains ECL class. - $actual = $crawler->filter('nav.ecl-navigation'); - $this->assertCount(1, $actual); - - // Assert list contains ECL classes. - $actual = $crawler->filter('ul.ecl-navigation.ecl-u-pb-m.ecl-u-pt-m'); - $this->assertCount(1, $actual); - - // Assert active link contains ECL classes. - $actual = $crawler->filter('li.ecl-navigation__item--active')->text(); - $this->assertEquals('Third link - Active', trim($actual)); - - // Assert regular link contains ECL classes and the links are ordered by - // weight. - $actual = $crawler->filter('li.ecl-navigation__item > a') - ->eq(0) - ->text(); - $this->assertEquals('First link - Inactive', trim($actual)); - - $actual = $crawler->filter('li.ecl-navigation__item > a') - ->eq(1) - ->text(); - $this->assertEquals('Second link', trim($actual)); - - $actual = $crawler->filter('li.ecl-navigation__item > a') - ->eq(2) - ->text(); - $this->assertEquals('Third link - Active', trim($actual)); + $expected_items = [ + 'items' => [ + [ + 'label' => 'First link - Inactive', + 'path' => 'http://www.inactive.com', + ], + [ + 'label' => 'Second link', + 'path' => 'http://www.middlelink.com', + ], + [ + 'label' => 'Third link - Active', + 'path' => 'http://www.active.com', + 'is_current' => TRUE, + ], + ], + ]; + $assert = new TabsAssert(); + $assert->assertPattern($expected_items, $html); } } diff --git a/tests/src/PatternAssertions/TabsAssert.php b/tests/src/PatternAssertions/TabsAssert.php index b4cda63da..354c99244 100644 --- a/tests/src/PatternAssertions/TabsAssert.php +++ b/tests/src/PatternAssertions/TabsAssert.php @@ -1,6 +1,6 @@ filter('div.ecl-tabs__item'); + $item_elements = $crawler->filter('div.ecl-tabs__item:not(.ecl-tabs__item--more)'); self::assertCount(count($expected_items), $item_elements); foreach ($expected_items as $index => $expected_item) { $item_element = $item_elements->eq($index);