From 9a7611b7b6ee79c8cc0fc60a8711a4a8492bdaa1 Mon Sep 17 00:00:00 2001 From: Jean Valverde <600163+mogtofu33@users.noreply.github.com> Date: Sun, 26 Apr 2020 11:25:11 +0200 Subject: [PATCH 1/3] Add Drupal 8.8 support. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4fced1a..4b537af 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "require": { "php": ">=7.1", "composer-plugin-api": "^1.1", - "drupal/core": "~8.7.0", + "drupal/core": "~8.7 || ~8.8", "monolog/monolog": "^1.3", "nesbot/carbon": "^1.24", "symfony/config": "^3.4 || >=4.0 <4.3", From 84689ba8b56fe00d300e18614c2964ba9bed3b4d Mon Sep 17 00:00:00 2001 From: Jean Valverde Date: Sun, 26 Apr 2020 15:02:29 +0200 Subject: [PATCH 2/3] feat(action): add action debug_cacheability_header --- README.md | 1 + .../AbstractOverrideBoolParameterAction.php | 42 ++++++++++++++++ .../EnableDebugCacheabilityHeaderAction.php | 35 +++++++++++++ src/ActionMetadata/ActionMetadataManager.php | 6 +++ ...nableDebugCacheabilityHeaderActionTest.php | 50 +++++++++++++++++++ .../Composer/Helper/fixtures/drupal-debug.yml | 2 + 6 files changed, 136 insertions(+) create mode 100644 src/Action/AbstractOverrideBoolParameterAction.php create mode 100644 src/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderAction.php create mode 100644 tests/Integration/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderActionTest.php diff --git a/README.md b/README.md index 0e91eb1..7a881a9 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Here is the list of the current available actions and how they help you: | Display Dump Location | Display location when you use the `dump()` function of the Symfony VarDumper component | | Display Pretty Exceptions | Display a better looking exception page and log exceptions (active when the `Request` is handled by the Kernel and if the exceptions are caught) | | Display Pretty Exceptions ASAP | Display a better looking exception page (active as soon as the Kernel is instantiated) | +| Enable Cacheability header | Enable the [debug_cacheability_header](https://www.drupal.org/docs/8/api/responses/cacheableresponseinterface#debugging) | | Enable Debug Class Loader | Enable the `DebugClassLoader` of the Symfony Debug component | | Enable Twig Debug | Enable Twig Debug mode | | ~~Enable Twig Strict Variables~~ | ~~Enable Twig `strict_variables` option~~ (disabled at the moment because the [Drupal core is not ready](https://www.drupal.org/project/drupal/issues/2445705) at all) | diff --git a/src/Action/AbstractOverrideBoolParameterAction.php b/src/Action/AbstractOverrideBoolParameterAction.php new file mode 100644 index 0000000..f43e13d --- /dev/null +++ b/src/Action/AbstractOverrideBoolParameterAction.php @@ -0,0 +1,42 @@ +hasParameter(static::getParameterId())) { + throw new NotSupportedException(\sprintf('The "%s" parameter should already be set in the container builder.', static::getParameterId())); + } + + $container->setParameter(static::getParameterId(), $this->getOverride()); + } + + /** + * @return string + */ + abstract protected static function getParameterId(): string; + + /** + * @return bool + */ + abstract protected function getOverride(): bool; +} diff --git a/src/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderAction.php b/src/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderAction.php new file mode 100644 index 0000000..26e37cc --- /dev/null +++ b/src/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderAction.php @@ -0,0 +1,35 @@ + array( + ActionMetadata::class, + EnableDebugCacheabilityHeaderAction::class, + array(), + ), 'enable_debug_class_loader' => array( ActionMetadata::class, EnableDebugClassLoaderAction::class, diff --git a/tests/Integration/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderActionTest.php b/tests/Integration/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderActionTest.php new file mode 100644 index 0000000..72e92c1 --- /dev/null +++ b/tests/Integration/Action/EnableDebugCacheabilityHeader/EnableDebugCacheabilityHeaderActionTest.php @@ -0,0 +1,50 @@ +executeScenario($client)); + $this->assertNotContains(array('X-Drupal-Cache-Tags', 'X-Drupal-Cache-Contexts'), $headers); + } + + /** + * {@inheritdoc} + */ + protected function doTestTargetedBehaviorWithDebugKernel(Client $client): void + { + $headers = $this->executeScenario($client); + $this->assertArrayHasKey('X-Drupal-Cache-Tags', $headers); + $this->assertArrayHasKey('X-Drupal-Cache-Contexts', $headers); + } + + private function executeScenario(Client $client): array + { + $client->request('GET', '/'); + + /** @var Response $response */ + $response = $client->getResponse(); + + return $response->getHeaders(); + } +} diff --git a/tests/Unit/src/Composer/Helper/fixtures/drupal-debug.yml b/tests/Unit/src/Composer/Helper/fixtures/drupal-debug.yml index 4f4ab74..4e94a73 100644 --- a/tests/Unit/src/Composer/Helper/fixtures/drupal-debug.yml +++ b/tests/Unit/src/Composer/Helper/fixtures/drupal-debug.yml @@ -34,6 +34,8 @@ drupal-debug: enabled: true charset: null file_link_format: null + enable_debug_cacheability_header: + enabled: true enable_debug_class_loader: enabled: true enable_twig_debug: From 72db8aa8f11020dce6a780bcb104d0c7bb260e92 Mon Sep 17 00:00:00 2001 From: Jean Valverde Date: Wed, 6 May 2020 10:31:27 +0200 Subject: [PATCH 3/3] Fix tests. --- tests/Unit/src/Action/ActionRegistrarTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Unit/src/Action/ActionRegistrarTest.php b/tests/Unit/src/Action/ActionRegistrarTest.php index 49f095e..c1d285a 100644 --- a/tests/Unit/src/Action/ActionRegistrarTest.php +++ b/tests/Unit/src/Action/ActionRegistrarTest.php @@ -23,6 +23,7 @@ use Ekino\Drupal\Debug\Action\DisplayDumpLocation\DisplayDumpLocationAction; use Ekino\Drupal\Debug\Action\DisplayPrettyExceptions\DisplayPrettyExceptionsAction; use Ekino\Drupal\Debug\Action\DisplayPrettyExceptionsASAP\DisplayPrettyExceptionsASAPAction; +use Ekino\Drupal\Debug\Action\EnableDebugCacheabilityHeader\EnableDebugCacheabilityHeaderAction; use Ekino\Drupal\Debug\Action\EnableDebugClassLoader\EnableDebugClassLoaderAction; use Ekino\Drupal\Debug\Action\EnableTwigDebug\EnableTwigDebugAction; use Ekino\Drupal\Debug\Action\EnableTwigStrictVariables\EnableTwigStrictVariablesAction; @@ -122,11 +123,12 @@ public function testAddCompilerPassActionsToContainerBuilder(): void { $containerBuilder = $this->createMock(ContainerBuilder::class); $containerBuilder - ->expects($this->exactly(5)) + ->expects($this->exactly(6)) ->method('addCompilerPass') ->withConsecutive( array($this->isInstanceOf(DisableTwigCacheAction::class)), array($this->isInstanceOf(DisplayPrettyExceptionsAction::class)), + array($this->isInstanceOf(EnableDebugCacheabilityHeaderAction::class)), array($this->isInstanceOf(EnableTwigDebugAction::class)), array($this->isInstanceOf(EnableTwigStrictVariablesAction::class)), array($this->isInstanceOf(WatchModulesHooksImplementationsAction::class))