function DefaultContentModerationStateRevisionUpdateTest::assertCompositeEntityMatchesDefaultRevisionId

Assert for the given entity, the default revision ID matches.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to use for the assertion.

1 call to DefaultContentModerationStateRevisionUpdateTest::assertCompositeEntityMatchesDefaultRevisionId()
DefaultContentModerationStateRevisionUpdateTest::testUpdateDefaultRevision in core/modules/content_moderation/tests/src/Functional/Update/DefaultContentModerationStateRevisionUpdateTest.php
Test updating the default revision.

File

core/modules/content_moderation/tests/src/Functional/Update/DefaultContentModerationStateRevisionUpdateTest.php, line 67

Class

DefaultContentModerationStateRevisionUpdateTest
Test updating the ContentModerationState entity default revisions.

Namespace

Drupal\Tests\content_moderation\Functional\Update

Code

protected function assertCompositeEntityMatchesDefaultRevisionId(ContentEntityInterface $entity) {
    $entity_type_manager = $this->container
        ->get('entity_type.manager');
    $entity_list = $entity_type_manager->getStorage('content_moderation_state')
        ->loadByProperties([
        'content_entity_type_id' => $entity->getEntityTypeId(),
        'content_entity_id' => $entity->id(),
    ]);
    $content_moderation_state_entity = array_shift($entity_list);
    $this->assertEquals($entity->getLoadedRevisionId(), $content_moderation_state_entity->content_entity_revision_id->value);
    // Check that the data table records were updated correctly.
    
    /** @var \Drupal\Core\Database\Connection $database */
    $database = $this->container
        ->get('database');
    $query = 'SELECT * FROM {content_moderation_state_field_data} WHERE id = :id';
    $records = $database->query($query, [
        ':id' => $content_moderation_state_entity->id(),
    ])
        ->fetchAllAssoc('langcode');
    foreach ($records as $langcode => $record) {
        
        /** @var \Drupal\Core\Entity\ContentEntityInterface $translation */
        $translation = $content_moderation_state_entity->getTranslation($langcode);
        foreach ((array) $record as $field_name => $value) {
            if ($translation->hasField($field_name)) {
                $items = $translation->get($field_name)
                    ->getValue();
                $this->assertEquals(current($items[0]), $value);
            }
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.