From 23fc2b6c353b68a7a181d23be6efd25b22fe7295 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Tue, 13 Jun 2023 07:00:35 +1000 Subject: [PATCH] Issue #3004897 by clemens.tolboom, smustgrave, ridhimaabrol24, pooja saraah, ameymudras, ranjith_kumar_k_u, danielgry, larowlan, quietone: Respect tour status (disabled | enabled) --- .../tour/tests/src/Functional/TourTest.php | 27 ++++++++++ .../tests/src/Functional/TourTestBase.php | 50 +++++++++++-------- core/modules/tour/tour.module | 1 + 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/core/modules/tour/tests/src/Functional/TourTest.php b/core/modules/tour/tests/src/Functional/TourTest.php index 11bfef4d54c..a7d8d40fdb8 100644 --- a/core/modules/tour/tests/src/Functional/TourTest.php +++ b/core/modules/tour/tests/src/Functional/TourTest.php @@ -234,6 +234,33 @@ class TourTest extends TourTestBasic { $this->assertCount(0, $elements, 'Did not find English variant of tip 1.'); } + /** + * Tests enabling and disabling the tour tip functionality. + */ + public function testStatus() { + // Set tour tip status as enabled. + $tour = Tour::load('tour-test'); + $tour->setStatus(TRUE); + $tour->save(); + + $this->drupalGet('tour-test-1'); + $this->assertSession()->statusCodeEquals(200); + + // Tour tips should be visible on the page. + $this->assertTourTips(); + + $tour->setStatus(FALSE); + $tour->save(); + + // Navigate and verify the tour_test_1 tip is not found with + // appropriate classes. + $this->drupalGet('tour-test-1'); + $this->assertSession()->statusCodeEquals(200); + + // No tips expected as tour is disabled. + $this->assertTourTips(expectEmpty: TRUE); + } + /** * Gets tour tips from the JavaScript drupalSettings variable. * diff --git a/core/modules/tour/tests/src/Functional/TourTestBase.php b/core/modules/tour/tests/src/Functional/TourTestBase.php index 8a55f1e4fad..de9fb4595e5 100644 --- a/core/modules/tour/tests/src/Functional/TourTestBase.php +++ b/core/modules/tour/tests/src/Functional/TourTestBase.php @@ -28,8 +28,10 @@ abstract class TourTestBase extends BrowserTestBase { * * @param array $tips * A list of tips which provide either a "data-id" or "data-class". + * @param bool $expectEmpty + * Whether or not the field is expected to be Empty. */ - public function assertTourTips($tips = []) { + public function assertTourTips(array $tips = [], bool $expectEmpty = FALSE) { // Get the rendered tips and their data-id and data-class attributes. if (empty($tips)) { // Tips are rendered as drupalSettings values. @@ -43,29 +45,33 @@ abstract class TourTestBase extends BrowserTestBase { } } - // If the tips are still empty we need to fail. - if (empty($tips)) { - $this->fail('Could not find tour tips on the current page.'); + $tip_count = count($tips); + if ($tip_count === 0 && $expectEmpty) { + // No tips found as expected. + return; } - else { - // Check for corresponding page elements. - $total = 0; - $modals = 0; - foreach ($tips as $tip) { - if (!empty($tip['data-id'])) { - $elements = $this->getSession()->getPage()->findAll('css', '#' . $tip['data-id']); - $this->assertCount(1, $elements, new FormattableMarkup('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); - } - elseif (!empty($tip['data-class'])) { - $elements = $this->getSession()->getPage()->findAll('css', '.' . $tip['data-class']); - $this->assertNotEmpty($elements, sprintf("Page element for tour tip with class .%s should be present", $tip['data-class'])); - } - else { - // It's a modal. - $modals++; - } - $total++; + if ($tip_count > 0 && $expectEmpty) { + $this->fail(sprintf('No tips were expected but %d were found', $tip_count)); + } + $this->assertGreaterThan(0, $tip_count); + + // Check for corresponding page elements. + $total = 0; + $modals = 0; + foreach ($tips as $tip) { + if (!empty($tip['data-id'])) { + $elements = $this->getSession()->getPage()->findAll('css', '#' . $tip['data-id']); + $this->assertCount(1, $elements, new FormattableMarkup('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); } + elseif (!empty($tip['data-class'])) { + $elements = $this->getSession()->getPage()->findAll('css', '.' . $tip['data-class']); + $this->assertNotEmpty($elements, sprintf("Page element for tour tip with class .%s should be present", $tip['data-class'])); + } + else { + // It's a modal. + $modals++; + } + $total++; } } diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module index e6bbd2ae63a..3d9432654b4 100644 --- a/core/modules/tour/tour.module +++ b/core/modules/tour/tour.module @@ -85,6 +85,7 @@ function tour_page_bottom(array &$page_bottom) { $results = \Drupal::entityQuery('tour') ->condition('routes.*.route_name', $route_name) + ->condition('status', TRUE) ->execute(); if (!empty($results) && $tours = Tour::loadMultiple(array_keys($results))) { foreach ($tours as $id => $tour) {