function StateFormatterTest::testStateFieldFormatter

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

Test the embed field.

@dataProvider formatterTestCases

File

core/modules/content_moderation/tests/src/Kernel/StateFormatterTest.php, line 51

Class

StateFormatterTest
Test the state field formatter.

Namespace

Drupal\Tests\content_moderation\Kernel

Code

public function testStateFieldFormatter($field_value, $formatter_settings, $expected_output) {
    $entity = EntityTestRev::create([
        'moderation_state' => $field_value,
    ]);
    $entity->save();
    $field_output = $this->container
        ->get('renderer')
        ->executeInRenderContext(new RenderContext(), function () use ($entity, $formatter_settings) {
        return $entity->moderation_state
            ->view($formatter_settings);
    });
    $this->assertEquals($expected_output, $field_output[0]);
}

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