You are here

public function ComposerProjectTemplatesTest::testVerifyTemplateTestProviderIsAccurate in Drupal 9

Same name and namespace in other branches
  1. 8 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 107

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 = Composer::composerSubprojectPaths($root, 'Template');
  $this
    ->assertSameSize($template_files, $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 \SplFileInfo $file */
  foreach ($template_files as $file) {
    $json_file = new JsonFile($file
      ->getPathname());
    $json = $json_file
      ->read();
    $this
      ->assertArrayHasKey('name', $json);

    // Assert that the template name is in the project created
    // from the template.
    $this
      ->assertArrayHasKey($json['name'], $template_data);
  }
}