You are here

public function ComposerProjectTemplatesTest::testVerifyTemplateTestProviderIsAccurate in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php \Drupal\BuildTests\Composer\Template\ComposerProjectTemplatesTest::testVerifyTemplateTestProviderIsAccurate()

Make sure we've accounted for all the templates.

File

core/tests/Drupal/BuildTests/Composer/Template/ComposerProjectTemplatesTest.php, line 76

Class

ComposerProjectTemplatesTest
Demonstrate that Composer project templates are buildable as patched.

Namespace

Drupal\BuildTests\Composer\Template

Code

public function testVerifyTemplateTestProviderIsAccurate() {
  $root = $this
    ->getDrupalRoot();
  $data = $this
    ->provideTemplateCreateProject($root);

  // Find all the templates.
  $template_files = Finder::create()
    ->files()
    ->name('composer.json')
    ->in($root . '/composer/Template');
  $this
    ->assertEquals(count($template_files), count($data));

  // We could have the same number of templates but different names.
  $template_data = [];
  foreach ($data as $data_name => $data_value) {
    $template_data[$data_value[0]] = $data_name;
  }

  /* @var $file \SplFileInfo */
  foreach ($template_files as $file) {
    $json_file = new JsonFile($file
      ->getPathname());
    $json = $json_file
      ->read();
    $this
      ->assertArrayHasKey('name', $json);

    // Does provideTemplateCreateProject() give us this template name?
    $this
      ->assertArrayHasKey($json['name'], $template_data);
  }
}