public function BulkFormTest::testBulkForm

Tests the bulk form.

File

drupal/core/modules/action/lib/Drupal/action/Tests/BulkFormTest.php, line 37
Contains \Drupal\action\Tests\BulkFormTest.

Class

BulkFormTest
Tests the views bulk form test.

Namespace

Drupal\action\Tests

Code

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.');
}