public function PreviewLinkSessionTokenUpdateTest::testMultipleEntitiesFieldMigration in Preview Link 2.x
Same name and namespace in other branches
- 2.0.x tests/src/Functional/Update/PreviewLinkSessionTokenUpdateTest.php \Drupal\Tests\preview_link\Functional\Update\PreviewLinkSessionTokenUpdateTest::testMultipleEntitiesFieldMigration()
Tests upgrade path to enable DER and migrate data over.
See also
File
- tests/
src/ Functional/ Update/ PreviewLinkSessionTokenUpdateTest.php, line 56
Class
- PreviewLinkSessionTokenUpdateTest
- Tests upgrade path adding Preview Link session functionality.
Namespace
Drupal\Tests\preview_link\Functional\UpdateCode
public function testMultipleEntitiesFieldMigration() : void {
EntityTestMulRevPub::create([
'id' => 2,
])
->save();
$db = \Drupal::database();
$dbSchema = $db
->schema();
$configFactory = \Drupal::configFactory();
// Check that the sms tables exist but the others don't.
$this
->assertTrue($dbSchema
->tableExists('preview_link'));
$this
->assertTrue($dbSchema
->fieldExists('preview_link', 'entity_type_id'));
$this
->assertTrue($dbSchema
->fieldExists('preview_link', 'entity_id'));
$this
->assertEquals('de3a19ee-1edc-4b2e-9af8-f512dddcddcc', $db
->query('SELECT token FROM {preview_link} WHERE id = :id', [
':id' => 1,
])
->fetchField());
$this
->assertNull($configFactory
->get('preview_link.settings')
->get('multiple_entities'));
$definition = \Drupal::entityDefinitionUpdateManager()
->getEntityType('preview_link');
$this
->assertTrue($definition
->hasKey('entity_id'));
$this
->assertTrue($definition
->hasKey('entity_type_id'));
$this
->assertTrue($definition
->hasKey('token'));
$this
->runUpdates();
$this
->assertTrue(\Drupal::moduleHandler()
->moduleExists('dynamic_entity_reference'));
$this
->assertTrue($dbSchema
->tableExists('preview_link'));
$this
->assertTrue($dbSchema
->tableExists('preview_link__entities'));
$this
->assertFalse($dbSchema
->fieldExists('preview_link', 'entity_type_id'));
$this
->assertFalse($dbSchema
->fieldExists('preview_link', 'entity_id'));
$this
->assertFalse($configFactory
->get('preview_link.settings')
->get('multiple_entities'));
$definition = \Drupal::entityTypeManager()
->getDefinition('preview_link');
$this
->assertFalse($definition
->hasKey('entity_id'));
$this
->assertFalse($definition
->hasKey('entity_type_id'));
$this
->assertFalse($definition
->hasKey('token'));
/** @var \Drupal\preview_link\Entity\PreviewLinkInterface[] $previewLinks */
$previewLinks = PreviewLink::loadMultiple();
$this
->assertCount(1, $previewLinks);
$this
->assertEquals('de3a19ee-1edc-4b2e-9af8-f512dddcddcc', $previewLinks[1]
->getToken());
$hostEntities = $previewLinks[1]
->getEntities();
$previewLinkHostEntity = reset($hostEntities);
$this
->assertEquals('entity_test_mulrevpub', $previewLinkHostEntity
->getEntityTypeId());
$this
->assertEquals('2', $previewLinks[1]
->getEntities()[0]
->id());
}