EntityUpdateProgUpTest.php in Entity Update 8
File
modules/entity_update_tests/src/Tests/EntityUpdateProgUpTest.php
View source
<?php
namespace Drupal\entity_update_tests\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\entity_update\EntityUpdate;
use Drupal\entity_update_tests\EntityUpdateTestHelper;
use Drupal\entity_update_tests\Entity\EntityUpdateTestsContentEntity;
class EntityUpdateProgUpTest extends WebTestBase {
public static $modules = [
'entity_update',
'entity_update_tests',
];
protected function setUp() {
parent::setUp();
EntityUpdateTestHelper::fieldDisable('name');
EntityUpdateTestHelper::fieldEnable('description');
EntityUpdateTestHelper::fieldSetType('type', NULL);
EntityUpdate::basicUpdate();
EntityUpdateTestsContentEntity::create([
'id' => 1,
])
->save();
}
public function testProgUpdateAddFields() {
EntityUpdateTestHelper::fieldEnable('name');
$ids_old = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
if ($res = EntityUpdate::safeUpdateMain()) {
}
else {
}
$this
->assert($res, 'Entity schema has been updated successfully.');
$ids_new = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
$result = array_diff($ids_old, $ids_new);
if ($res = empty($result)) {
}
else {
}
$this
->assert($res, 'Entity schema has been updated successfully.');
}
public function testProgUpdateRemoveFields() {
EntityUpdateTestHelper::fieldDisable('description');
$ids_old = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
if ($res = EntityUpdate::safeUpdateMain()) {
}
else {
}
$this
->assert($res, 'Entity schema has been updated successfully.');
$ids_new = \Drupal::entityQuery('entity_update_tests_cnt')
->execute();
$result = array_diff($ids_old, $ids_new);
if ($res = empty($result)) {
EntityUpdate::cleanupEntityBackup();
}
else {
}
$this
->assert($res, 'Entity schema has been updated successfully.');
}
}