3 namespace Drupal\Tests\node\Kernel;
5 use Drupal\field\Entity\FieldConfig;
6 use Drupal\field\Entity\FieldStorageConfig;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\KernelTests\KernelTestBase;
11 * Tests node body field storage.
15 class NodeBodyFieldStorageTest extends KernelTestBase {
22 public static $modules = ['user', 'system', 'field', 'node', 'text', 'filter'];
24 protected function setUp() {
26 $this->installSchema('system', 'sequences');
27 // Necessary for module uninstall.
28 $this->installSchema('user', 'users_data');
29 $this->installEntitySchema('user');
30 $this->installEntitySchema('node');
31 $this->installConfig(['field', 'node']);
35 * Tests node body field storage persistence even if there are no instances.
37 public function testFieldOverrides() {
38 $field_storage = FieldStorageConfig::loadByName('node', 'body');
39 $this->assertTrue($field_storage, 'Node body field storage exists.');
40 $type = NodeType::create(['name' => 'Ponies', 'type' => 'ponies']);
42 node_add_body_field($type);
43 $field_storage = FieldStorageConfig::loadByName('node', 'body');
44 $this->assertTrue(count($field_storage->getBundles()) == 1, 'Node body field storage is being used on the new node type.');
45 $field = FieldConfig::loadByName('node', 'ponies', 'body');
47 $field_storage = FieldStorageConfig::loadByName('node', 'body');
48 $this->assertTrue(count($field_storage->getBundles()) == 0, 'Node body field storage exists after deleting the only instance of a field.');
49 \Drupal::service('module_installer')->uninstall(['node']);
50 $field_storage = FieldStorageConfig::loadByName('node', 'body');
51 $this->assertFalse($field_storage, 'Node body field storage does not exist after uninstalling the Node module.');