You are here

function FileScanDirectoryTest::testReturn in SimpleTest 7

Check the format of the returned values.

File

tests/file.test, line 828
This provides SimpleTests for the core file handling functionality. These include FileValidateTest and FileSaveTest.

Class

FileScanDirectoryTest
Tests the file_scan_directory() function.

Code

function testReturn() {

  // Grab a listing of all the JavaSscript 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), t('Found two, expected javascript files.'));

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

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