X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontent_moderation%2Ftests%2Fsrc%2FFunctional%2FModerationFormTest.php;h=9f3c401e632bbd74d23eac4939a67d9042f45924;hb=refs%2Fheads%2Fd864;hp=13fd0c0571a7efdd9463d0219cb6b44ec88bb397;hpb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;p=yaffs-website diff --git a/web/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php b/web/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php index 13fd0c057..9f3c401e6 100644 --- a/web/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php +++ b/web/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php @@ -2,7 +2,8 @@ namespace Drupal\Tests\content_moderation\Functional; -use Drupal\workflows\Entity\Workflow; +use Drupal\Core\Entity\Entity\EntityFormDisplay; +use Drupal\Core\Url; /** * Tests the moderation form, specifically on nodes. @@ -79,6 +80,21 @@ class ModerationFormTest extends ModerationStateTestBase { $this->assertResponse(200); $this->assertField('edit-new-state', 'The node view page has a moderation form.'); + // Preview the draft. + $this->drupalPostForm($edit_path, [ + 'body[0][value]' => 'Second version of the content.', + 'moderation_state[0][state]' => 'draft', + ], t('Preview')); + + // The preview view should not have a moderation form. + $preview_url = Url::fromRoute('entity.node.preview', [ + 'node_preview' => $node->uuid(), + 'view_mode_id' => 'full', + ]); + $this->assertResponse(200); + $this->assertUrl($preview_url); + $this->assertNoField('edit-new-state', 'The node preview page has no moderation form.'); + // The latest version page should not show, because there is still no // pending revision. $this->drupalGet($latest_version_path); @@ -90,6 +106,10 @@ class ModerationFormTest extends ModerationStateTestBase { 'moderation_state[0][state]' => 'published', ], t('Save')); + // Check widget default value. + $this->drupalGet($edit_path); + $this->assertFieldByName('moderation_state[0][state]', 'published', 'The moderation default value is set correctly.'); + // The published view should not have a moderation form, because it is the // live revision. $this->drupalGet($canonical_path); @@ -136,9 +156,8 @@ class ModerationFormTest extends ModerationStateTestBase { */ public function testNonBundleModerationForm() { $this->drupalLogin($this->rootUser); - $workflow = Workflow::load('editorial'); - $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub'); - $workflow->save(); + $this->workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_mulrevpub', 'entity_test_mulrevpub'); + $this->workflow->save(); // Create new moderated content in draft. $this->drupalPostForm('entity_test_mulrevpub/add', ['moderation_state[0][state]' => 'draft'], t('Save')); @@ -295,14 +314,6 @@ class ModerationFormTest extends ModerationStateTestBase { $this->drupalGet($latest_version_path, ['language' => $french]); $this->assertTrue($this->xpath('//ul[@class="entity-moderation-form"]')); - // It should not be possible to add a new english revision. - $this->drupalGet($edit_path); - $this->assertSession()->fieldNotExists('moderation_state[0][state]'); - $this->assertSession()->pageTextContains('Unable to save this Moderated content.'); - - $this->clickLink('Publish'); - $this->assertSession()->fieldValueEquals('body[0][value]', 'Third version of the content.'); - $this->drupalGet($edit_path); $this->clickLink('Delete'); $this->assertSession()->buttonExists('Delete'); @@ -323,7 +334,7 @@ class ModerationFormTest extends ModerationStateTestBase { $this->drupalGet($latest_version_path, ['language' => $french]); $this->assertFalse($this->xpath('//ul[@class="entity-moderation-form"]')); - // Now we can publish the english (revision 5). + // Publish the English pending revision (revision 5). $this->drupalGet($edit_path); $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); $this->assertSession()->optionExists('moderation_state[0][state]', 'published'); @@ -336,13 +347,13 @@ class ModerationFormTest extends ModerationStateTestBase { $this->drupalGet($latest_version_path); $this->assertFalse($this->xpath('//ul[@class="entity-moderation-form"]')); - // Make sure we're allowed to create a pending french revision. + // Make sure we are allowed to create a pending French revision. $this->drupalGet($edit_path, ['language' => $french]); $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); $this->assertSession()->optionExists('moderation_state[0][state]', 'published'); $this->assertSession()->optionExists('moderation_state[0][state]', 'archived'); - // Add a english pending revision (revision 6). + // Add an English pending revision (revision 6). $this->drupalGet($edit_path); $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); $this->assertSession()->optionExists('moderation_state[0][state]', 'published'); @@ -354,16 +365,10 @@ class ModerationFormTest extends ModerationStateTestBase { $this->drupalGet($latest_version_path); $this->assertTrue($this->xpath('//ul[@class="entity-moderation-form"]')); - - // Make sure we're not allowed to create a pending french revision. - $this->drupalGet($edit_path, ['language' => $french]); - $this->assertSession()->fieldNotExists('moderation_state[0][state]'); - $this->assertSession()->pageTextContains('Unable to save this Moderated content.'); - $this->drupalGet($latest_version_path, ['language' => $french]); $this->assertFalse($this->xpath('//ul[@class="entity-moderation-form"]')); - // We should be able to publish the english pending revision (revision 7) + // Publish the English pending revision (revision 7) $this->drupalGet($edit_path); $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); $this->assertSession()->optionExists('moderation_state[0][state]', 'published'); @@ -376,44 +381,17 @@ class ModerationFormTest extends ModerationStateTestBase { $this->drupalGet($latest_version_path); $this->assertFalse($this->xpath('//ul[@class="entity-moderation-form"]')); - // Make sure we're allowed to create a pending french revision. + // Make sure we are allowed to create a pending French revision. $this->drupalGet($edit_path, ['language' => $french]); $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); $this->assertSession()->optionExists('moderation_state[0][state]', 'published'); $this->assertSession()->optionExists('moderation_state[0][state]', 'archived'); - // Make sure we're allowed to create a pending english revision. - $this->drupalGet($edit_path); - $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); - $this->assertSession()->optionExists('moderation_state[0][state]', 'published'); - $this->assertSession()->optionExists('moderation_state[0][state]', 'archived'); - - // Create new moderated content. (revision 1). - $this->drupalPostForm('node/add/moderated_content', [ - 'title[0][value]' => 'Second moderated content', - 'body[0][value]' => 'First version of the content.', - 'moderation_state[0][state]' => 'published', - ], t('Save')); - - $node = $this->drupalGetNodeByTitle('Second moderated content'); - $this->assertTrue($node->language(), 'en'); - $edit_path = sprintf('node/%d/edit', $node->id()); - $translate_path = sprintf('node/%d/translations/add/en/fr', $node->id()); - - // Add a pending revision (revision 2). + // Make sure we are allowed to create a pending English revision. $this->drupalGet($edit_path); $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); $this->assertSession()->optionExists('moderation_state[0][state]', 'published'); $this->assertSession()->optionExists('moderation_state[0][state]', 'archived'); - $this->drupalPostForm(NULL, [ - 'body[0][value]' => 'Second version of the content.', - 'moderation_state[0][state]' => 'draft', - ], t('Save')); - - // It shouldn't be possible to translate as we have a pending revision. - $this->drupalGet($translate_path); - $this->assertSession()->fieldNotExists('moderation_state[0][state]'); - $this->assertSession()->pageTextContains('Unable to save this Moderated content.'); // Create new moderated content (revision 1). $this->drupalPostForm('node/add/moderated_content', [ @@ -444,11 +422,6 @@ class ModerationFormTest extends ModerationStateTestBase { 'moderation_state[0][state]' => 'draft', ], t('Save (this translation)')); - // Editing the original translation should not be possible. - $this->drupalGet($edit_path); - $this->assertSession()->fieldNotExists('moderation_state[0][state]'); - $this->assertSession()->pageTextContains('Unable to save this Moderated content.'); - // Updating and publishing the french translation is still possible. $this->drupalGet($edit_path, ['language' => $french]); $this->assertSession()->optionExists('moderation_state[0][state]', 'draft'); @@ -468,6 +441,23 @@ class ModerationFormTest extends ModerationStateTestBase { ], t('Save (this translation)')); } + /** + * Test the moderation_state field when an alternative widget is set. + */ + public function testAlternativeModerationStateWidget() { + $entity_form_display = EntityFormDisplay::load('node.moderated_content.default'); + $entity_form_display->setComponent('moderation_state', [ + 'type' => 'string_textfield', + 'region' => 'content', + ]); + $entity_form_display->save(); + $this->drupalPostForm('node/add/moderated_content', [ + 'title[0][value]' => 'Test content', + 'moderation_state[0][value]' => 'published', + ], 'Save'); + $this->assertSession()->pageTextContains('Moderated content Test content has been created.'); + } + /** * Tests that workflows and states can not be deleted if they are in use. * @@ -481,7 +471,7 @@ class ModerationFormTest extends ModerationStateTestBase { 'edit own moderated_content content', 'use editorial transition create_new_draft', 'use editorial transition publish', - 'use editorial transition archive' + 'use editorial transition archive', ]); $this->drupalLogin($user); $paths = [