BulkFormTest.php 3.92 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
<?php

/**
 * @file
 * Contains \Drupal\node\Tests\Views\BulkFormTest.
 */

namespace Drupal\node\Tests\Views;

/**
 * Tests the views bulk form test.
 *
 * @see \Drupal\node\Plugin\views\field\BulkForm
 */
class BulkFormTest extends NodeTestBase {

  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = array('test_node_bulk_form');

  public static function getInfo() {
    return array(
      'name' => 'Node: Bulk form',
      'description' => 'Tests a node bulk form.',
28
      'group' => 'Views module integration',
29 30 31 32 33 34 35 36 37 38 39 40 41 42
    );
  }

  /**
   * Tests the node bulk form.
   */
  public function testBulkForm() {
    $this->drupalLogin($this->drupalCreateUser(array('administer nodes')));
    $node = $this->drupalCreateNode();

    $this->drupalGet('test-node-bulk-form');
    $elements = $this->xpath('//select[@id="edit-action"]//option');
    $this->assertIdentical(count($elements), 8, 'All node operations are found.');

43 44
    // Unpublish a node using the bulk form.
    $this->assertTrue($node->isPublished(), 'Node is initially published');
45 46 47 48 49
    $edit = array(
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_unpublish_action',
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    // Re-load the node and check the status.
    $node = entity_load('node', $node->id(), TRUE);
    $this->assertFalse($node->isPublished(), 'Node has been unpublished');

    // Publish action.
    $edit = array(
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_publish_action',
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
    // Re-load the node and check the status.
    $node = entity_load('node', $node->id(), TRUE);
    $this->assertTrue($node->isPublished(), 'Node has been published');

    // Make sticky action.
    $node->setPublished(FALSE);
    $node->save();
    $this->assertFalse($node->isSticky(), 'Node is not sticky');
    $edit = array(
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_make_sticky_action',
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
    // Re-load the node and check the status and sticky flag.
    $node = entity_load('node', $node->id(), TRUE);
    $this->assertTrue($node->isPublished(), 'Node has been published');
    $this->assertTrue($node->isSticky(), 'Node has been made sticky');

    // Make unsticky action.
    $edit = array(
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_make_unsticky_action',
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
    // Re-load the node and check the sticky flag.
    $node = entity_load('node', $node->id(), TRUE);
    $this->assertFalse($node->isSticky(), 'Node is not sticky anymore');

    // Promote to front page.
    $node->setPublished(FALSE);
    $node->save();
    $this->assertFalse($node->isPromoted(), 'Node is not promoted to the front page');
    $edit = array(
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_promote_action',
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
    // Re-load the node and check the status and promoted flag.
    $node = entity_load('node', $node->id(), TRUE);
    $this->assertTrue($node->isPublished(), 'Node has been published');
    $this->assertTrue($node->isPromoted(), 'Node has been promoted to the front page');

    // Demote from front page.
    $edit = array(
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_unpromote_action',
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
    // Re-load the node and check the promoted flag.
    $node = entity_load('node', $node->id(), TRUE);
    $this->assertFalse($node->isPromoted(), 'Node has been demoted');

    // Delete node.
    $edit = array(
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_delete_action',
    );
    $this->drupalPost(NULL, $edit, t('Apply'));
    $this->drupalPost(NULL, array(), t('Delete'));
    // Re-load the node and check if it has been deleted.
    $node = entity_load('node', $node->id(), TRUE);
    $this->assertNull($node, 'Node has been deleted');
122 123 124
  }

}