protected function WebTestBase::createTypedData

Creates a typed data object and executes some basic assertions.

See also

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

1 call to WebTestBase::createTypedData()
TypedDataTest::testGetAndSet in drupal/core/modules/system/lib/Drupal/system/Tests/TypedData/TypedDataTest.php
Tests the basics around constructing and working with data wrappers.

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php, line 2069
Definition of Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

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

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

  // Construct the object.
  $data = typed_data()
    ->create($definition, $value, $context);

  // 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['label']), $definition['label'] . ' data definition was returned.');

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