You are here

function ScanDirectoryTest::testReturn in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/File/ScanDirectoryTest.php \Drupal\system\Tests\File\ScanDirectoryTest::testReturn()

Check the format of the returned values.

File

core/modules/system/src/Tests/File/ScanDirectoryTest.php, line 41
Contains \Drupal\system\Tests\File\ScanDirectoryTest.

Class

ScanDirectoryTest
Tests the file_scan_directory() function.

Namespace

Drupal\system\Tests\File

Code

function testReturn() {

  // Grab a listing of all the JavaScript files and check that they're
  // passed to the callback.
  $all_files = file_scan_directory($this->path, '/^javascript-/');
  ksort($all_files);
  $this
    ->assertEqual(2, count($all_files), 'Found two, expected javascript files.');

  // Check the first file.
  $file = reset($all_files);
  $this
    ->assertEqual(key($all_files), $file->uri, 'Correct array key was used for the first returned file.');
  $this
    ->assertEqual($file->uri, $this->path . '/javascript-1.txt', 'First file name was set correctly.');
  $this
    ->assertEqual($file->filename, 'javascript-1.txt', 'First basename was set correctly');
  $this
    ->assertEqual($file->name, 'javascript-1', 'First name was set correctly.');

  // Check the second file.
  $file = next($all_files);
  $this
    ->assertEqual(key($all_files), $file->uri, 'Correct array key was used for the second returned file.');
  $this
    ->assertEqual($file->uri, $this->path . '/javascript-2.script', 'Second file name was set correctly.');
  $this
    ->assertEqual($file->filename, 'javascript-2.script', 'Second basename was set correctly');
  $this
    ->assertEqual($file->name, 'javascript-2', 'Second name was set correctly.');
}