You are here

public function ConfigTest::testSafeStringHandling in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 536
Contains \Drupal\Tests\Core\Config\ConfigTest.

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'));
}