You are here

function MediaBrowserLibraryTestCase::testFilesBrowserSort in D7 Media 7.3

Same name and namespace in other branches
  1. 7.4 tests/media.test \MediaBrowserLibraryTestCase::testFilesBrowserSort()
  2. 7.2 tests/media.test \MediaBrowserLibraryTestCase::testFilesBrowserSort()

Tests that the views sorting works on the media browser 'Library' tab.

File

tests/media.test, line 536
Tests for media.module.

Class

MediaBrowserLibraryTestCase
Tests the media browser 'Library' tab.

Code

function testFilesBrowserSort() {

  // Load only the 'Library' tab of the media browser.
  $options = array(
    'query' => array(
      'enabledPlugins' => array(
        'media_default--media_browser_1' => 'media_default--media_browser_1',
      ),
    ),
  );
  $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('media/browser', $options);
  foreach ($this
    ->xpath('//ul[@class="media-list-thumbnails"]/li/div[@data-fid]/@data-fid') as $input) {
    $files_form[] = $input;
  }
  $this
    ->assertEqual($files_query, $files_form, 'Files are sorted in the form according to the default query.');
}