Verified Commit c7839e14 authored by Project Update Bot's avatar Project Update Bot Committed by Lee Rowlands
Browse files

Issue #3297902 by Project Update Bot: Automated Drupal 10 compatibility fixes

parent a50da83a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
name: Publishing Dropbutton
type: module
description: 'Restore publishing dropbuttons for node and content_moderation.'
core_version_requirement: ^8 || ^9
core_version_requirement: ^9.1 || ^10

dependencies:
  - drupal:system (>=8.4)
+54 −42
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ class ModerationFormTest extends ModerationStateTestBase {
   *
   * @var array
   */
  public static $modules = [
  protected static $modules = [
    'node',
    'content_moderation',
    'locale',
@@ -35,7 +35,7 @@ class ModerationFormTest extends ModerationStateTestBase {
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
  protected function setUp(): void {
    parent::setUp();
    $this->drupalLogin($this->adminUser);
    $this->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE);
@@ -51,8 +51,9 @@ class ModerationFormTest extends ModerationStateTestBase {
   * @see \Drupal\Tests\content_moderation\Functional\ModerationStateBlockTest::testCustomBlockModeration
   */
  public function testModerationForm() {
    $this->drupalGet('node/add/moderated_content');
    // Create new moderated content in draft.
    $this->drupalPostForm('node/add/moderated_content', [
    $this->submitForm([
      'title[0][value]' => 'Some moderated content',
      'body[0][value]' => 'First version of the content.',
    ], t('Save and Create New Draft'));
@@ -67,73 +68,77 @@ class ModerationFormTest extends ModerationStateTestBase {
    // The canonical view should have a moderation form, because it is not the
    // live revision.
    $this->drupalGet($canonical_path);
    $this->assertResponse(200);
    $this->assertField('edit-new-state', 'The node view page has a moderation form.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldExists('edit-new-state', 'The node view page has a moderation form.');

    // The latest version page should not show, because there is no pending
    // revision.
    $this->drupalGet($latest_version_path);
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet($edit_path);

    // Update the draft.
    $this->drupalPostForm($edit_path, [
    $this->submitForm([
      'body[0][value]' => 'Second version of the content.',
    ], t('Save and Create New Draft'));

    // The canonical view should have a moderation form, because it is not the
    // live revision.
    $this->drupalGet($canonical_path);
    $this->assertResponse(200);
    $this->assertField('edit-new-state', 'The node view page has a moderation form.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldExists('edit-new-state', 'The node view page has a moderation form.');

    // The latest version page should not show, because there is still no
    // pending revision.
    $this->drupalGet($latest_version_path);
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet($edit_path);

    // Publish the draft.
    $this->drupalPostForm($edit_path, [
    $this->submitForm([
      'body[0][value]' => 'Third version of the content.',
    ], t('Save and Publish'));

    // The published view should not have a moderation form, because it is the
    // live revision.
    $this->drupalGet($canonical_path);
    $this->assertResponse(200);
    $this->assertNoField('edit-new-state', 'The node view page has no moderation form.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldNotExists('edit-new-state', 'The node view page has no moderation form.');

    // The latest version page should not show, because there is still no
    // pending revision.
    $this->drupalGet($latest_version_path);
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet($edit_path);

    // Make a pending revision.
    $this->drupalPostForm($edit_path, [
    $this->submitForm([
      'body[0][value]' => 'Fourth version of the content.',
    ], t('Save and Create New Draft'));

    // The published view should not have a moderation form, because it is the
    // live revision.
    $this->drupalGet($canonical_path);
    $this->assertResponse(200);
    $this->assertNoField('edit-new-state', 'The node view page has no moderation form.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldNotExists('edit-new-state', 'The node view page has no moderation form.');

    // The latest version page should show the moderation form and have "Draft"
    // status, because the pending revision is in "Draft".
    $this->drupalGet($latest_version_path);
    $this->assertResponse(200);
    $this->assertField('edit-new-state', 'The latest-version page has a moderation form.');
    $this->assertText('Draft', 'Correct status found on the latest-version page.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->fieldExists('edit-new-state', 'The latest-version page has a moderation form.');
    $this->assertSession()->pageTextContains('Draft');
    $this->drupalGet($latest_version_path);

    // Submit the moderation form to change status to published.
    $this->drupalPostForm($latest_version_path, [
    $this->submitForm([
      'new_state' => 'published',
    ], t('Apply'));

    // The latest version page should not show, because there is no
    // pending revision.
    $this->drupalGet($latest_version_path);
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
  }

  /**
@@ -146,61 +151,66 @@ class ModerationFormTest extends ModerationStateTestBase {
    $workflow->save();

    drupal_flush_all_caches();
    $this->drupalGet('entity_test_mulrevpub/add');

    // Create new moderated content in draft.
    $this->drupalPostForm('entity_test_mulrevpub/add', [], t('Save and Create New Draft'));
    $this->submitForm([], t('Save and Create New Draft'));

    // The latest version page should not show, because there is no pending
    // revision.
    $this->drupalGet('/entity_test_mulrevpub/manage/1/latest');
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet('entity_test_mulrevpub/manage/1/edit');

    // Update the draft.
    $this->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [], t('Save and Create New Draft'));
    $this->submitForm([], t('Save and Create New Draft'));

    // The latest version page should not show, because there is still no
    // pending revision.
    $this->drupalGet('/entity_test_mulrevpub/manage/1/latest');
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet('entity_test_mulrevpub/manage/1/edit');

    // Publish the draft.
    $this->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [], t('Save and Publish'));
    $this->submitForm([], t('Save and Publish'));

    // The published view should not have a moderation form, because it is the
    // default revision.
    $this->drupalGet('entity_test_mulrevpub/manage/1');
    $this->assertResponse(200);
    $this->assertNoText('Status', 'The node view page has no moderation form.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextNotContains('Status');

    // The latest version page should not show, because there is still no
    // pending revision.
    $this->drupalGet('entity_test_mulrevpub/manage/1/latest');
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet('entity_test_mulrevpub/manage/1/edit');

    // Make a pending revision.
    $this->drupalPostForm('entity_test_mulrevpub/manage/1/edit', [], t('Save and Create New Draft'));
    $this->submitForm([], t('Save and Create New Draft'));

    // The published view should not have a moderation form, because it is the
    // default revision.
    $this->drupalGet('entity_test_mulrevpub/manage/1');
    $this->assertResponse(200);
    $this->assertNoText('Status', 'The node view page has no moderation form.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextNotContains('Status');

    // The latest version page should show the moderation form and have "Draft"
    // status, because the pending revision is in "Draft".
    $this->drupalGet('entity_test_mulrevpub/manage/1/latest');
    $this->assertResponse(200);
    $this->assertText('Draft', 'Correct status found on the latest-version page.');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Draft');
    $this->drupalGet('entity_test_mulrevpub/manage/1/latest');

    // Submit the moderation form to change status to published.
    $this->drupalPostForm('entity_test_mulrevpub/manage/1/latest', [
    $this->submitForm([
      'new_state' => 'published',
    ], t('Apply'));

    // The latest version page should not show, because there is no
    // pending revision.
    $this->drupalGet('entity_test_mulrevpub/manage/1/latest');
    $this->assertResponse(403);
    $this->assertSession()->statusCodeEquals(403);
  }

  /**
@@ -213,7 +223,8 @@ class ModerationFormTest extends ModerationStateTestBase {
    $edit = [
      'predefined_langcode' => 'fr',
    ];
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, t('Add language'));

    // Enable content translation on articles.
    $this->drupalGet('admin/config/regional/content-language');
@@ -222,14 +233,15 @@ class ModerationFormTest extends ModerationStateTestBase {
      'settings[node][moderated_content][translatable]' => TRUE,
      'settings[node][moderated_content][settings][language][language_alterable]' => TRUE,
    ];
    $this->drupalPostForm(NULL, $edit, t('Save configuration'));
    $this->submitForm($edit, t('Save configuration'));

    // Adding languages requires a container rebuild in the test running
    // environment so that multilingual services are used.
    $this->rebuildContainer();
    $this->drupalGet('node/add/moderated_content');

    // Create new moderated content in draft (revision 1).
    $this->drupalPostForm('node/add/moderated_content', [
    $this->submitForm([
      'title[0][value]' => 'Some moderated content',
      'body[0][value]' => 'First version of the content.',
    ], t('Save and Create New Draft'));
@@ -251,7 +263,7 @@ class ModerationFormTest extends ModerationStateTestBase {
    $this->assertNotEmpty($this->xpath('//input[@value="Save and Create New Draft (this translation)"]'));
    $this->assertNotEmpty($this->xpath('//input[@value="Save and Publish (this translation)"]'));
    $this->assertEmpty($this->xpath('//input[@value="Save and Archive (this translation)"]'));
    $this->drupalPostForm(NULL, [
    $this->submitForm([
      'body[0][value]' => 'Second version of the content.',
    ], t('Save and Publish (this translation)'));

@@ -264,7 +276,7 @@ class ModerationFormTest extends ModerationStateTestBase {
    $this->assertNotEmpty($this->xpath('//input[@value="Save and Create New Draft (this translation)"]'));
    $this->assertNotEmpty($this->xpath('//input[@value="Save and Publish (this translation)"]'));
    $this->assertNotEmpty($this->xpath('//input[@value="Save and Archive (this translation)"]'));
    $this->drupalPostForm(NULL, [
    $this->submitForm([
      'body[0][value]' => 'Third version of the content.',
    ], t('Save and Create New Draft (this translation)'));

+15 −9
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ class NodeFormButtonsTest extends NodeTestBase {
   *
   * @var array
   */
  public static $modules = [
  protected static $modules = [
    'publishing_dropbutton',
  ];

@@ -44,7 +44,7 @@ class NodeFormButtonsTest extends NodeTestBase {
   */
  protected $adminUser;

  protected function setUp() {
  protected function setUp(): void {
    parent::setUp();

    // Create a user that has no access to change the state of the node.
@@ -68,7 +68,8 @@ class NodeFormButtonsTest extends NodeTestBase {
    // Save the node and assert it's published after clicking
    // 'Save and publish'.
    $edit = ['title[0][value]' => $this->randomString()];
    $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, t('Save and publish'));

    // Get the node.
    $node_1 = $node_storage->load(1);
@@ -80,14 +81,15 @@ class NodeFormButtonsTest extends NodeTestBase {

    // Save the node and verify it's still published after clicking
    // 'Save and keep published'.
    $this->drupalPostForm(NULL, $edit, t('Save and keep published'));
    $this->submitForm($edit, t('Save and keep published'));
    $node_storage->resetCache([1]);
    $node_1 = $node_storage->load(1);
    $this->assertTrue($node_1->isPublished(), 'Node is published');
    $this->drupalGet('node/' . $node_1->id() . '/edit');

    // Save the node and verify it's unpublished after clicking
    // 'Save and unpublish'.
    $this->drupalPostForm('node/' . $node_1->id() . '/edit', $edit, t('Save and unpublish'));
    $this->submitForm($edit, t('Save and unpublish'));
    $node_storage->resetCache([1]);
    $node_1 = $node_storage->load(1);
    $this->assertFalse($node_1->isPublished(), 'Node is unpublished');
@@ -106,7 +108,8 @@ class NodeFormButtonsTest extends NodeTestBase {

    // Create the node.
    $edit = ['title[0][value]' => $this->randomString()];
    $this->drupalPostForm('node/add/article', $edit, t('Save'));
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, t('Save'));
    $node_2 = $node_storage->load(2);
    $this->assertTrue($node_2->isPublished(), 'Node is published');

@@ -114,7 +117,8 @@ class NodeFormButtonsTest extends NodeTestBase {
    // was created by the normal user.
    $this->drupalLogout();
    $this->drupalLogin($this->adminUser);
    $this->drupalPostForm('node/' . $node_2->id() . '/edit', [], t('Save and unpublish'));
    $this->drupalGet('node/' . $node_2->id() . '/edit');
    $this->submitForm([], t('Save and unpublish'));
    $node_storage->resetCache([2]);
    $node_2 = $node_storage->load(2);
    $this->assertFalse($node_2->isPublished(), 'Node is unpublished');
@@ -123,7 +127,8 @@ class NodeFormButtonsTest extends NodeTestBase {
    // it's still unpublished.
    $this->drupalLogout();
    $this->drupalLogin($this->webUser);
    $this->drupalPostForm('node/' . $node_2->id() . '/edit', [], t('Save'));
    $this->drupalGet('node/' . $node_2->id() . '/edit');
    $this->submitForm([], t('Save'));
    $node_storage->resetCache([2]);
    $node_2 = $node_storage->load(2);
    $this->assertFalse($node_2->isPublished(), 'Node is still unpublished');
@@ -146,7 +151,8 @@ class NodeFormButtonsTest extends NodeTestBase {
    $this->drupalLogout();
    $this->drupalLogin($this->webUser);
    $edit = ['title[0][value]' => $this->randomString()];
    $this->drupalPostForm('node/add/article', $edit, t('Save'));
    $this->drupalGet('node/add/article');
    $this->submitForm($edit, t('Save'));
    $node_3 = $node_storage->load(3);
    $this->assertFalse($node_3->isPublished(), 'Node is unpublished');
  }