function ConfigTargetTest::testFormCacheable

Same name and namespace in other branches
  1. 11.x core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php \Drupal\Tests\Core\Form\ConfigTargetTest::testFormCacheable()

@covers \Drupal\Core\Form\ConfigFormBase::storeConfigKeyToFormElementMap @dataProvider providerTestFormCacheable

File

core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php, line 67

Class

ConfigTargetTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Form%21ConfigTarget.php/class/ConfigTarget/10" title="Represents the mapping of a config property to a form element." class="local">\Drupal\Core\Form\ConfigTarget</a> @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testFormCacheable(bool $expected, ?callable $fromConfig, ?callable $toConfig) : void {
    $form = [
        'test' => [
            '#type' => 'text',
            '#default_value' => 'A test',
            '#config_target' => new ConfigTarget('system.site', 'admin_compact_mode', $fromConfig, $toConfig),
            '#name' => 'test',
            '#array_parents' => [
                'test',
            ],
        ],
    ];
    $test_form = new class ($this->prophesize(ConfigFactoryInterface::class)
        ->reveal(), $this->prophesize(TypedConfigManagerInterface::class)
        ->reveal()) extends ConfigFormBase {
        use RedundantEditableConfigNamesTrait;
        public function getFormId() {
            return 'test';
        }

};
    $form_state = new FormState();
    // Make the form cacheable.
    $form_state->setRequestMethod('POST')
        ->setCached();
    $test_form->storeConfigKeyToFormElementMap($form, $form_state);
    $this->assertSame($expected, $form_state->isCached());
}

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