You are here

public function ScanDirectoryTest::testReturn in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php \Drupal\KernelTests\Core\File\ScanDirectoryTest::testReturn()

Check the format of the returned values.

@covers ::scanDirectory

File

core/tests/Drupal/KernelTests/Core/File/ScanDirectoryTest.php, line 50

Class

ScanDirectoryTest
Tests \Drupal\Core\File\FileSystem::scanDirectory.

Namespace

Drupal\KernelTests\Core\File

Code

public function testReturn() {

  // Grab a listing of all the JavaScript files and check that they're
  // passed to the callback.
  $all_files = $this->fileSystem
    ->scanDirectory($this->path, '/^javascript-/');
  ksort($all_files);
  $this
    ->assertCount(2, $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.');
}