View source
<?php
namespace Drupal\Tests\workspaces\Functional\Update;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
use Drupal\workspaces\Entity\Workspace;
class WorkspacesUpdateTest extends UpdatePathTestBase {
protected static $modules = [
'workspaces',
'workspace_update_test',
];
public function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
__DIR__ . '/../../../../../system/tests/fixtures/update/drupal-8.4.0.bare.standard.php.gz',
__DIR__ . '/../../../fixtures/update/drupal-8.6.0-workspaces_installed.php',
];
}
public function testWorkspaceAssociationRemoval() {
$database = \Drupal::database();
$wa_records = $database
->select('workspace_association')
->countQuery()
->execute()
->fetchField();
$this
->assertEquals(2, $wa_records);
$war_records = $database
->select('workspace_association_revision')
->countQuery()
->execute()
->fetchField();
$this
->assertEquals(3, $war_records);
$this
->assertNull(\Drupal::entityDefinitionUpdateManager()
->getFieldStorageDefinition('workspace', 'node'));
$this
->runUpdates();
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
$this
->assertTrue($entity_definition_update_manager
->getFieldStorageDefinition('workspace', 'node'));
$this
->assertTrue($entity_definition_update_manager
->getFieldStorageDefinition('workspace', 'taxonomy_term'));
$this
->assertTrue($entity_definition_update_manager
->getFieldStorageDefinition('workspace', 'path_alias'));
$schema = $database
->schema();
$this
->assertTrue($schema
->fieldExists('node_revision', 'workspace'));
$this
->assertFalse($schema
->fieldExists('node', 'workspace'));
$this
->assertFalse($schema
->fieldExists('node_field_data', 'workspace'));
$this
->assertFalse($schema
->fieldExists('node_field_revision', 'workspace'));
$wa_records = $database
->select('workspace_association')
->fields('workspace_association')
->execute()
->fetchAll(\PDO::FETCH_ASSOC);
$expected = [
[
'workspace' => 'stage',
'target_entity_type_id' => 'node',
'target_entity_id' => '1',
'target_entity_revision_id' => '2',
],
[
'workspace' => 'dev',
'target_entity_type_id' => 'node',
'target_entity_id' => '8',
'target_entity_revision_id' => '10',
],
];
$this
->assertEquals($expected, $wa_records);
$revisions = \Drupal::entityTypeManager()
->getStorage('node')
->loadMultipleRevisions([
2,
9,
10,
]);
$this
->assertEquals('stage', $revisions[2]->workspace->target_id);
$this
->assertEquals('dev', $revisions[9]->workspace->target_id);
$this
->assertEquals('dev', $revisions[10]->workspace->target_id);
$this
->assertNull($entity_definition_update_manager
->getEntityType('workspace_association'));
$this
->assertNull($entity_definition_update_manager
->getFieldStorageDefinition('id', 'workspace_association'));
$this
->assertNull(\Drupal::keyValue('entity.storage_schema.sql')
->get('workspace_association.entity_schema_data'));
$this
->assertFalse($schema
->tableExists('workspace_association_revision'));
}
public function testWorkspaceParentField() {
$this
->runUpdates();
$this
->assertNotEmpty(\Drupal::entityDefinitionUpdateManager()
->getFieldStorageDefinition('parent', 'workspace'));
$stage = Workspace::load('stage');
$this
->assertTrue($stage
->hasField('parent'));
$this
->assertTrue($stage->parent
->isEmpty());
$form_display = EntityFormDisplay::load('workspace.workspace.deploy');
$this
->assertNull($form_display
->getComponent('parent'));
}
protected function replaceUser1() {
}
}