public function FieldDeletionTest::testDeleteField in Tome 8
@covers \Drupal\tome_sync\Exporter::exportContent
File
- modules/
tome_sync/ tests/ src/ Kernel/ FieldDeletionTest.php, line 36
Class
- FieldDeletionTest
- Tests that exports are updated when fields are deleted.
Namespace
Drupal\Tests\tome_sync\KernelCode
public function testDeleteField() {
/** @var \Drupal\Core\Config\StorageInterface $storage */
$storage = \Drupal::service('tome_sync.storage.content');
$field_config = node_add_body_field(NodeType::load('article'));
node_add_body_field(NodeType::load('page'));
$article = Node::create([
'type' => 'article',
'title' => 'My article',
]);
$article
->save();
$page = Node::create([
'type' => 'page',
'title' => 'My page',
]);
$page
->save();
$data = $storage
->read(TomeSyncHelper::getContentName($article));
$this
->assertArrayHasKey('body', $data);
$data = $storage
->read(TomeSyncHelper::getContentName($page));
$this
->assertArrayHasKey('body', $data);
$field_config
->delete();
$data = $storage
->read(TomeSyncHelper::getContentName($article));
$this
->assertArrayNotHasKey('body', $data);
$data = $storage
->read(TomeSyncHelper::getContentName($page));
$this
->assertArrayHasKey('body', $data);
FieldStorageConfig::loadByName('node', 'body')
->delete();
$data = $storage
->read(TomeSyncHelper::getContentName($page));
$this
->assertArrayNotHasKey('body', $data);
}