public function FarmEntityBundleFieldTest::testBundleFieldPostponedInstall in farmOS 2.x
Test installing the farm_entity_contrib_test module after farm_entity_test.
File
- modules/
core/ entity/ tests/ src/ Functional/ FarmEntityBundleFieldTest.php, line 65
Class
- FarmEntityBundleFieldTest
- Tests that bundle fields are created during a postponed install.
Namespace
Drupal\Tests\farm_entity\FunctionalCode
public function testBundleFieldPostponedInstall() {
// Install the farm_entity_contrib_test module.
$result = $this->moduleInstaller
->install([
'farm_entity_contrib_test',
], TRUE);
$this
->assertTrue($result);
// Must clear the cache for the test environment.
$this->entityFieldManager
->clearCachedFieldDefinitions();
// Test bundle field definition exists.
$fields = $this->entityFieldManager
->getFieldDefinitions('log', 'test');
$this
->assertArrayHasKey('test_contrib_hook_bundle_field', $fields);
// Test log field storage definition exists.
$this
->assertFieldStorageDefinitionExists('log', 'test_contrib_hook_bundle_field');
// Save the contrib field storage definition for later.
$installed_contrib_field_storage_definition = $this->entityFieldManager
->getFieldStorageDefinitions('log')['test_contrib_hook_bundle_field'];
// Uninstall the farm_entity_contrib_test module.
$result = $this->moduleInstaller
->uninstall([
'farm_entity_contrib_test',
]);
$this
->assertTrue($result);
// Must clear the cache for the test environment.
$this->entityFieldManager
->clearCachedFieldDefinitions();
// Test bundle field definition is deleted.
$fields = $this->entityFieldManager
->getFieldDefinitions('log', 'test');
$this
->assertArrayNotHasKey('test_contrib_hook_bundle_field', $fields);
// Test log field storage definition is deleted.
$this
->assertFieldStorageDefinitionExists('log', 'test_contrib_hook_bundle_field', FALSE);
// Ensure the database table was deleted.
/** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
$table_mapping = $this->entityTypeManager
->getStorage('log')
->getTableMapping();
$table = $table_mapping
->getDedicatedDataTableName($installed_contrib_field_storage_definition);
$this
->assertFalse($this->database
->schema()
->tableExists($table));
}