3 namespace Drupal\Tests\content_moderation\Kernel;
5 use Drupal\Core\Render\RenderContext;
6 use Drupal\entity_test\Entity\EntityTestRev;
7 use Drupal\KernelTests\KernelTestBase;
8 use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
11 * Test the state field formatter.
13 * @group content_moderation
15 class StateFormatterTest extends KernelTestBase {
17 use ContentModerationTestTrait;
24 public static $modules = [
34 protected function setUp() {
37 $this->installEntitySchema('entity_test_rev');
38 $this->installEntitySchema('content_moderation_state');
39 $this->installConfig('content_moderation');
41 $workflow = $this->createEditorialWorkflow();
42 $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
47 * Test the embed field.
49 * @dataProvider formatterTestCases
51 public function testStateFieldFormatter($field_value, $formatter_settings, $expected_output) {
52 $entity = EntityTestRev::create([
53 'moderation_state' => $field_value,
57 $field_output = $this->container->get('renderer')->executeInRenderContext(new RenderContext(), function () use ($entity, $formatter_settings) {
58 return $entity->moderation_state->view($formatter_settings);
61 $this->assertEquals($expected_output, $field_output[0]);
67 public function formatterTestCases() {
72 'type' => 'content_moderation_state',
79 'Published State' => [
82 'type' => 'content_moderation_state',
86 '#markup' => 'Published',