commit ab8bbc722de26bb2078942ce861989f76f28a055 Author: Greg Anderson Date: Thu May 30 08:30:19 2019 -0700 Add marker interface ConjoinableInterface. Add a test of appending to a scaffold file that has already been appended to. diff --git a/core/lib/Drupal/Component/Scaffold/Operations/AppendOp.php b/core/lib/Drupal/Component/Scaffold/Operations/AppendOp.php index d4d58b1b33..d8ca757a4d 100644 --- a/core/lib/Drupal/Component/Scaffold/Operations/AppendOp.php +++ b/core/lib/Drupal/Component/Scaffold/Operations/AppendOp.php @@ -9,7 +9,7 @@ /** * Scaffold operation to add to the beginning and/or end of a scaffold file. */ -class AppendOp implements OperationInterface { +class AppendOp implements OperationInterface, ConjoinableInterface { /** * Path to the source file to prepend, if any. diff --git a/core/lib/Drupal/Component/Scaffold/Operations/ConjoinableInterface.php b/core/lib/Drupal/Component/Scaffold/Operations/ConjoinableInterface.php new file mode 100644 index 0000000000..4f494173fa --- /dev/null +++ b/core/lib/Drupal/Component/Scaffold/Operations/ConjoinableInterface.php @@ -0,0 +1,15 @@ + $op) { $destination = ScaffoldFilePath::destinationPath($package_name, $destination_rel_path, $location_replacements); // If there was already a scaffolding operation happening at this path, - // AppendOp operations can be joined to the previous operation using a - // ConjunctionOp. - if (isset($list_of_scaffold_files[$destination_rel_path]) && $op instanceof AppendOp) { + // and the new operation is Conjoinable, then use a ConjunctionOp to + // join together both operations. This will cause both operations to + // run, one after the other. At the moment, only AppendOp is conjoinable; + // all other operations simply replace anything at the same path. + if (isset($list_of_scaffold_files[$destination_rel_path]) && $op instanceof ConjoinableInterface) { $op = new ConjunctionOp($list_of_scaffold_files[$destination_rel_path]->op(), $op); } diff --git a/core/tests/Drupal/Tests/Component/Scaffold/Functional/ScaffoldTest.php b/core/tests/Drupal/Tests/Component/Scaffold/Functional/ScaffoldTest.php index 3e733c2ad2..0c18b2b5ff 100644 --- a/core/tests/Drupal/Tests/Component/Scaffold/Functional/ScaffoldTest.php +++ b/core/tests/Drupal/Tests/Component/Scaffold/Functional/ScaffoldTest.php @@ -138,7 +138,8 @@ public function scaffoldTestValues() { return [ [ 'drupal-composer-drupal-project', - 'assertDrupalProjectSutWasScaffolded', TRUE, + 'assertDrupalProjectSutWasScaffolded', + TRUE, ], [ 'drupal-drupal', @@ -155,6 +156,11 @@ public function scaffoldTestValues() { 'assertDrupalDrupalFileWasAppended', FALSE, ], + [ + 'drupal-drupal-append-to-append', + 'assertFileWasAppendedToAppendedFile', + FALSE, + ], [ 'drupal-drupal-test-append', 'assertDrupalDrupalFileWasAppended', @@ -338,6 +344,12 @@ protected function assertDrupalDrupalFileWasAppended($sut, $is_link, $project_na $this->assertCommonDrupalAssetsWereScaffolded($docroot, $is_link); } + protected function assertFileWasAppendedToAppendedFile($sut, $is_link, $project_name) { + $docroot = $sut; + $this->assertScaffoldedFile($docroot . '/robots.txt', FALSE, '#in drupal-drupal-append-to-append composer.json fixture.*This content is prepended to the top of the existing robots.txt fixture.*Test version of robots.txt from drupal/core.*This content is appended to the bottom of the existing robots.txt fixture.*in profile-with-append composer.json fixture.*This content is appended to the bottom of the existing robots.txt fixture.*in drupal-drupal-append-to-append composer.json fixture#ms'); + $this->assertCommonDrupalAssetsWereScaffolded($docroot, $is_link, $project_name); + } + /** * Asserts that the scaffold files from drupal/assets are placed as expected. * diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/assets/append-to-robots.txt b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/assets/append-to-robots.txt new file mode 100644 index 0000000000..5290d32590 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/assets/append-to-robots.txt @@ -0,0 +1,3 @@ +# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +# This content is appended to the bottom of the existing robots.txt fixture. +# robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-append-to-append composer.json fixture. diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/assets/prepend-to-robots.txt b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/assets/prepend-to-robots.txt new file mode 100644 index 0000000000..8f7550ff5e --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/assets/prepend-to-robots.txt @@ -0,0 +1,3 @@ +# robots.txt fixture scaffolded from "file-mappings" in drupal-drupal-append-to-append composer.json fixture. +# This content is prepended to the top of the existing robots.txt fixture. +# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/composer.json.tmpl b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/composer.json.tmpl new file mode 100644 index 0000000000..1919d878c6 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/drupal-drupal-append-to-append/composer.json.tmpl @@ -0,0 +1,71 @@ +{ + "name": "fixtures/drupal-drupal-test-append", + "type": "project", + "minimum-stability": "dev", + "prefer-stable": true, + "repositories": { + "composer-scaffold": { + "type": "path", + "url": "__PROJECT_ROOT__", + "options": { + "symlink": true + } + }, + "drupal-core-fixture": { + "type": "path", + "url": "../drupal-core-fixture", + "options": { + "symlink": true + } + }, + "profile-with-append": { + "type": "path", + "url": "../profile-with-append", + "options": { + "symlink": true + } + }, + "drupal-assets-fixture": { + "type": "path", + "url": "../drupal-assets-fixture", + "options": { + "symlink": true + } + } + }, + "require": { + "drupal/core-composer-scaffold": "*", + "fixtures/profile-with-append": "*", + "fixtures/drupal-core-fixture": "*" + }, + "extra": { + "composer-scaffold": { + "allowed-packages": [ + "fixtures/drupal-core-fixture", + "fixtures/profile-with-append" + ], + "locations": { + "web-root": "./" + }, + "symlink": __SYMLINK__, + "file-mapping": { + "[web-root]/.htaccess": false, + "[web-root]/robots.txt": { + "prepend": "assets/prepend-to-robots.txt", + "append": "assets/append-to-robots.txt" + } + } + }, + "installer-paths": { + "core": ["type:drupal-core"], + "modules/contrib/{$name}": ["type:drupal-module"], + "modules/custom/{$name}": ["type:drupal-custom-module"], + "profiles/contrib/{$name}": ["type:drupal-profile"], + "profiles/custom/{$name}": ["type:drupal-custom-profile"], + "themes/contrib/{$name}": ["type:drupal-theme"], + "themes/custom/{$name}": ["type:drupal-custom-theme"], + "libraries/{$name}": ["type:drupal-library"], + "drush/Commands/contrib/{$name}": ["type:drupal-drush"] + } + } +} diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/profile-with-append/assets/append-to-robots.txt b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/profile-with-append/assets/append-to-robots.txt new file mode 100644 index 0000000000..ab2eb43a74 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/profile-with-append/assets/append-to-robots.txt @@ -0,0 +1,3 @@ +# :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +# This content is appended to the bottom of the existing robots.txt fixture. +# robots.txt fixture scaffolded from "file-mappings" in profile-with-append composer.json fixture. diff --git a/core/tests/Drupal/Tests/Component/Scaffold/fixtures/profile-with-append/composer.json.tmpl b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/profile-with-append/composer.json.tmpl new file mode 100644 index 0000000000..d67135fcac --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Scaffold/fixtures/profile-with-append/composer.json.tmpl @@ -0,0 +1,12 @@ +{ + "name": "fixtures/profile-with-append", + "extra": { + "composer-scaffold": { + "file-mapping": { + "[web-root]/robots.txt": { + "append": "assets/append-to-robots.txt" + } + } + } + } +}