function EntityFieldTest::testBaseFieldNonExistingBaseField

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::testBaseFieldNonExistingBaseField()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php \Drupal\KernelTests\Core\Entity\EntityFieldTest::testBaseFieldNonExistingBaseField()
  3. 10 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 671

Class

EntityFieldTest
Tests the Entity Field API.

Namespace

Drupal\KernelTests\Core\Entity

Code

public function testBaseFieldNonExistingBaseField() : void {
    $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.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.