class TourExampleTest

Same name in other branches
  1. 3.x modules/tour_example/tests/src/Functional/TourExampleTest.php \Drupal\Tests\tour_example\Functional\TourExampleTest
  2. 4.0.x modules/tour_example/tests/src/Functional/TourExampleTest.php \Drupal\Tests\tour_example\Functional\TourExampleTest

Regression tests for the tour_example module.

We use TourTestBasic to get some built-in tour tip testing assertions.

@group tour_example @group examples

Hierarchy

  • class \Drupal\Tests\tour_example\Functional\TourExampleTest extends \Drupal\Tests\tour\Functional\TourTestBasic

Expanded class hierarchy of TourExampleTest

Related topics

File

tour_example/tests/src/Functional/TourExampleTest.php, line 18

Namespace

Drupal\Tests\tour_example\Functional
View source
class TourExampleTest extends TourTestBasic {
    
    /**
     * {@inheritdoc}
     */
    protected $defaultTheme = 'stark';
    
    /**
     * Modules to enable.
     *
     * @var array
     */
    public static $modules = [
        'tour_example',
    ];
    
    /**
     * The installation profile to use with this test.
     *
     * @var string
     */
    protected $profile = 'minimal';
    
    /**
     * 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.
     */
    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',
            'second-item',
            'third-item',
            'fourth-item',
        ];
        // Ensure that we have the same number of tour tips that we expect.
        $this->assertCount(count($tip_ids), $this->xpath("//ol[@id = \"tour\"]//li"));
        // Ensure each item exists.
        foreach ($tip_ids as $tip_id) {
            $this->assertNotEmpty($this->xpath("//ol[@id = \"tour\"]//li[contains(@class, \"tip-{$tip_id}\")]"), "Tip id: {$tip_id}");
        }
        // Verify that existing tour tips have corresponding target page elements.
        $this->assertTourTips();
    }

}

Members

Title Sort descending Modifiers Object type Summary
TourExampleTest::$defaultTheme protected property
TourExampleTest::$modules public static property Modules to enable.
TourExampleTest::$profile protected property The installation profile to use with this test.
TourExampleTest::testTourExample public function Main test.