You are here

public function WebformWizardLinksTest::testWizardLinks in Webform 8.5

Same name and namespace in other branches
  1. 6.x tests/src/Functional/Wizard/WebformWizardLinksTest.php \Drupal\Tests\webform\Functional\Wizard\WebformWizardLinksTest::testWizardLinks()

Test webform wizard progress and preview links.

File

tests/src/Functional/Wizard/WebformWizardLinksTest.php, line 24

Class

WebformWizardLinksTest
Tests for webform wizard progress and preview links.

Namespace

Drupal\Tests\webform\Functional\Wizard

Code

public function testWizardLinks() {
  $this
    ->drupalLogin($this->rootUser);
  $wizard_webform = Webform::load('test_form_wizard_links');

  // Check that first page has no links.
  $this
    ->drupalGet('/webform/test_form_wizard_links');
  $this
    ->assertCssSelect('.webform-wizard-pages-links');
  $this
    ->assertNoFieldByName('webform_wizard_page-page_1', 'Edit');
  $this
    ->assertNoFieldByName('webform_wizard_page-page_2', 'Edit');

  // Check that second page links to first page.
  $this
    ->drupalPostForm('/webform/test_form_wizard_links', [], 'Next >');
  $this
    ->assertCssSelect('.webform-wizard-pages-links');
  $this
    ->assertFieldByName('webform_wizard_page-page_1', 'Edit');
  $this
    ->assertNoFieldByName('webform_wizard_page-page_2', 'Edit');

  // Check that preview links to first and second page.
  $this
    ->drupalPostForm('/webform/test_form_wizard_links', [], 'Preview');
  $this
    ->assertCssSelect('.webform-wizard-pages-links');
  $this
    ->assertFieldByName('webform_wizard_page-page_1', 'Edit');
  $this
    ->assertFieldByName('webform_wizard_page-page_2', 'Edit');

  // Check that preview links are not wrapper in .form-actions.
  $this
    ->assertNoCssSelect('.webform-wizard-pages-links.form-actions');

  // Check 'wizard_progress_link' setting.
  $this
    ->assertCssSelect('.webform-wizard-pages-links[data-wizard-progress-link="true"]');

  // Check 'wizard_preview_link' setting.
  $this
    ->assertCssSelect('.webform-wizard-pages-links[data-wizard-preview-link="true"]');

  // Set preview links to FALSE.
  $wizard_webform
    ->setSetting('wizard_preview_link', FALSE)
    ->save();

  // Check preview page is not linked.
  $this
    ->drupalGet('/webform/test_form_wizard_links');
  $this
    ->assertCssSelect('.webform-wizard-pages-links[data-wizard-progress-link="true"]');
  $this
    ->assertNoCssSelect('.webform-wizard-pages-links[data-wizard-preview-link="true"]');

  // Set progress bar links to FALSE.
  $wizard_webform
    ->setSetting('wizard_progress_link', FALSE)
    ->setSetting('wizard_preview_link', TRUE)
    ->save();

  // Check progress bar is not linked.
  $this
    ->drupalGet('/webform/test_form_wizard_links');
  $this
    ->assertNoCssSelect('.webform-wizard-pages-links[data-wizard-progress-link="true"]');
  $this
    ->assertCssSelect('.webform-wizard-pages-links[data-wizard-preview-link="true"]');

  // Set progress bar links and preview page to FALSE.
  $wizard_webform
    ->setSetting('wizard_progress_link', FALSE)
    ->setSetting('wizard_preview_link', FALSE)
    ->save();
  $this
    ->drupalGet('/webform/test_form_wizard_links');
  $this
    ->assertNoCssSelect('.webform-wizard-pages-links');
}