protected function TypedDataTest::createTypedData

Creates a typed data object and executes some basic assertions.

See also

Drupal\Core\TypedData\TypedDataManager::create().

3 calls to TypedDataTest::createTypedData()
TypedDataTest::testGetAndSet in drupal/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
Tests the basics around constructing and working with typed data objects.
TypedDataTest::testTypedDataLists in drupal/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
Tests using typed data lists.
TypedDataTest::testTypedDataMaps in drupal/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
Tests using a typed data map.

File

drupal/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php, line 53
Definition of Drupal\system\Tests\TypedData\TypedDataTest.

Class

TypedDataTest
Tests primitive data types.

Namespace

Drupal\system\Tests\TypedData

Code

protected function createTypedData($definition, $value = NULL, $name = NULL) {

  // Save the type that was passed in so we can compare with it later.
  $type = $definition['type'];

  // Construct the object.
  $data = $this->typedData
    ->create($definition, $value, $name);

  // Assert the definition of the wrapper.
  $this
    ->assertTrue($data instanceof \Drupal\Core\TypedData\TypedDataInterface, 'Typed data object is an instance of the typed data interface.');
  $definition = $data
    ->getDefinition();
  $this
    ->assertTrue(!empty($definition['type']), format_string('!type data definition was returned.', array(
    '!type' => $definition['type'],
  )));

  // Assert that the correct type was constructed.
  $this
    ->assertEqual($data
    ->getType(), $type, format_string('!type object returned type.', array(
    '!type' => $definition['type'],
  )));
  return $data;
}