function CToolsWizardTest::testEntityWizard

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

Test wizard entity config update.

File

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

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, 'Next');
    // Submit the first step.
    $edit = [
        'one' => 'The first bit',
    ];
    $this->submitForm($edit, 'Next');
    // Submit the second step.
    $edit = [
        'two' => 'The second bit',
    ];
    $this->submitForm($edit, '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',
    ], 'Next');
    $this->assertSession()
        ->fieldValueEquals('two', 'The second bit');
    $this->submitForm([], '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([], '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');
}