function TourExampleTest::testTourExample

Same name in other branches
  1. 3.x modules/tour_example/tests/src/Functional/TourExampleTest.php \Drupal\Tests\tour_example\Functional\TourExampleTest::testTourExample()
  2. 8.x-1.x tour_example/tests/src/Functional/TourExampleTest.php \Drupal\Tests\tour_example\Functional\TourExampleTest::testTourExample()

Main test.

Make sure the Tour Example link is on the front page. Make sure all the tour tips exist on the page. Make sure all the corresponding target elements exist for tour tips that have targets.

File

modules/tour_example/tests/src/Functional/TourExampleTest.php, line 54

Class

TourExampleTest
Regression tests for the tour_example module.

Namespace

Drupal\Tests\tour_example\Functional

Code

public function testTourExample() {
    $assert = $this->assertSession();
    // Create a user with the permissions we need in order to display the
    // toolbar and run a tour from it.
    $this->drupalLogin($this->createUser([
        'access content',
        'access toolbar',
        'access tour',
    ]));
    // Test for a link to the tour_example in the Tools menu.
    $this->drupalGet(Url::fromRoute('<front>'));
    $assert->statusCodeEquals(200);
    $assert->linkByHrefExists('examples/tour-example');
    // Verify anonymous user can successfully access the tour_examples page.
    $this->drupalGet(Url::fromRoute('tour_example.description'));
    $assert->statusCodeEquals(200);
    // Get all the tour elements. These are the IDs of each tour tip. See them
    // in config/install/tour.tour.tour-example.yml.
    $tip_ids = [
        'introduction' => '',
        'first-item' => '#tour-target-1',
        'second-item' => '#tour-target-2',
        'third-item' => '#tour-target-3',
        'fourth-item' => '#tour-target-4',
    ];
    // Ensure that we have the right number of buttons.
    // First tip does not have accompanying button, so we have less buttons
    // than tour items.
    $this->assertCount(count($tip_ids) - 1, $this->cssSelect('#button-container .button'));
    // Ensure each item exists.
    foreach ($tip_ids as $tip_id => $tip_selector) {
        if (!$tip_selector) {
            continue;
        }
        $this->assertNotEmpty($this->cssSelect($tip_selector), "Tip id: {$tip_id} {$tip_selector}");
    }
    // Verify that existing tour tips have corresponding target page elements.
    $this->assertTourTips();
}