function ConfigTest::testSafeStringHandling

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::testSafeStringHandling()
  2. 10 core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::testSafeStringHandling()
  3. 11.x core/tests/Drupal/Tests/Core/Config/ConfigTest.php \Drupal\Tests\Core\Config\ConfigTest::testSafeStringHandling()

@covers ::setData @covers ::set @covers ::initWithData

File

core/tests/Drupal/Tests/Core/Config/ConfigTest.php, line 618

Class

ConfigTest
Tests the Config.

Namespace

Drupal\Tests\Core\Config

Code

public function testSafeStringHandling() {
    // Safe strings are cast when using ::set().
    $safe_string = Markup::create('bar');
    $this->config
        ->set('foo', $safe_string);
    $this->assertSame('bar', $this->config
        ->get('foo'));
    $this->config
        ->set('foo', [
        'bar' => $safe_string,
    ]);
    $this->assertSame('bar', $this->config
        ->get('foo.bar'));
    // Safe strings are cast when using ::setData().
    $this->config
        ->setData([
        'bar' => $safe_string,
    ]);
    $this->assertSame('bar', $this->config
        ->get('bar'));
    // Safe strings are not cast when using ::initWithData().
    $this->config
        ->initWithData([
        'bar' => $safe_string,
    ]);
    $this->assertSame($safe_string, $this->config
        ->get('bar'));
}

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