-
-
Save dawehner/121e2a0e8668f3a8bb043f1d2142f12d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/core/lib/Drupal/Core/Condition/ConditionAccessResolverTrait.php b/core/lib/Drupal/Core/Condition/ConditionAccessResolverTrait.php | |
| index 106eeec..8cee282 100644 | |
| --- a/core/lib/Drupal/Core/Condition/ConditionAccessResolverTrait.php | |
| +++ b/core/lib/Drupal/Core/Condition/ConditionAccessResolverTrait.php | |
| @@ -26,8 +26,11 @@ protected function resolveConditions($conditions, $condition_logic) { | |
| $pass = $condition->execute(); | |
| } | |
| catch (ContextException $e) { | |
| - // If a condition is missing context, consider that a fail. | |
| - $pass = FALSE; | |
| + // A condition is missing context. In case its negated, don't consider | |
| + // it as fail, but rather success. Let's choose for the | |
| + // "Not node:article" condition. In case we are on the frontpage, this | |
| + // condition should return TRUE. | |
| + $pass = $condition->isNegated(); | |
| } | |
| // If a condition fails and all conditions were needed, deny access. | |
| diff --git a/core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php b/core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php | |
| index 00511d3..7bb9a2d 100644 | |
| --- a/core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php | |
| +++ b/core/tests/Drupal/Tests/Core/Condition/ConditionAccessResolverTraitTest.php | |
| @@ -40,10 +40,22 @@ public function providerTestResolveConditions() { | |
| ->method('execute') | |
| ->will($this->returnValue(FALSE)); | |
| $condition_exception = $this->getMock('Drupal\Core\Condition\ConditionInterface'); | |
| + $condition_exception->expects($this->atLeastOnce()) | |
| + ->method('isNegated') | |
| + ->willReturn(FALSE); | |
| $condition_exception->expects($this->any()) | |
| ->method('execute') | |
| ->will($this->throwException(new ContextException())); | |
| + $condition_negated_exception = $this->getMock('Drupal\Core\Condition\ConditionInterface'); | |
| + $condition_negated_exception->expects($this->atLeastOnce()) | |
| + ->method('isNegated') | |
| + ->willReturn(TRUE); | |
| + $condition_negated_exception->expects($this->any()) | |
| + ->method('execute') | |
| + ->will($this->throwException(new ContextException())); | |
| + | |
| + | |
| $conditions = array(); | |
| $data[] = array($conditions, 'and', TRUE); | |
| $data[] = array($conditions, 'or', FALSE); | |
| @@ -79,6 +91,26 @@ public function providerTestResolveConditions() { | |
| $conditions = array($condition_exception, $condition_false); | |
| $data[] = array($conditions, 'or', FALSE); | |
| $data[] = array($conditions, 'and', FALSE); | |
| + | |
| + $conditions = array($condition_negated_exception); | |
| + $data[] = array($conditions, 'or', TRUE); | |
| + $data[] = array($conditions, 'and', TRUE); | |
| + | |
| + $conditions = array($condition_true, $condition_negated_exception); | |
| + $data[] = array($conditions, 'or', TRUE); | |
| + $data[] = array($conditions, 'and', TRUE); | |
| + | |
| + $conditions = array($condition_negated_exception, $condition_true); | |
| + $data[] = array($conditions, 'or', TRUE); | |
| + $data[] = array($conditions, 'and', TRUE); | |
| + | |
| + $conditions = array($condition_false, $condition_negated_exception); | |
| + $data[] = array($conditions, 'or', TRUE); | |
| + $data[] = array($conditions, 'and', FALSE); | |
| + | |
| + $conditions = array($condition_negated_exception, $condition_false); | |
| + $data[] = array($conditions, 'or', TRUE); | |
| + $data[] = array($conditions, 'and', FALSE); | |
| return $data; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment