BulkFormTest.php 2.25 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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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
<?php

/**
 * @file
 * Contains \Drupal\action\Tests\BulkFormTest.
 */

namespace Drupal\action\Tests;

use Drupal\simpletest\WebTestBase;

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

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('action_bulk_test');

  public static function getInfo() {
    return array(
      'name' => 'Bulk form',
      'description' => 'Tests the views bulk form test.',
      'group' => 'Action',
    );
  }

  /**
   * Tests the bulk form.
   */
  public function testBulkForm() {
    $nodes = array();
    for ($i = 0; $i < 10; $i++) {
      $nodes[] = $this->drupalCreateNode(array('sticky' => FALSE));
    }

    $this->drupalGet('test_bulk_form');

    $this->assertFieldById('edit-action', NULL, 'The action select field appears.');

    // Make sure a checkbox appears on all rows.
    $edit = array();
    for ($i = 0; $i < 10; $i++) {
      $this->assertFieldById('edit-bulk-form-' . $i, NULL, format_string('The checkbox on row @row appears.', array('@row' => $i)));
      $edit["bulk_form[$i]"] = TRUE;
    }

    // Set all nodes to sticky and check that.
    $edit += array('action' => 'node_make_sticky_action');
    $this->drupalPost(NULL, $edit, t('Update'));

    foreach ($nodes as $node) {
      $changed_node = node_load($node->id());
      $this->assertTrue($changed_node->sticky, format_string('Node @nid got marked as sticky.', array('@nid' => $node->id())));
    }

    $this->assertText('Make content sticky action performed on 10 item(s).');

    // Unpublish just one node.
    $node = node_load($nodes[0]->id());
    $this->assertTrue($node->status, 'The node is published.');

    $edit = array('bulk_form[0]' => TRUE, 'action' => 'node_unpublish_action');
    $this->drupalPost(NULL, $edit, t('Update'));

    $this->assertText('Unpublish content action performed on 1 item(s).');

    // Load the node again.
    $node = node_load($node->id(), TRUE);
    $this->assertFalse($node->status, 'A single node has been unpublished.');

    // The second node should still be published.
    $node = node_load($nodes[1]->id(), TRUE);
    $this->assertTrue($node->status, 'An unchecked node is still published.');
  }

}