function ContentModerationStateStorageSchemaTest::assertStorageException

Same name in other branches
  1. 9 core/modules/content_moderation/tests/src/Kernel/ContentModerationStateStorageSchemaTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateStorageSchemaTest::assertStorageException()
  2. 8.9.x core/modules/content_moderation/tests/src/Kernel/ContentModerationStateStorageSchemaTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateStorageSchemaTest::assertStorageException()
  3. 11.x core/modules/content_moderation/tests/src/Kernel/ContentModerationStateStorageSchemaTest.php \Drupal\Tests\content_moderation\Kernel\ContentModerationStateStorageSchemaTest::assertStorageException()

Assert if a storage exception is triggered when saving a given entity.

@internal

Parameters

array $values: An array of entity values.

bool $has_exception: If an exception should be triggered when saving the entity.

1 call to ContentModerationStateStorageSchemaTest::assertStorageException()
ContentModerationStateStorageSchemaTest::testUniqueKeys in core/modules/content_moderation/tests/src/Kernel/ContentModerationStateStorageSchemaTest.php
Tests the ContentModerationState unique keys.

File

core/modules/content_moderation/tests/src/Kernel/ContentModerationStateStorageSchemaTest.php, line 133

Class

ContentModerationStateStorageSchemaTest
Test the ContentModerationState storage schema.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

protected function assertStorageException(array $values, bool $has_exception) : void {
    $defaults = [
        'moderation_state' => 'draft',
        'workflow' => 'editorial',
    ];
    $entity = ContentModerationState::create($values + $defaults);
    $exception_triggered = FALSE;
    try {
        ContentModerationState::updateOrCreateFromEntity($entity);
    } catch (\Exception $e) {
        $exception_triggered = TRUE;
    }
    $this->assertEquals($has_exception, $exception_triggered);
}

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