WebformCardsProgressJavaScriptTest.php in Webform 8.5
File
modules/webform_cards/tests/src/FunctionalJavaScript/WebformCardsProgressJavaScriptTest.php
View source
<?php
namespace Drupal\Tests\webform_cards\FunctionalJavaScript;
use Drupal\webform\Entity\Webform;
use Drupal\Tests\webform\FunctionalJavascript\WebformWebDriverTestBase;
class WebformCardsProgressJavaScriptTest extends WebformWebDriverTestBase {
public static $modules = [
'webform',
'webform_cards',
'webform_cards_test',
];
public function testProgress() {
$session = $this
->getSession();
$page = $session
->getPage();
$assert_session = $this
->assertSession();
$webform = Webform::load('test_cards_progress');
$this
->drupalGet('/webform/test_cards_progress');
$this
->assertCssSelect('#edit-cards-prev');
$this
->assertCssSelect('#edit-cards-next');
$this
->assertCssSelect('#edit-preview-next');
$this
->assertCssSelect('#edit-submit');
$assert_session
->waitForElement('css', '.webform-card--active[data-webform-key="card_1"]');
$this
->assertElementNotVisible('#edit-cards-prev');
$this
->assertElementVisible('#edit-cards-next');
$this
->assertElementNotVisible('#edit-preview-next');
$this
->assertElementNotVisible('#edit-submit');
$page
->pressButton('edit-cards-next');
$assert_session
->waitForElement('css', '.webform-card--active[data-webform-key="card_2"]');
$assert_session
->waitForElementVisible('css', '#edit-cards-prev');
$this
->assertElementVisible('#edit-cards-prev');
$this
->assertElementNotVisible('#edit-cards-next');
$this
->assertElementVisible('#edit-preview-next');
$this
->assertElementVisible('#edit-submit');
$page
->pressButton('edit-preview-next');
$this
->assertCssSelect('.webform-preview');
$this
->assertElementVisible('#edit-preview-prev');
$this
->assertElementVisible('#edit-submit');
$webform
->setSetting('wizard_track', 'name')
->save();
$this
->drupalGet('/webform/test_cards_progress');
$this
->assertQuery('page=card_1');
$page
->pressButton('edit-cards-next');
$this
->assertQuery('page=card_2');
$page
->pressButton('edit-cards-prev');
$this
->assertQuery('page=card_1');
$this
->drupalGet('/webform/test_cards_progress', [
'query' => [
'custom_param' => '1',
],
]);
$this
->assertQuery('custom_param=1&page=card_1');
$page
->pressButton('edit-cards-next');
$this
->assertQuery('custom_param=1&page=card_2');
$page
->pressButton('edit-cards-prev');
$this
->assertQuery('custom_param=1&page=card_1');
$page
->pressButton('edit-cards-next');
$this
->assertQuery('custom_param=1&page=card_2');
$page
->pressButton('edit-preview-next');
$this
->assertQuery('custom_param=1&page=webform_preview');
$this
->drupalGet('/webform/test_cards_progress');
$assert_session
->pageTextNotContains('Complete');
$webform
->setSetting('wizard_confirmation', TRUE)
->save();
$this
->drupalGet('/webform/test_cards_progress');
$assert_session
->pageTextContains('Complete');
$webform
->setSetting('wizard_confirmation_label', 'Done')
->save();
$this
->drupalGet('/webform/test_cards_progress');
$assert_session
->pageTextNotContains('Complete');
$assert_session
->pageTextContains('Done');
$this
->drupalGet('/webform/test_cards_progress_links');
$assert_session
->waitForElement('css', '#edit-element-1');
$this
->assertNoCssSelect('[data-webform-card="card_1"] .progress-marker[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_1"] .progress-title[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_2"] .progress-marker[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_2"] .progress-title[role="link"]');
$this
->assertCssSelect('.progress-step.is-active[data-webform-card="card_1"]');
$assert_session
->waitForElement('css', '.webform-card--active[data-webform-key="card_1"]');
$page
->pressButton('edit-cards-next');
$assert_session
->waitForElement('css', '#edit-element-2');
$assert_session
->waitForElement('css', '.webform-card--active[data-webform-key="card_2"]');
$assert_session
->waitForElementVisible('css', '#edit-cards-prev');
$this
->assertCssSelect('[data-webform-card="card_1"] .progress-marker[role="link"]');
$this
->assertCssSelect('[data-webform-card="card_1"] .progress-title[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_2"] .progress-marker[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_2"] .progress-title[role="link"]');
$this
->assertCssSelect('.progress-step.is-complete[data-webform-card="card_1"]');
$this
->assertCssSelect('.progress-step.is-active[data-webform-card="card_2"]');
$page
->pressButton('edit-preview-next');
$assert_session
->waitForElement('css', '.webform-preview');
$assert_session
->waitForElement('css', 'input[type="submit"]#edit-webform-start-card_1');
$this
->assertCssSelect('[data-webform-card="card_1"] .progress-marker[role="link"]');
$this
->assertCssSelect('[data-webform-card="card_1"] .progress-title[role="link"]');
$this
->assertCssSelect('[data-webform-card="card_2"] .progress-marker[role="link"]');
$this
->assertCssSelect('[data-webform-card="card_2"] .progress-title[role="link"]');
$this
->assertNoCssSelect('[data-webform-page="webform_preview"] .progress-marker[role="link"]');
$this
->assertNoCssSelect('[data-webform-page="webform_preview"] .progress-title[role="link"]');
$this
->assertCssSelect('.progress-step.is-active[data-webform-page="webform_preview"]');
$this
->assertCssSelect('input[type="submit"]#edit-webform-start-card_1');
$this
->assertCssSelect('input[type="submit"]#edit-webform-start-card_2');
$page
->pressButton('edit-webform-start-card_1');
$assert_session
->waitForElement('css', '#edit-element-1');
$this
->assertNoCssSelect('[data-webform-card="card_1"] .progress-marker[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_1"] .progress-title[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_2"] .progress-marker[role="link"]');
$this
->assertNoCssSelect('[data-webform-card="card_2"] .progress-title[role="link"]');
$this
->assertCssSelect('.progress-step.is-active[data-webform-card="card_1"]');
}
protected function assertQuery($expected_query = '') {
$actual_query = parse_url($this
->getSession()
->getCurrentUrl(), PHP_URL_QUERY) ?: '';
$this
->assertEquals($expected_query, $actual_query);
}
}