You are here

function FileEntityAdminTestCase::testFilesAdminSort in File Entity (fieldable files) 7.2

Same name and namespace in other branches
  1. 7.3 file_entity.test \FileEntityAdminTestCase::testFilesAdminSort()

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

File

./file_entity.test, line 674
Test integration for the file_entity module.

Class

FileEntityAdminTestCase
Test file administration page functionality.

Code

function testFilesAdminSort() {
  $this
    ->drupalLogin($this->admin_user);
  $i = 0;
  foreach (array(
    'dd',
    'aa',
    'DD',
    'bb',
    'cc',
    'CC',
    'AA',
    'BB',
  ) as $prefix) {
    $this
      ->createFileEntity(array(
      'filepath' => $prefix . $this
        ->randomName(6),
      'timestamp' => $i,
    ));
    $i++;
  }

  // Test that the default sort by file_managed.timestamp DESC actually fires properly.
  $files_query = db_select('file_managed', 'fm')
    ->fields('fm', array(
    'fid',
  ))
    ->orderBy('timestamp', 'DESC')
    ->execute()
    ->fetchCol();
  $files_form = array();
  $this
    ->drupalGet('admin/content/file');
  foreach ($this
    ->xpath('//table/tbody/tr/td/div/input/@value') as $input) {
    $files_form[] = $input;
  }
  $this
    ->assertEqual($files_query, $files_form, 'Files are sorted in the form according to the default query.');

  // Compare the rendered HTML node list to a query for the files ordered by
  // filename to account for possible database-dependent sort order.
  $files_query = db_select('file_managed', 'fm')
    ->fields('fm', array(
    'fid',
  ))
    ->orderBy('filename')
    ->execute()
    ->fetchCol();
  $files_form = array();
  $this
    ->drupalGet('admin/content/file', array(
    'query' => array(
      'sort' => 'asc',
      'order' => 'Title',
    ),
  ));
  foreach ($this
    ->xpath('//table/tbody/tr/td/div/input/@value') as $input) {
    $files_form[] = $input;
  }
  $this
    ->assertEqual($files_query, $files_form, 'Files are sorted in the form the same as they are in the query.');
}