function ConfigActionTest::testSimpleConfigUpdate

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Config/Action/ConfigActionTest.php \Drupal\KernelTests\Core\Config\Action\ConfigActionTest::testSimpleConfigUpdate()

See also

\Drupal\Core\Config\Action\Plugin\ConfigAction\SimpleConfigUpdate

File

core/tests/Drupal/KernelTests/Core/Config/Action/ConfigActionTest.php, line 240

Class

ConfigActionTest
Tests the config action system.

Namespace

Drupal\KernelTests\Core\Config\Action

Code

public function testSimpleConfigUpdate() : void {
    $this->installConfig('config_test');
    $this->assertSame('bar', $this->config('config_test.system')
        ->get('foo'));
    
    /** @var \Drupal\Core\Config\Action\ConfigActionManager $manager */
    $manager = $this->container
        ->get('plugin.manager.config_action');
    // Call the simple config update action.
    $manager->applyAction('simple_config_update', 'config_test.system', [
        'foo' => 'Yay!',
    ]);
    $this->assertSame('Yay!', $this->config('config_test.system')
        ->get('foo'));
    try {
        $manager->applyAction('simple_config_update', 'config_test.system', 'Test');
        $this->fail('Expected exception not thrown');
    } catch (ConfigActionException $e) {
        $this->assertSame('Config config_test.system can not be updated because $value is not an array', $e->getMessage());
    }
    $this->config('config_test.system')
        ->delete();
    try {
        $manager->applyAction('simple_config_update', 'config_test.system', [
            'foo' => 'Yay!',
        ]);
        $this->fail('Expected exception not thrown');
    } catch (ConfigActionException $e) {
        $this->assertSame('Config config_test.system does not exist so can not be updated', $e->getMessage());
    }
}

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