You are here

public function FormsStepsNavigationTest::testNavigation in Forms Steps 8

Test the navigation in steps.

File

tests/src/Functional/FormsStepsNavigationTest.php, line 48

Class

FormsStepsNavigationTest
Class FormsStepsNavigationTest.

Namespace

Drupal\Tests\forms_steps\Functional

Code

public function testNavigation() {

  // TODO: seems that we have a bug in core, new form class not correctly
  // defined coz of cache.
  drupal_flush_all_caches();

  // Access the step 1.
  $this
    ->drupalGet($this->data['forms_steps']['steps'][1]['url']);

  // Check status code.
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->pageTextContains($this->data['forms_steps']['steps'][1]['label']);
  $value = 'This is an article Test Titre content';
  $this
    ->drupalPostForm(NULL, [
    'title[0][value]' => $value,
  ], t('Save'));

  // Access step 2.
  $this
    ->assertSession()
    ->pageTextContains($this->data['forms_steps']['steps'][2]['label']);
  $this
    ->assertStringContainsStringIgnoringCase($this->data['forms_steps']['steps'][2]['url'], $this
    ->getUrl());
  $this
    ->assertSession()
    ->pageTextContains($value);
  $value2 = 'This is an article Test Titre content 2';
  $this
    ->drupalPostForm(NULL, [
    'title[0][value]' => $value2,
  ], t('Save'));

  // Access step 3.
  $this
    ->assertSession()
    ->pageTextContains($this->data['forms_steps']['steps'][3]['label']);
  $this
    ->assertStringContainsStringIgnoringCase($this->data['forms_steps']['steps'][3]['url'], $this
    ->getUrl());
  $value3 = 'This is a page Test Titre content';
  $this
    ->drupalPostForm(NULL, [
    'title[0][value]' => $value3,
  ], t('Save'));

  // Access step 4.
  $this
    ->assertSession()
    ->pageTextContains($this->data['forms_steps']['steps'][4]['label']);
  $this
    ->assertStringContainsStringIgnoringCase($this->data['forms_steps']['steps'][4]['url'], $this
    ->getUrl());
  $this
    ->assertSession()
    ->fieldExists('title[0][value]');
  $this
    ->assertSession()
    ->buttonExists('Previous');
  $this
    ->assertSession()
    ->fieldValueEquals('title[0][value]', $value2);

  // Access step 3.
  $this
    ->drupalPostForm(NULL, [], 'Previous');
  $this
    ->assertSession()
    ->pageTextContains($this->data['forms_steps']['steps'][3]['label']);
  $this
    ->assertSession()
    ->fieldValueEquals('title[0][value]', $value3);

  // Access step 2.
  $this
    ->drupalPostForm(NULL, [], 'Previous');
  $this
    ->assertSession()
    ->pageTextContains($this->data['forms_steps']['steps'][2]['label']);
  $this
    ->assertSession()
    ->fieldValueEquals('title[0][value]', $value2);

  // Access step 1.
  $this
    ->drupalPostForm(NULL, [], 'Previous');
  $this
    ->assertSession()
    ->pageTextContains($this->data['forms_steps']['steps'][1]['label']);
  $this
    ->assertSession()
    ->fieldValueEquals('title[0][value]', $value2);
  $this
    ->assertSession()
    ->buttonNotExists('Previous');
}