public function EntityUpdateFunctionsTest::testEntityUpdateAdvanced in Entity Update 8
Entity advanced update simulation.
File
- modules/
entity_update_tests/ src/ Tests/ EntityUpdateFunctionsTest.php, line 270
Class
- EntityUpdateFunctionsTest
- Test Entity Update functions.
Namespace
Drupal\entity_update_tests\TestsCode
public function testEntityUpdateAdvanced() {
/* TODO : Review this test */
// Enable the field.
EntityUpdateTestHelper::fieldEnable('name');
EntityUpdateTestHelper::fieldEnable('description');
// Update entity type.
$res = EntityUpdate::basicUpdate();
$this
->assert($res, 'Entity schema has been updated (Field Add).');
// Create an entity.
$data = [
'id' => 1,
'name' => 'name',
'description' => 'description',
];
$entity = EntityUpdateTestsContentEntity::create($data);
$entity
->save();
$ids = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
$this
->assertEqual(count($ids), 1, 'Has one entity.');
// Disable field 'name'.
EntityUpdateTestHelper::fieldDisable('name');
// Try update without --force.
$res = EntityUpdate::basicUpdate();
$this
->assert(!$res, 'Entity schema is NOT updated (Uninstall + data).');
// Try update using --force (After D8.5 this will update).
$res = EntityUpdate::basicUpdate(TRUE);
$this
->assert($res, 'Entity schema is updated (Uninstall + data).');
// Simulate advanced update. Re enable field.
EntityUpdateTestHelper::fieldEnable('name');
$res = EntityUpdate::basicUpdate(TRUE);
$this
->assert($res, 'Entity schema is updated by advanced (Uninstall + data).');
// Cleanup backup DB.
$res = EntityUpdate::cleanupEntityBackup();
// Copy to backup DB.
$type = 'entity_update_tests_cnt';
$res = EntityUpdate::entityUpdateDataBackupDel(EntityUpdate::getEntityTypesToUpdate($type), $type);
$this
->assert($res, 'Entity data backup.');
// Update codes (Disable field).
EntityUpdateTestHelper::fieldDisable('name');
// Update entity types.
$res = EntityUpdate::basicUpdate();
$this
->assert($res, 'Entity schema has updated (without data).');
// Restore from backup DB.
$res = EntityUpdate::entityUpdateDataRestore();
$this
->assert($res, 'Entity data Restore.');
// Count entities.
$ids = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
$this
->assertEqual(count($ids), 1, 'Has one entity.');
// Cleanup backup DB.
$res = EntityUpdate::cleanupEntityBackup();
}