You are here

public function EntityUpdateFunctionsTest::testEntityUpdateBasicForce in Entity Update 2.0.x

Entity update function : basic --force.

File

tests/src/Functional/EntityUpdateFunctionsTest.php, line 135

Class

EntityUpdateFunctionsTest
Test Entity Update functions.

Namespace

Drupal\Tests\entity_update\Functional

Code

public function testEntityUpdateBasicForce() {

  // Create an entity.
  $entity = EntityUpdateTestsContentEntity::create([
    'id' => 1,
  ]);
  $entity
    ->save();
  $ids = \Drupal::entityQuery('entity_update_tests_cnt')
    ->execute();
  $this
    ->assertEquals(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
    ->assertTrue($res, 'Entity schema has been updated (Field Add).');

  // Disable field 'name'.
  EntityUpdateTestHelper::fieldDisable('name');

  // Update using --force.
  $res = EntityUpdate::basicUpdate(TRUE);
  $this
    ->assertTrue($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
    ->assertTrue($res, 'Entity schema has updated (Uninstall + data).');
}