public function EntityUpdateToPublishableTest::testConvertToPublishable in Drupal 8
Tests the conversion of an entity type to be publishable.
See also
entity_test_update_update_8400()
File
- core/
modules/ system/ tests/ src/ Functional/ Update/ EntityUpdateToPublishableTest.php, line 87
Class
- EntityUpdateToPublishableTest
- Tests the upgrade path for making an entity publishable.
Namespace
Drupal\Tests\system\Functional\UpdateCode
public function testConvertToPublishable() {
// Check that entity type is not publishable prior to running the update
// process.
$entity_test_update = $this->lastInstalledSchemaRepository
->getLastInstalledDefinition('entity_test_update');
$this
->assertFalse($entity_test_update
->getKey('published'));
// Make the entity type translatable and publishable.
$this
->updateEntityTypeDefinition();
$this
->enableUpdates('entity_test_update', 'entity_rev_pub_updates', 8400);
$this
->runUpdates();
/** @var \Drupal\Core\Entity\EntityTypeInterface $entity_test_update */
$entity_test_update = $this->lastInstalledSchemaRepository
->getLastInstalledDefinition('entity_test_update');
$this
->assertEquals('status', $entity_test_update
->getKey('published'));
/** @var \Drupal\Core\Entity\Sql\SqlEntityStorageInterface $storage */
$storage = \Drupal::entityTypeManager()
->getStorage('entity_test_update');
$this
->assertCount(102, $storage
->loadMultiple(), 'All test entities were found.');
// The test entity with ID 50 was created before Content Translation was
// enabled, which means it didn't have a 'content_translation_status' field.
// content_translation_update_8400() added values for that field which
// should now be reflected in the entity's 'status' field.
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $storage
->load(50);
$this
->assertEquals(1, $entity->status->value);
$translation = $entity
->getTranslation('ro');
$this
->assertEquals(1, $translation->status->value);
// The test entity with ID 100 was created with Content Translation enabled
// and it should have the same values as entity 50.
$entity = $storage
->load(100);
$this
->assertEquals(1, $entity->status->value);
$translation = $entity
->getTranslation('ro');
$this
->assertEquals(1, $translation->status->value);
// The test entity 101 had 'content_translation_status' set to 0 for the
// English (source) language.
$entity = $storage
->load(101);
$this
->assertEquals(0, $entity->status->value);
$translation = $entity
->getTranslation('ro');
$this
->assertEquals(1, $translation->status->value);
// The test entity 102 had 'content_translation_status' set to 0 for the
// Romanian language.
$entity = $storage
->load(102);
$this
->assertEquals(1, $entity->status->value);
$translation = $entity
->getTranslation('ro');
$this
->assertEquals(0, $translation->status->value);
}