function ContextHandlerTest::providerTestGetMatchingContexts

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::providerTestGetMatchingContexts()
  2. 8.9.x core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::providerTestGetMatchingContexts()
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::providerTestGetMatchingContexts()

Provides data for testGetMatchingContexts().

File

core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php, line 142

Class

ContextHandlerTest
@coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler[[api-linebreak]] @group Plugin

Namespace

Drupal\Tests\Core\Plugin

Code

public static function providerTestGetMatchingContexts() {
  $requirement_any = new ContextDefinition();
  $requirement_specific = new ContextDefinition('string');
  $requirement_specific->setConstraints([
    'Blank' => [],
  ]);
  $context_any = new ContextDefinition('any');
  $context_constraint_mismatch = new ContextDefinition('foo');
  $context_datatype_mismatch = new ContextDefinition('fuzzy');
  $context_specific = new ContextDefinition('string');
  $context_specific->setConstraints([
    'Blank' => [],
  ]);
  $data = [];
  // No context will return no valid contexts.
  $data[] = [
    [],
    $requirement_any,
  ];
  // A context with a generic matching requirement is valid.
  $data[] = [
    [
      $context_any,
    ],
    $requirement_any,
  ];
  // A context with a specific matching requirement is valid.
  $data[] = [
    [
      $context_specific,
    ],
    $requirement_specific,
  ];
  // A context with a mismatched constraint is invalid.
  $data[] = [
    [
      $context_constraint_mismatch,
    ],
    $requirement_specific,
    [],
  ];
  // A context with a mismatched datatype is invalid.
  $data[] = [
    [
      $context_datatype_mismatch,
    ],
    $requirement_specific,
    [],
  ];
  return $data;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.