function TourTestBase::assertTourTips
Same name in other branches
- 9 core/modules/tour/tests/src/Functional/TourTestBase.php \Drupal\Tests\tour\Functional\TourTestBase::assertTourTips()
- 8.9.x core/modules/tour/src/Tests/TourTestBase.php \Drupal\tour\Tests\TourTestBase::assertTourTips()
- 8.9.x core/modules/tour/tests/src/Functional/TourTestBase.php \Drupal\Tests\tour\Functional\TourTestBase::assertTourTips()
- 10 core/modules/tour/tests/src/Functional/TourTestBase.php \Drupal\Tests\tour\Functional\TourTestBase::assertTourTips()
Asserts the presence of page elements for tour tips.
// Basic example.
$this->assertTourTips();
// Advanced example. The following would be used for multi-page or
// targeting a specific subset of tips.
$tips = array();
$tips[] = array(
'data-id' => 'foo',
);
$tips[] = array(
'data-id' => 'bar',
);
$tips[] = array(
'data-class' => 'baz',
);
$this->assertTourTips($tips);
Parameters
array $tips: A list of tips which provide either a "data-id" or "data-class".
bool $expectEmpty: Whether or not the field is expected to be Empty.
10 calls to TourTestBase::assertTourTips()
- BlockLayoutTourTest::testBlockLayoutTourTips in core/
modules/ tour/ tests/ src/ Functional/ Block/ BlockLayoutTourTest.php - Tests Block Layout tour tip availability.
- LanguageTourTest::testLanguageAddTour in core/
modules/ tour/ tests/ src/ Functional/ Language/ LanguageTourTest.php - Go to add language page and check the tour tooltips.
- LanguageTourTest::testLanguageEditTour in core/
modules/ tour/ tests/ src/ Functional/ Language/ LanguageTourTest.php - Go to edit language page and check the tour tooltips.
- LanguageTourTest::testLanguageTour in core/
modules/ tour/ tests/ src/ Functional/ Language/ LanguageTourTest.php - Tests language tour tip availability.
- LocaleTranslateStringTourTest::testTranslateStringTourTips in core/
modules/ tour/ tests/ src/ Functional/ Locale/ LocaleTranslateStringTourTest.php - Tests locale tour tip availability.
File
-
core/
modules/ tour/ tests/ src/ Functional/ TourTestBase.php, line 35
Class
- TourTestBase
- Base class for testing Tour functionality.
Namespace
Drupal\Tests\tour\FunctionalCode
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.
$drupalSettings = $this->getDrupalSettings();
if (isset($drupalSettings['_tour_internal'])) {
foreach ($drupalSettings['_tour_internal'] as $tip) {
$tips[] = [
'selector' => $tip['selector'] ?? NULL,
];
}
}
}
$tip_count = count($tips);
if ($tip_count === 0 && $expectEmpty) {
// No tips found as expected.
return;
}
if ($tip_count > 0 && $expectEmpty) {
$this->fail("No tips were expected but {$tip_count} were found");
}
$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, sprintf('Found corresponding page element for tour tip with id #%s', $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++;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.