FileScanDirectoryTest::testOptionKey

7 file.test FileScanDirectoryTest::testOptionKey()
8 file.test FileScanDirectoryTest::testOptionKey()

Check that key parameter sets the return value's key.

File

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

Code

function testOptionKey() {
  // "filename", for the path starting with $dir.
  $expected = array($this->path . '/javascript-1.txt', $this->path . '/javascript-2.script');
  $actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'filepath')));
  sort($actual);
  $this->assertEqual($expected, $actual, t('Returned the correct values for the filename key.'));

  // "basename", for the basename of the file.
  $expected = array('javascript-1.txt', 'javascript-2.script');
  $actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'filename')));
  sort($actual);
  $this->assertEqual($expected, $actual, t('Returned the correct values for the basename key.'));

  // "name" for the name of the file without an extension.
  $expected = array('javascript-1', 'javascript-2');
  $actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'name')));
  sort($actual);
  $this->assertEqual($expected, $actual, t('Returned the correct values for the name key.'));

  // Invalid option that should default back to "filename".
  $expected = array($this->path . '/javascript-1.txt', $this->path . '/javascript-2.script');
  $actual = array_keys(file_scan_directory($this->path, '/^javascript-/', array('key' => 'INVALID')));
  sort($actual);
  $this->assertEqual($expected, $actual, t('An invalid key defaulted back to the default.'));
}
Login or register to post comments