function ConfigTargetTest::testTree

Same name in this branch
  1. 10 core/modules/system/tests/src/Functional/Form/ConfigTargetTest.php \Drupal\Tests\system\Functional\Form\ConfigTargetTest::testTree()
Same name in other branches
  1. 11.x core/modules/system/tests/src/FunctionalJavascript/Form/ConfigTargetTest.php \Drupal\Tests\system\FunctionalJavascript\Form\ConfigTargetTest::testTree()
  2. 11.x core/modules/system/tests/src/Functional/Form/ConfigTargetTest.php \Drupal\Tests\system\Functional\Form\ConfigTargetTest::testTree()

Tests #config_target with no callbacks.

If a #config_target has no callbacks, the form can be cached.

File

core/modules/system/tests/src/FunctionalJavascript/Form/ConfigTargetTest.php, line 31

Class

ConfigTargetTest
Tests forms using #config_target and #ajax together.

Namespace

Drupal\Tests\system\FunctionalJavascript\Form

Code

public function testTree() : void {
    
    /** @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable */
    $key_value_expirable = \Drupal::service('keyvalue.expirable')->get('form');
    $page = $this->getSession()
        ->getPage();
    $assert_session = $this->assertSession();
    $this->drupalGet('/form-test/tree-config-target');
    $this->assertCount(0, $key_value_expirable->getAll());
    $page->fillField('Nemesis', 'Test');
    $assert_session->pageTextNotContains('Option 3');
    $page->selectFieldOption('test1', 'Option 2');
    $assert_session->waitForText('Option 3');
    $assert_session->pageTextContains('Option 3');
    // The ajax request should result in the form being cached.
    $this->assertCount(1, $key_value_expirable->getAll());
    $page->pressButton('Save configuration');
    $assert_session->pageTextContains('The configuration options have been saved.');
    $assert_session->fieldValueEquals('Nemesis', 'Test');
    // The form cache will be deleted after submission.
    $this->assertCount(0, $key_value_expirable->getAll());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.