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\workflows\Entity\Workflow;
11 * Test the state field formatter.
13 * @group content_moderation
15 class StateFormatterTest extends KernelTestBase {
22 public static $modules = [
32 protected function setUp() {
35 $this->installEntitySchema('entity_test_rev');
36 $this->installEntitySchema('content_moderation_state');
37 $this->installConfig('content_moderation');
39 $workflow = Workflow::load('editorial');
40 $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
45 * Test the embed field.
47 * @dataProvider formatterTestCases
49 public function testStateFieldFormatter($field_value, $formatter_settings, $expected_output) {
50 $entity = EntityTestRev::create([
51 'moderation_state' => $field_value,
55 $field_output = $this->container->get('renderer')->executeInRenderContext(new RenderContext(), function() use ($entity, $formatter_settings) {
56 return $entity->moderation_state->view($formatter_settings);
59 $this->assertEquals($expected_output, $field_output[0]);
65 public function formatterTestCases() {
70 'type' => 'content_moderation_state',
77 'Published State' => [
80 'type' => 'content_moderation_state',
84 '#markup' => 'Published',