diff --git a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php index 5cfac80..4893c54 100644 --- a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php +++ b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php @@ -104,16 +104,20 @@ protected function assertCacheTags(array $expected_tags) { * The expected cache contexts. * @param string $message * (optional) A verbose message to output. + * + * @return + * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertCacheContexts(array $expected_contexts, $message = NULL) { $actual_contexts = $this->getCacheHeaderValues('X-Drupal-Cache-Contexts'); sort($expected_contexts); sort($actual_contexts); - $this->assertIdentical($actual_contexts, $expected_contexts, $message); - if ($actual_contexts !== $expected_contexts) { + $return = $this->assertIdentical($actual_contexts, $expected_contexts, $message); + if (!$return) { debug('Missing cache contexts: ' . implode(',', array_diff($actual_contexts, $expected_contexts))); debug('Unwanted cache contexts: ' . implode(',', array_diff($expected_contexts, $actual_contexts))); } + return $return; } /** diff --git a/core/modules/toolbar/src/Tests/ToolbarCacheContextsTest.php b/core/modules/toolbar/src/Tests/ToolbarCacheContextsTest.php index 0bf88b0..fb8c14c 100644 --- a/core/modules/toolbar/src/Tests/ToolbarCacheContextsTest.php +++ b/core/modules/toolbar/src/Tests/ToolbarCacheContextsTest.php @@ -100,6 +100,9 @@ public function testToolbarCacheContextsCaller() { * Expected cache contexts for both users. * @param string $message * (optional) A verbose message to output. + * + * @return + * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertToolbarCacheContexts(array $cache_contexts, $message = NULL) { // Default cache contexts that should exist on all test cases. @@ -112,13 +115,21 @@ protected function assertToolbarCacheContexts(array $cache_contexts, $message = // Assert contexts for user1 which has only default permissions. $this->drupalLogin($this->adminUser); $this->drupalGet('test-page'); - $this->assertCacheContexts($cache_contexts, $message); + $return = $this->assertCacheContexts($cache_contexts); $this->drupalLogout(); // Assert contexts for user2 which has some additional permissions. $this->drupalLogin($this->adminUser2); $this->drupalGet('test-page'); - $this->assertCacheContexts($cache_contexts, $message); + $return = $return && $this->assertCacheContexts($cache_contexts); + + if ($return) { + $this->pass($message); + } + else { + $this->fail($message); + } + return $return; } /** @@ -130,8 +141,9 @@ protected function assertToolbarCacheContexts(array $cache_contexts, $message = protected function installModules(array $module_list) { \Drupal::service('module_installer')->install($module_list); - // Caches have to be rebuilt since modules might have added some routes. - drupal_flush_all_caches(); + // Installing modules updates the container and needs a router rebuild. + $this->container = \Drupal::getContainer(); + $this->container->get('router.builder')->rebuildIfNeeded(); }