1 file.test FileAdminTestCase::testFilesAdminSort()

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

File

core/modules/file/tests/file.test, line 2801
Tests for file.module.

Class

FileAdminTestCase
Test file administration page functionality.

Code

function testFilesAdminSort() {
  $this->backdropLogin($this->admin_user);
  $i = 0;
  foreach (array('dd', 'aa', 'DD', 'bb', 'cc', 'CC', 'AA', 'BB') as $prefix) {
    $this->createFile(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->backdropGet('admin/content/files');
  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->backdropGet('admin/content/files', array('query' => array('sort' => 'asc', 'order' => 'filename')));
  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.');
}