You are here

public function ComposerIntegrationTest::testExpectedScaffoldFiles in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/ComposerIntegrationTest.php \Drupal\Tests\ComposerIntegrationTest::testExpectedScaffoldFiles()

Tests core's composer.json extra drupal-scaffold file-mappings section.

Verify that every file listed in file-mappings exists in its destination path (mapping key) and also at its source path (mapping value), and that both of these files have exactly the same content.

In Drupal 9, the files at the destination path will be removed. For the remainder of the Drupal 8 development cycle, these files will remain in order to maintain backwards compatibility with sites based on the template project drupal-composer/drupal-project.

See https://www.drupal.org/project/drupal/issues/3075954

@dataProvider providerTestExpectedScaffoldFiles

Parameters

string $destRelPath: Path to scaffold file destination location

string $sourceRelPath: Path to scaffold file source location

string $expectedDestination: Named location to the destination path of the scaffold file

File

core/tests/Drupal/Tests/ComposerIntegrationTest.php, line 189

Class

ComposerIntegrationTest
Tests Composer integration.

Namespace

Drupal\Tests

Code

public function testExpectedScaffoldFiles($destRelPath, $sourceRelPath, $expectedDestination = '[web-root]') {

  // Grab the 'file-mapping' section of the core composer.json file.
  $json = json_decode(file_get_contents($this->root . '/core/composer.json'));
  $scaffold_file_mapping = (array) $json->extra->{'drupal-scaffold'}->{'file-mapping'};

  // Assert that the 'file-mapping' section has the expected entry.
  $this
    ->assertArrayHasKey("{$expectedDestination}/{$destRelPath}", $scaffold_file_mapping);
  $this
    ->assertEquals($sourceRelPath, $scaffold_file_mapping["{$expectedDestination}/{$destRelPath}"]);

  // Assert that the source file exists.
  $this
    ->assertFileExists($this->root . '/core/' . $sourceRelPath);

  // Assert that the destination file exists and has the same contents as
  // the source file. Note that in Drupal 9, the destination file will be
  // removed.
  $this
    ->assertFileExists($this->root . '/' . $destRelPath);
  $this
    ->assertFileEquals($this->root . '/core/' . $sourceRelPath, $this->root . '/' . $destRelPath, 'Scaffold source and destination files must have the same contents.');
}