function ScanDirectoryTest::testOptionKey
Same name in other branches
- 9 core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php \Drupal\KernelTests\Core\File\ScanDirectoryTest::testOptionKey()
- 10 core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php \Drupal\KernelTests\Core\File\ScanDirectoryTest::testOptionKey()
- 11.x core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php \Drupal\KernelTests\Core\File\ScanDirectoryTest::testOptionKey()
Check that key parameter sets the return value's key.
@covers ::scanDirectory
File
-
core/
tests/ Drupal/ KernelTests/ Core/ File/ ScanDirectoryTest.php, line 115
Class
- ScanDirectoryTest
- Tests \Drupal\Core\File\FileSystem::scanDirectory.
Namespace
Drupal\KernelTests\Core\FileCode
public function testOptionKey() {
// "filename", for the path starting with $dir.
$expected = [
$this->path . '/javascript-1.txt',
$this->path . '/javascript-2.script',
];
$actual = array_keys($this->fileSystem
->scanDirectory($this->path, '/^javascript-/', [
'key' => 'filepath',
]));
sort($actual);
$this->assertEqual($expected, $actual, 'Returned the correct values for the filename key.');
// "basename", for the basename of the file.
$expected = [
'javascript-1.txt',
'javascript-2.script',
];
$actual = array_keys($this->fileSystem
->scanDirectory($this->path, '/^javascript-/', [
'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 = [
'javascript-1',
'javascript-2',
];
$actual = array_keys($this->fileSystem
->scanDirectory($this->path, '/^javascript-/', [
'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 = [
$this->path . '/javascript-1.txt',
$this->path . '/javascript-2.script',
];
$actual = array_keys($this->fileSystem
->scanDirectory($this->path, '/^javascript-/', [
'key' => 'INVALID',
]));
sort($actual);
$this->assertEqual($expected, $actual, 'An invalid key defaulted back to the default.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.