diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php index 77fdc08..f87d87a 100644 --- a/core/modules/language/src/Plugin/Condition/Language.php +++ b/core/modules/language/src/Plugin/Condition/Language.php @@ -143,7 +143,8 @@ public function evaluate() { $language = $this->getContextValue('language'); // Language visibility settings. - return !empty($this->configuration['langcodes'][$language->getId()]); + $result = !empty($this->configuration['langcodes'][$language->getId()]); + return $this->configuration['negate'] ? !$result : $result; } /** diff --git a/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php b/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php index 3b82d48..46eb74c 100644 --- a/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php +++ b/core/modules/system/src/Plugin/Condition/CurrentThemeCondition.php @@ -109,7 +109,9 @@ public function evaluate() { return TRUE; } - return $this->themeManager->getActiveTheme()->getName() == $this->configuration['theme']; + $result = $this->themeManager->getActiveTheme()->getName() == $this->configuration['theme']; + + return $this->configuration['negate'] ? !$result : $result; } /** diff --git a/core/modules/system/src/Plugin/Condition/RequestPath.php b/core/modules/system/src/Plugin/Condition/RequestPath.php index 64331be..0e1a6d0 100644 --- a/core/modules/system/src/Plugin/Condition/RequestPath.php +++ b/core/modules/system/src/Plugin/Condition/RequestPath.php @@ -148,15 +148,18 @@ public function evaluate() { // with different case. Ex: /Page, /page, /PAGE. $pages = Unicode::strtolower($this->configuration['pages']); if (!$pages) { - return TRUE; + $result = TRUE; } + else { + $request = $this->requestStack->getCurrentRequest(); + // Compare the lowercase path alias (if any) and internal path. + $path = rtrim($this->currentPath->getPath($request), '/'); + $path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path)); - $request = $this->requestStack->getCurrentRequest(); - // Compare the lowercase path alias (if any) and internal path. - $path = rtrim($this->currentPath->getPath($request), '/'); - $path_alias = Unicode::strtolower($this->aliasManager->getAliasByPath($path)); + $result = $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages)); + } - return $this->pathMatcher->matchPath($path_alias, $pages) || (($path != $path_alias) && $this->pathMatcher->matchPath($path, $pages)); + return $this->configuration['negate'] ? !$result : $result; } /** diff --git a/core/tests/Drupal/Tests/Core/Condition/ConditionManagerTest.php b/core/tests/Drupal/Tests/Core/Condition/ConditionManagerTest.php new file mode 100644 index 0000000..2603827 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Condition/ConditionManagerTest.php @@ -0,0 +1,77 @@ +moduleHandler = $this->getMock('\Drupal\Core\Extension\ModuleHandlerInterface'); + + $this->cache = $this->getMock('\Drupal\Core\Cache\CacheBackendInterface'); + + $namespaces = new ArrayObject(); + + $this->sut = new ConditionManager($namespaces, $this->cache, $this->moduleHandler); + } + + /** + * @covers ::__construct + */ + public function testConstruct() { + $namespaces = new ArrayObject(); + $this->sut = new ConditionManager($namespaces, $this->cache, $this->moduleHandler); + } + + /** + * @covers ::execute + */ + public function testExecute() { + $execution_result = $this->randomMachineName(); + + $condition = $this->getMock('\Drupal\Core\Condition\ConditionInterface'); + $condition->expects($this->atLeastOnce()) + ->method('evaluate') + ->willReturn($execution_result); + + $this->assertSame($execution_result, $this->sut->execute($condition)); + } + +}