UpdateTest.php in Entity Legal 3.0.x
File
tests/src/Functional/UpdateTest.php
View source
<?php
namespace Drupal\Tests\entity_legal\Functional;
use Drupal\entity_legal\Entity\EntityLegalDocument;
use Drupal\entity_legal\Entity\EntityLegalDocumentVersion;
use Drupal\FunctionalTests\Update\UpdatePathTestBase;
class UpdateTest extends UpdatePathTestBase {
protected function setDatabaseDumpFiles() {
$this->databaseDumpFiles = [
DRUPAL_ROOT . '/core/modules/system/tests/fixtures/update/drupal-8.6.0.bare.testing.php.gz',
__DIR__ . '/../../fixtures/update/install_entity_legal.php',
__DIR__ . '/../../fixtures/update/legal_documents.php',
__DIR__ . '/../../fixtures/update/update_8200.php',
];
}
public function testUpdate8200() {
$factory = \Drupal::configFactory();
$published_versions = [];
foreach ($factory
->listAll('entity_legal.document.') as $name) {
list(, , $id) = explode('.', $name);
$published_version = $factory
->get($name)
->get('published_version');
$this
->assertNotNull($published_version);
$this
->assertStringStartsWith($id . '_', $published_version);
$published_versions[$id] = $published_version;
}
$field_exist = \Drupal::database()
->schema()
->fieldExists('entity_legal_document_version_data', 'published');
$this
->assertFalse($field_exist);
$this
->runUpdates();
foreach (EntityLegalDocument::loadMultiple() as $document) {
$this
->assertArrayNotHasKey('published_version', $document
->toArray());
$published_version_entity = $document
->getPublishedVersion();
$this
->assertSame($published_versions[$document
->id()], $published_version_entity
->id());
$ids = \Drupal::entityQuery(ENTITY_LEGAL_DOCUMENT_VERSION_ENTITY_NAME)
->condition('document_name', $document
->id())
->execute();
foreach (EntityLegalDocumentVersion::loadMultiple($ids) as $id => $document_version) {
$this
->assertEquals(in_array($id, $published_versions), $document_version
->isPublished());
}
}
}
}