Unverified Commit e8a0c86a authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3048962 by Sam152, anmolgoyal74, paulocs, EclipseGc, abarrios,...

Issue #3048962 by Sam152, anmolgoyal74, paulocs, EclipseGc, abarrios, scotwith1t, Lendude: Moderation State fields generate bad sample data

(cherry picked from commit 486bab8b)
parent 749fc09a
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -174,4 +174,12 @@ protected function updateModeratedEntity($moderation_state_id) {
    }
  }

  /**
   * {@inheritdoc}
   */
  public function generateSampleItems($count = 1) {
    // No sample items generated since the starting moderation state is always
    // computed based on the default state of the associated workflow.
  }

}
+20 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\workflows\Entity\Workflow;

/**
@@ -17,6 +18,7 @@
class ModerationStateFieldItemListTest extends KernelTestBase {

  use ContentModerationTestTrait;
  use UserCreationTrait;

  /**
   * {@inheritdoc}
@@ -42,6 +44,7 @@ protected function setUp(): void {
    parent::setUp();

    $this->installSchema('node', 'node_access');
    $this->installSchema('system', 'sequences');
    $this->installEntitySchema('node');
    $this->installEntitySchema('user');
    $this->installEntitySchema('content_moderation_state');
@@ -401,6 +404,23 @@ public function testWithExistingUnmoderatedContent() {
    $this->assertEquals('published', $translation->moderation_state->value);
  }

  /**
   * Test generating sample values for entities with a moderation state.
   */
  public function testModerationStateSampleValues() {
    $this->container->get('current_user')->setAccount(
      $this->createUser([
        'use editorial transition create_new_draft',
        'use editorial transition publish',
      ])
    );
    $sample = $this->container->get('entity_type.manager')
      ->getStorage('node')
      ->createWithSampleValues('example');
    $this->assertCount(0, $sample->validate());
    $this->assertEquals('draft', $sample->moderation_state->value);
  }

  /**
   * Tests field item list translation support with unmoderated content.
   */