function ConfigTargetTest::testFormCacheable

Same name 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 \Drupal\Core\Form\ConfigTarget @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.