You are here

function NodeAdminTestCase::testContentAdminSort in Drupal 7

Tests that the table sorting works on the content admin pages.

File

modules/node/node.test, line 1797
Tests for node.module.

Class

NodeAdminTestCase
Tests node administration page functionality.

Code

function testContentAdminSort() {
  $this
    ->drupalLogin($this->admin_user);
  foreach (array(
    'dd',
    'aa',
    'DD',
    'bb',
    'cc',
    'CC',
    'AA',
    'BB',
  ) as $prefix) {
    $this
      ->drupalCreateNode(array(
      'title' => $prefix . $this
        ->randomName(6),
    ));
  }

  // Test that the default sort by node.changed DESC actually fires properly.
  $nodes_query = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ))
    ->orderBy('changed', 'DESC')
    ->execute()
    ->fetchCol();
  $nodes_form = array();
  $this
    ->drupalGet('admin/content');
  foreach ($this
    ->xpath('//table/tbody/tr/td/div/input/@value') as $input) {
    $nodes_form[] = $input;
  }
  $this
    ->assertEqual($nodes_query, $nodes_form, 'Nodes are sorted in the form according to the default query.');

  // Compare the rendered HTML node list to a query for the nodes ordered by
  // title to account for possible database-dependent sort order.
  $nodes_query = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ))
    ->orderBy('title')
    ->execute()
    ->fetchCol();
  $nodes_form = array();
  $this
    ->drupalGet('admin/content', array(
    'query' => array(
      'sort' => 'asc',
      'order' => 'Title',
    ),
  ));
  foreach ($this
    ->xpath('//table/tbody/tr/td/div/input/@value') as $input) {
    $nodes_form[] = $input;
  }
  $this
    ->assertEqual($nodes_query, $nodes_form, 'Nodes are sorted in the form the same as they are in the query.');
}