function ConfigTargetTest::testFromFormConfigTarget

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Core/Form/ConfigTargetTest.php \Drupal\Tests\Core\Form\ConfigTargetTest::testFromFormConfigTarget()

@covers ::fromForm

File

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

Class

ConfigTargetTest
@coversDefaultClass \Drupal\Core\Form\ConfigTarget @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testFromFormConfigTarget() : void {
    $form = [
        'test' => [
            '#type' => 'text',
            '#default_value' => 'A test',
            '#config_target' => new ConfigTarget('system.site', 'admin_compact_mode', 'intval', 'boolval'),
            '#name' => 'test',
            '#parents' => [
                'test',
            ],
        ],
    ];
    $config_target = ConfigTarget::fromForm([
        'test',
    ], $form);
    $this->assertSame('system.site', $config_target->configName);
    $this->assertSame([
        'admin_compact_mode',
    ], $config_target->propertyPaths);
    $this->assertSame([
        'test',
    ], $config_target->elementParents);
    $this->assertSame(1, ($config_target->fromConfig)(TRUE));
    $this->assertFalse(($config_target->toConfig)('0'));
}

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