public function EntityUpdateFunctionsTest::testEntityUpdateBasicForce in Entity Update 8
Entity update function : basic --force.
File
- modules/
entity_update_tests/ src/ Tests/ EntityUpdateFunctionsTest.php, line 124
Class
- EntityUpdateFunctionsTest
- Test Entity Update functions.
Namespace
Drupal\entity_update_tests\TestsCode
public function testEntityUpdateBasicForce() {
// Create an entity.
$entity = EntityUpdateTestsContentEntity::create([
'id' => 1,
]);
$entity
->save();
$ids = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
$this
->assertEqual(count($ids), 1, 'Has one entity.');
// Enable the field.
EntityUpdateTestHelper::fieldEnable('name');
EntityUpdateTestHelper::fieldEnable('description');
// Check and Make Update using --force.
$res = EntityUpdate::basicUpdate(TRUE);
$this
->assert($res, 'Entity schema has been updated (Field Add).');
// Disable field 'name'.
EntityUpdateTestHelper::fieldDisable('name');
// Update using --force.
$res = EntityUpdate::basicUpdate(TRUE);
$this
->assert($res, 'Entity schema has been updated (Field Remove).');
// Update entity, add description.
$entity = EntityUpdateTestsContentEntity::load(1);
$entity
->set('description', 'a description');
$entity
->save();
EntityUpdateTestHelper::fieldDisable('description');
// Update using --force (After D8.5 this will update).
$res = EntityUpdate::basicUpdate(TRUE);
$this
->assert($res, 'Entity schema has updated (Uninstall + data).');
}