public function UpdateTest::testUpdate8200 in Entity Legal 4.0.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/UpdateTest.php \Drupal\Tests\entity_legal\Functional\UpdateTest::testUpdate8200()
- 3.0.x tests/src/Functional/UpdateTest.php \Drupal\Tests\entity_legal\Functional\UpdateTest::testUpdate8200()
Tests entity_legal_update_8200().
See also
File
- tests/
src/ Functional/ UpdateTest.php, line 38
Class
- UpdateTest
- Tests update scripts.
Namespace
Drupal\Tests\entity_legal\FunctionalCode
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');
// Check that the 'published_version' property exists.
$this
->assertNotNull($published_version);
// Check that the 'published_version' property has the proper pattern.
$this
->assertStringStartsWith($id . '_', $published_version);
// Save the values for later checks.
$published_versions[$id] = $published_version;
}
// Check that the 'published' field doesn't exist yet.
$field_exist = \Drupal::database()
->schema()
->fieldExists('entity_legal_document_version_data', 'published');
$this
->assertFalse($field_exist);
// Run updates.
$this
->runUpdates();
/** @var \Drupal\entity_legal\EntityLegalDocumentInterface $document */
foreach (EntityLegalDocument::loadMultiple() as $document) {
// Check that the 'published_version' has been removed.
$this
->assertArrayNotHasKey('published_version', $document
->toArray());
// Check that the published version value was been correctly transferred.
$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) {
// Check the new 'published' field on each legal document version.
$this
->assertEquals(in_array($id, $published_versions), $document_version
->isPublished());
}
}
}