Commit a62e5f82 authored by Paulo Henrique Cota Starling's avatar Paulo Henrique Cota Starling
Browse files

Issue #3304903 by david.muffley, paulocs: ContextAll does not return false if...

Issue #3304903 by david.muffley, paulocs: ContextAll does not return false if a context doesn't exist
parent 98e1d617
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -156,10 +156,13 @@ class ContextAll extends ConditionPluginBase implements ContainerFactoryPluginIn
    // Now handle required contexts.
    foreach ($required_contexts as $name) {
      /** @var \Drupal\context\ContextInterface $required_context */
      if ($required_context = $this->contextManager->getContext($name)) {
        if (!$this->contextManager->evaluateContextConditions($required_context) && !$required_context->disabled()) {
      $required_context = $this->contextManager->getContext($name);
      // A non-existent context can never be active.
      if (!isset($required_context)) {
        return FALSE;
      }
      if (!$this->contextManager->evaluateContextConditions($required_context) && !$required_context->disabled()) {
        return FALSE;
      }
    }

+7 −0
Original line number Diff line number Diff line
@@ -146,6 +146,13 @@ class ContextAllAnyTest extends KernelTestBase {
    $this->assertTrue($condition->evaluate(), 'All contexts are active');
    $this->assertEquals($condition->summary(), 'Return true on the basis of other active contexts: ~another_context, test', 'Context applied.');

    // Test that a non-existent context evaluates to false.
    $condition->setConfig('values', 'does_not_exist');
    $this->assertFalse($condition->evaluate(), 'All contexts are not active');

    $condition->setConfig('values', "another_context\r\ndoes_not_exist");
    $this->assertFalse($condition->evaluate(), 'All contexts are not active');

  }

  /**