diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php index 11deaa72c0..12d966d23e 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateNodeTest.php @@ -4,6 +4,8 @@ use Drupal\Core\Url; use Drupal\node\Entity\Node; +use Drupal\Tests\image\Kernel\ImageFieldCreationTrait; +use Drupal\Tests\TestFileCreationTrait; /** * Tests general content moderation workflow for nodes. @@ -12,6 +14,23 @@ */ class ModerationStateNodeTest extends ModerationStateTestBase { + use ImageFieldCreationTrait; + use TestFileCreationTrait; + + /** + * The name of the moderated image field used in the test. + * + * @var string + */ + protected $moderatedImagefieldName; + + /** + * The name of the unmoderated image field used in the test. + * + * @var string + */ + protected $unmoderatedImagefieldName; + /** * {@inheritdoc} */ @@ -19,6 +38,13 @@ protected function setUp() { parent::setUp(); $this->drupalLogin($this->adminUser); $this->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE); + $this->createContentTypeFromUi('Unmoderated content', 'unmoderated_content'); + + // Create a image field on both content types. + $this->moderatedImagefieldName = strtolower($this->randomMachineName()); + $this->unmoderatedImagefieldName = strtolower($this->randomMachineName()); + $this->createImageField($this->moderatedImagefieldName, 'moderated_content', [], ['title_field' => 1]); + $this->createImageField($this->unmoderatedImagefieldName, 'unmoderated_content', [], ['title_field' => 1]); $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content'); } @@ -26,15 +52,42 @@ protected function setUp() { * Tests creating and deleting content. */ public function testCreatingContent() { - $this->drupalPostForm('node/add/moderated_content', [ + // First test we can add unmoderated nodes and the moderation state is null. + $test_image = current($this->getTestFiles('image')); + $edit = [ + 'title[0][value]' => 'unmoderated content', + 'files[' . $this->unmoderatedImagefieldName . '_0]' => \Drupal::service('file_system')->realpath($test_image->uri), + ]; + $this->drupalPostForm('node/add/unmoderated_content', $edit, t('Save')); + $edit = [ + $this->unmoderatedImagefieldName . '[0][alt]' => 'Test image', + $this->unmoderatedImagefieldName . '[0][title]' => 'Test image title' + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); + $node = $this->getNodeByTitle('unmoderated content'); + if (!$node) { + $this->fail('Test node was not saved correctly.'); + } + $this->assertNull($node->moderation_state->value); + + // Next test we can created moderated nodes. + $test_image = current($this->getTestFiles('image')); + $edit = [ 'title[0][value]' => 'moderated content', 'moderation_state[0][state]' => 'draft', - ], t('Save')); + 'files[' . $this->moderatedImagefieldName . '_0]' => \Drupal::service('file_system')->realpath($test_image->uri), + ]; + $this->drupalPostForm('node/add/moderated_content', $edit, t('Save')); + $edit = [ + $this->moderatedImagefieldName . '[0][alt]' => 'Test image', + $this->moderatedImagefieldName . '[0][title]' => 'Test image title' + ]; + $this->drupalPostForm(NULL, $edit, t('Save')); $node = $this->getNodeByTitle('moderated content'); if (!$node) { $this->fail('Test node was not saved correctly.'); } - $this->assertEqual('draft', $node->moderation_state->value); + $this->assertEquals('draft', $node->moderation_state->value); $path = 'node/' . $node->id() . '/edit'; // Set up published revision. @@ -55,7 +108,7 @@ public function testCreatingContent() { $this->assertText(t('The Moderated content moderated content has been deleted.')); // Disable content moderation. - $edit['bundles[moderated_content]'] = FALSE; + $edit = ['bundles[moderated_content]' => FALSE]; $this->drupalPostForm('admin/config/workflow/workflows/manage/editorial/type/node', $edit, t('Save'));; // Ensure the parent environment is up-to-date. // @see content_moderation_workflow_insert() diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php b/core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php index 92f51a8286..77b6c16354 100644 --- a/core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php +++ b/core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php @@ -54,6 +54,8 @@ 'block_content', 'node', 'entity_test', + 'field_ui', + 'image', ]; /** @@ -106,7 +108,7 @@ protected function createContentTypeFromUi($content_type_name, $content_type_id, 'name' => $content_type_name, 'type' => $content_type_id, ]; - $this->drupalPostForm(NULL, $edit, t('Save content type')); + $this->drupalPostForm(NULL, $edit, t('Save and manage fields')); if ($moderated) { $this->enableModerationThroughUi($content_type_id, $workflow_id);