You are here

public function EntityUpdateProgUpTest::testProgUpdateRemoveFields in Entity Update 2.0.x

Entity update : remove fields.

Use this example if you remove fields. See the documentation for more details.

File

tests/src/Functional/EntityUpdateProgUpTest.php, line 95

Class

EntityUpdateProgUpTest
Entity Update module, Update entities programmatically test.

Namespace

Drupal\Tests\entity_update\Functional

Code

public function testProgUpdateRemoveFields() {

  // Disable the test field (Only for this test).
  EntityUpdateTestHelper::fieldDisable('description');

  // Entity checking process : Get current entities list.
  $ids_old = \Drupal::entityQuery('entity_update_tests_cnt')
    ->execute();

  // Make Update Using full methode.
  if ($res = EntityUpdate::safeUpdateMain()) {

    // Your codes if update success.
  }
  else {

    // Your codes if update false.
  }
  $this
    ->assert($res, 'Entity schema has been updated successfully.');

  // Entity checking process : Compare with new list entities list.
  $ids_new = \Drupal::entityQuery('entity_update_tests_cnt')
    ->execute();

  // Compare two lists.
  $result = array_diff($ids_old, $ids_new);
  if ($res = empty($result)) {

    // Your codes if update checking process success.
    EntityUpdate::cleanupEntityBackup();
  }
  else {

    // Your codes if update false.
  }
  $this
    ->assert($res, 'Entity schema has been updated successfully.');
}