You are here

function ScanDirectoryTest::testOptionKey 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::testOptionKey()

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

File

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

Class

ScanDirectoryTest
Tests the file_scan_directory() function.

Namespace

Drupal\system\Tests\File

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, '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, '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, '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, 'An invalid key defaulted back to the default.');
}