You are here

public function JsonTest::testEncodingStartEnd in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Serialization/JsonTest.php \Drupal\Tests\Component\Serialization\JsonTest::testEncodingStartEnd()

Tests end and start of the encoded string.

File

core/tests/Drupal/Tests/Component/Serialization/JsonTest.php, line 84
Contains \Drupal\Tests\Component\Serialization\JsonTest.

Class

JsonTest
@coversDefaultClass \Drupal\Component\Serialization\Json @group Serialization

Namespace

Drupal\Tests\Component\Serialization

Code

public function testEncodingStartEnd() {
  $json = Json::encode($this->string);

  // The first and last characters should be ", and no others.
  $this
    ->assertTrue($json[0] == '"', 'A JSON encoded string begins with ".');
  $this
    ->assertTrue($json[strlen($json) - 1] == '"', 'A JSON encoded string ends with ".');
  $this
    ->assertTrue(substr_count($json, '"') == 2, 'A JSON encoded string contains exactly two ".');
}