You are here

public function EntityFieldTest::testFieldOverrideBundleField in Zircon Profile 8

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

Tests creating a field override config for a bundle field.

See also

entity_test_entity_base_field_info_alter()

File

core/modules/system/src/Tests/Entity/EntityFieldTest.php, line 632
Contains \Drupal\system\Tests\Entity\EntityFieldTest.

Class

EntityFieldTest
Tests the Entity Field API.

Namespace

Drupal\system\Tests\Entity

Code

public function testFieldOverrideBundleField() {

  // First make sure the bundle field override in code, which is provided by
  // the test entity works.
  entity_test_create_bundle('some_test_bundle', 'Some test bundle', 'entity_test_field_override');
  $field_definitions = $this->entityManager
    ->getFieldDefinitions('entity_test_field_override', 'entity_test_field_override');
  $this
    ->assertEqual($field_definitions['name']
    ->getDescription(), 'The default description.');
  $this
    ->assertNull($field_definitions['name']
    ->getTargetBundle());
  $field_definitions = $this->entityManager
    ->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
  $this
    ->assertEqual($field_definitions['name']
    ->getDescription(), 'Custom description.');
  $this
    ->assertEqual($field_definitions['name']
    ->getTargetBundle(), 'some_test_bundle');

  // Now create a config override of the bundle field.
  $field_config = $field_definitions['name']
    ->getConfig('some_test_bundle');
  $field_config
    ->setTranslatable(FALSE);
  $field_config
    ->save();

  // Make sure both overrides are present.
  $this->entityManager
    ->clearCachedFieldDefinitions();
  $field_definitions = $this->entityManager
    ->getFieldDefinitions('entity_test_field_override', 'some_test_bundle');
  $this
    ->assertEqual($field_definitions['name']
    ->getDescription(), 'Custom description.');
  $this
    ->assertEqual($field_definitions['name']
    ->getTargetBundle(), 'some_test_bundle');
  $this
    ->assertFalse($field_definitions['name']
    ->isTranslatable());
}