You are here

public function EntityFieldTest::testBaseFieldNonExistingBaseField in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::testBaseFieldNonExistingBaseField()
  2. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::testBaseFieldNonExistingBaseField()

Tests a base field override on a non-existing base field.

See also

entity_test_entity_base_field_info_alter()

File

core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php, line 636

Class

EntityFieldTest
Tests the Entity Field API.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testBaseFieldNonExistingBaseField() {
  $this->entityTypeManager
    ->getStorage('node_type')
    ->create([
    'type' => 'page',
    'name' => 'page',
  ])
    ->save();
  \Drupal::service('entity_field.manager')
    ->clearCachedFieldDefinitions();
  $fields = \Drupal::service('entity_field.manager')
    ->getFieldDefinitions('node', 'page');
  $override = $fields['status']
    ->getConfig('page');
  $override
    ->setLabel($this
    ->randomString())
    ->save();
  \Drupal::state()
    ->set('entity_test.node_remove_status_field', TRUE);
  \Drupal::service('entity_field.manager')
    ->clearCachedFieldDefinitions();
  $fields = \Drupal::service('entity_field.manager')
    ->getFieldDefinitions('node', 'page');

  // A base field override on a non-existing base field should not cause a
  // field definition to come into existence.
  $this
    ->assertFalse(isset($fields['status']), 'Node\'s status base field does not exist.');
}