.../rest/tests/src/Functional/ResourceTestBase.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/modules/rest/tests/src/Functional/ResourceTestBase.php b/core/modules/rest/tests/src/Functional/ResourceTestBase.php index d8f171e..4f435c0 100644 --- a/core/modules/rest/tests/src/Functional/ResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/ResourceTestBase.php @@ -119,9 +119,7 @@ public function setUp() { // Ensure there's a clean slate: delete all REST resource config entities. $this->resourceConfigStorage->delete($this->resourceConfigStorage->loadMultiple()); - // If we remove resources we also need to ensure they don't stick in the - // {router} table. - \Drupal::service('router.builder')->rebuild(); + $this->refreshTestStateAfterRestResourceConfigChange(); } /** @@ -144,10 +142,23 @@ protected function provisionResource($resource_type, $formats = [], $authenticat 'authentication' => $authentication, ] ])->save(); + $this->refreshTestStateAfterRestResourceConfigChange(); + } + + /** + * Refreshes the state of the tester to be in sync with the testee. + * + * Should be called after every RestResourceConfig entity change. + */ + protected function refreshTestStateAfterRestResourceConfigChange() { // Ensure that the cache tags invalidator has its internal values reset. // Otherwise the http_response cache tag invalidation won't work. $this->refreshVariables(); - \Drupal::service('router.builder')->rebuild(); + + // Tests using this base class may trigger route rebuilds due to changes to + // RestResourceConfig entities. Ensure we generate routes using an + // up-to-date router. + \Drupal::service('router.builder')->rebuildIfNeeded(); } /**