View source
<?php
namespace Drupal\Tests\tour\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class TourJavascriptTest extends WebDriverTestBase {
protected static $modules = [
'tour',
'tour_test',
'toolbar',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$admin_user = $this
->drupalCreateUser([
'access toolbar',
'access tour',
]);
$this
->drupalLogin($admin_user);
}
public function testQueryArg() {
$assert_session = $this
->assertSession();
$this
->drupalGet('tour-test-1');
$assert_session
->assertNoElementAfterWait('css', '.tip-tour-test-1');
$assert_session
->pageTextContains('Where does the rain in Spain fail?');
$assert_session
->pageTextNotContains('Im all these things');
$assert_session
->pageTextNotContains('The first tip');
$this
->drupalGet('tour-test-1', [
'query' => [
'tips' => 'tip-tour-test-6',
],
]);
$this
->assertNotNull($assert_session
->waitForElementVisible('css', '.tip-tour-test-6'));
$assert_session
->pageTextContains('Im all these things');
$this
->drupalGet('tour-test-1', [
'query' => [
'tour' => '1',
],
]);
$this
->assertNotNull($assert_session
->waitForElementVisible('css', '.tip-tour-test-1'));
$assert_session
->pageTextContains('The first tip');
}
public function testGeneralTourUse() {
$page = $this
->getSession()
->getPage();
$assert_session = $this
->assertSession();
$this
->drupalGet('tour-test-1');
$assert_session
->assertNoElementAfterWait('css', '.tip-tour-test-1');
$page
->find('css', '#toolbar-tab-tour button')
->press();
$tip_to_close = $assert_session
->waitForElementVisible('css', '.shepherd-enabled.tip-tour-test-1');
$this
->assertNotNull($tip_to_close);
$tip_text = $tip_to_close
->getText();
$this
->assertStringContainsString('always the best dressed', $tip_text);
$this
->assertStringContainsString('1 of 3', $tip_text);
$this
->assertStringNotContainsString('End tour', $tip_text);
$tip_to_close
->find('css', '.shepherd-cancel-icon')
->press();
$assert_session
->assertNoElementAfterWait('css', '.tip-tour-test-1');
$assert_session
->assertNoElementAfterWait('css', '.shepherd-enabled');
$page
->find('css', '#toolbar-tab-tour button')
->press();
$tip1 = $assert_session
->waitForElementVisible('css', '.shepherd-enabled.tip-tour-test-1');
$this
->assertNotNull($tip1);
$tip1
->find('css', '.button--primary:contains("Next")')
->press();
$tip2 = $assert_session
->waitForElementVisible('css', '.shepherd-enabled.tip-tour-test-3');
$assert_session
->pageTextNotContains('always the best dressed');
$tip_text = $tip2
->getText();
$this
->assertStringContainsString('The awesome image', $tip_text);
$this
->assertStringContainsString('2 of 3', $tip_text);
$this
->assertStringNotContainsString('End tour', $tip_text);
$tip2
->find('css', '.button--primary:contains("Next")')
->press();
$tip3 = $assert_session
->waitForElementVisible('css', '.shepherd-enabled.tip-tour-test-6');
$assert_session
->pageTextNotContains('The awesome image');
$tip_text = $tip3
->getText();
$this
->assertStringContainsString('Im all these things', $tip_text);
$this
->assertStringContainsString('3 of 3', $tip_text);
$this
->assertStringNotContainsString('Next', $tip_text);
$tip3
->find('css', '.button--primary:contains("End tour")')
->press();
$assert_session
->assertNoElementAfterWait('css', '.shepherd-enabled');
$assert_session
->pageTextNotContains('The awesome image');
}
}