function CToolsWizardTest::testEntityWizard

Same name and namespace in other branches
  1. 8.x-3.x tests/src/Functional/CToolsWizardTest.php \Drupal\Tests\ctools\Functional\CToolsWizardTest::testEntityWizard()

Test wizard entity config update.

File

tests/src/Functional/CToolsWizardTest.php, line 94

Class

CToolsWizardTest
Tests basic wizard functionality.

Namespace

Drupal\Tests\ctools\Functional

Code

public function testEntityWizard() {
  $this->drupalLogin($this->drupalCreateUser([
    'administer site configuration',
  ]));
  // Start adding a new config entity.
  $this->drupalGet('admin/structure/ctools_wizard_test_config_entity/add');
  $this->assertSession()
    ->pageTextContains('Example entity');
  $this->assertSession()
    ->pageTextNotContains('Existing entity');
  // Submit the general step.
  $edit = [
    'id' => 'test123',
    'label' => 'Test Config Entity 123',
  ];
  $this->submitForm($edit, $this->t('Next'));
  // Submit the first step.
  $edit = [
    'one' => 'The first bit',
  ];
  $this->submitForm($edit, $this->t('Next'));
  // Submit the second step.
  $edit = [
    'two' => 'The second bit',
  ];
  $this->submitForm($edit, $this->t('Finish'));
  // Now we should be looking at the list of entities.
  $this->assertSession()
    ->addressEquals('admin/structure/ctools_wizard_test_config_entity');
  $this->assertSession()
    ->pageTextContains('Test Config Entity 123');
  // Edit the entity again and make sure the values are what we expect.
  $this->clickLink($this->t('Edit'));
  $this->assertSession()
    ->pageTextContains('Existing entity');
  $this->assertSession()
    ->fieldValueEquals('label', 'Test Config Entity 123');
  $this->clickLink($this->t('Form One'));
  $this->assertSession()
    ->fieldValueEquals('one', 'The first bit');
  $previous = $this->getUrl();
  $this->clickLink($this->t('Show on dialog'));
  $this->assertSession()
    ->responseContains('Value from one: The first bit');
  $this->drupalGet($previous);
  // Change the value for 'one'.
  $this->submitForm([
    'one' => 'New value',
  ], $this->t('Next'));
  $this->assertSession()
    ->fieldValueEquals('two', 'The second bit');
  $this->submitForm([], $this->t('Next'));
  // Make sure we get the additional step because the entity exists.
  $this->assertSession()
    ->pageTextContains('This step only shows if the entity is already existing!');
  $this->submitForm([], $this->t('Finish'));
  // Edit the entity again and make sure the change stuck.
  $this->assertSession()
    ->addressEquals('admin/structure/ctools_wizard_test_config_entity');
  $this->clickLink($this->t('Edit'));
  $this->clickLink($this->t('Form One'));
  $this->assertSession()
    ->fieldValueEquals('one', 'New value');
}