Issue #3004897 by clemens.tolboom, smustgrave, ridhimaabrol24, pooja saraah, ameymudras, ranjith_kumar_k_u, danielgry, larowlan, quietone: Respect tour status (disabled | enabled)

merge-requests/4168/head
Lee Rowlands 2023-06-13 07:00:35 +10:00
parent d2398cc3e7
commit 23fc2b6c35
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
3 changed files with 56 additions and 22 deletions

View File

@ -234,6 +234,33 @@ class TourTest extends TourTestBasic {
$this->assertCount(0, $elements, 'Did not find English variant of tip 1.'); $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. * Gets tour tips from the JavaScript drupalSettings variable.
* *

View File

@ -28,8 +28,10 @@ abstract class TourTestBase extends BrowserTestBase {
* *
* @param array $tips * @param array $tips
* A list of tips which provide either a "data-id" or "data-class". * 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. // Get the rendered tips and their data-id and data-class attributes.
if (empty($tips)) { if (empty($tips)) {
// Tips are rendered as drupalSettings values. // 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. $tip_count = count($tips);
if (empty($tips)) { if ($tip_count === 0 && $expectEmpty) {
$this->fail('Could not find tour tips on the current page.'); // No tips found as expected.
return;
} }
else { if ($tip_count > 0 && $expectEmpty) {
// Check for corresponding page elements. $this->fail(sprintf('No tips were expected but %d were found', $tip_count));
$total = 0; }
$modals = 0; $this->assertGreaterThan(0, $tip_count);
foreach ($tips as $tip) {
if (!empty($tip['data-id'])) { // Check for corresponding page elements.
$elements = $this->getSession()->getPage()->findAll('css', '#' . $tip['data-id']); $total = 0;
$this->assertCount(1, $elements, new FormattableMarkup('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']])); $modals = 0;
} foreach ($tips as $tip) {
elseif (!empty($tip['data-class'])) { if (!empty($tip['data-id'])) {
$elements = $this->getSession()->getPage()->findAll('css', '.' . $tip['data-class']); $elements = $this->getSession()->getPage()->findAll('css', '#' . $tip['data-id']);
$this->assertNotEmpty($elements, sprintf("Page element for tour tip with class .%s should be present", $tip['data-class'])); $this->assertCount(1, $elements, new FormattableMarkup('Found corresponding page element for tour tip with id #%data-id', ['%data-id' => $tip['data-id']]));
}
else {
// It's a modal.
$modals++;
}
$total++;
} }
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++;
} }
} }

View File

@ -85,6 +85,7 @@ function tour_page_bottom(array &$page_bottom) {
$results = \Drupal::entityQuery('tour') $results = \Drupal::entityQuery('tour')
->condition('routes.*.route_name', $route_name) ->condition('routes.*.route_name', $route_name)
->condition('status', TRUE)
->execute(); ->execute();
if (!empty($results) && $tours = Tour::loadMultiple(array_keys($results))) { if (!empty($results) && $tours = Tour::loadMultiple(array_keys($results))) {
foreach ($tours as $id => $tour) { foreach ($tours as $id => $tour) {