Commit 212ad337 authored by Jonathan Smith's avatar Jonathan Smith Committed by Jonathan Smith
Browse files

Issue #2712465 by jonathan1055: Divide the "node delete" test into two functions

parent 968e7cfb
Loading
Loading
Loading
Loading
+29 −23
Changes for tests/src/Functional/SchedulerDeleteNodeTest.php: 29 added lines, 23 removed lines.
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ namespace Drupal\Tests\scheduler\Functional;
use Drupal\node\Entity\NodeType;

/**
 * Tests deletion of a node enabled for Scheduler.
 * Tests deletion of nodes enabled for Scheduler.
 *
 * This checks how the deletion of a node interacts with the Scheduler
 * 'required' options and scheduled dates in the past.
@@ -16,21 +16,25 @@ class SchedulerDeleteNodeTest extends SchedulerBrowserTestBase {

  /**
   * Tests the deletion of a scheduled node.
   *
   * Check that it is possible to delete a node that does not have a publishing
   * date set, when scheduled publishing is required. Likewise for unpublishing.
   *
   * @see https://drupal.org/node/1614880
   */
  public function testScheduledNodeDelete() {
  public function testDeleteNodeWhenSchedulingIsRequired() {
    // Log in.
    $this->drupalLogin($this->adminUser);

    /*
    Test if it is possible to delete a node that does not have a publication
    date set, when scheduled publishing is required. Likewise for unpublishing.
    @see https://drupal.org/node/1614880
     */

    // Create a published and an unpublished node, both without scheduled dates.
    $type = $this->nodetype->get('type');
    $published_node = $this->drupalCreateNode(['type' => $type, 'status' => 1]);
    $unpublished_node = $this->drupalCreateNode(['type' => $type, 'status' => 0]);
    $published_node = $this->drupalCreateNode([
      'type' => $this->type,
      'status' => 1,
    ]);
    $unpublished_node = $this->drupalCreateNode([
      'type' => $this->type,
      'status' => 0,
    ]);

    // Make scheduled publishing and unpublishing required.
    $this->nodetype->setThirdPartySetting('scheduler', 'publish_required', TRUE)
@@ -51,34 +55,37 @@ class SchedulerDeleteNodeTest extends SchedulerBrowserTestBase {
    $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete a published node with no scheduling information.');
    $this->assertRaw(t('Are you sure you want to delete the content'), 'The deletion warning message is shown immediately when trying to delete a published node with no scheduling information.');

    // Do the same test for the unpublished node.
    $this->drupalGet('node/' . $unpublished_node->id() . '/edit');
    $this->clickLink('Delete');
    $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete an unpublished node with no scheduling information.');
    $this->assertRaw(t('Are you sure you want to delete the content'), 'The deletion warning message is shown immediately when trying to delete an unpublished node with no scheduling information.');
  }

    /*
    Test that nodes can be deleted with no validation errors if the dates are in
    the past.
    @see http://drupal.org/node/2627370
  /**
   * Tests the deletion of a scheduled node.
   *
   * Check that nodes can be deleted with no validation errors if the dates are
   * in the past.
   *
   * @see http://drupal.org/node/2627370
   */
  public function testDeleteNodeWithPastDates() {
    // Log in.
    $this->drupalLogin($this->adminUser);

    // Create nodes with publish_on and unpublish_on dates in the past.
    $published_node = $this->drupalCreateNode([
      'type' => $type,
      'type' => $this->type,
      'status' => TRUE,
      'unpublish_on' => strtotime('- 2 day'),
    ]);
    $unpublished_node = $this->drupalCreateNode([
      'type' => $type,
      'type' => $this->type,
      'status' => FALSE,
      'publish_on' => strtotime('- 2 day'),
    ]);

    // Turn off required publishing and unpublishing.
    $this->nodetype->setThirdPartySetting('scheduler', 'publish_required', FALSE)
      ->setThirdPartySetting('scheduler', 'unpublish_required', FALSE)
      ->save();

    // Attempt to delete the published node and check for no validation error.
    $this->drupalGet('node/' . $published_node->id() . '/edit');
    $this->clickLink('Delete');
@@ -90,7 +97,6 @@ class SchedulerDeleteNodeTest extends SchedulerBrowserTestBase {
    $this->clickLink('Delete');
    $this->assertNoRaw(t('Error message'), 'No error messages are shown when trying to delete a node with a publish date in the past.');
    $this->assertRaw(t('Are you sure you want to delete the content'), 'The deletion warning message is shown immediately when trying to delete a node with a publish date in the past.');

  }

}