You are here

public function EntityFieldDefaultValueTest::testDefaultValueCallback in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php \Drupal\system\Tests\Entity\EntityFieldDefaultValueTest::testDefaultValueCallback()

Tests custom default value callbacks.

File

core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php, line 61
Contains \Drupal\system\Tests\Entity\EntityFieldDefaultValueTest.

Class

EntityFieldDefaultValueTest
Tests default values for entity fields.

Namespace

Drupal\system\Tests\Entity

Code

public function testDefaultValueCallback() {
  $entity = $this->entityManager
    ->getStorage('entity_test_default_value')
    ->create();

  // The description field has a default value callback for testing, see
  // entity_test_field_default_value().
  $string = 'description_' . $entity
    ->language()
    ->getId();
  $expected = array(
    array(
      'shape' => "shape:0:{$string}",
      'color' => "color:0:{$string}",
    ),
    array(
      'shape' => "shape:1:{$string}",
      'color' => "color:1:{$string}",
    ),
  );
  $this
    ->assertEqual($entity->description
    ->getValue(), $expected);
}