You are here

public function ContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedBy in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php \Drupal\Tests\Core\Plugin\Context\ContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedBy()
  2. 9 core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php \Drupal\Tests\Core\Plugin\Context\ContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedBy()

Provides test data for ::testIsSatisfiedBy().

File

core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php, line 83

Class

ContextDefinitionIsSatisfiedTest
@coversDefaultClass \Drupal\Core\Plugin\Context\ContextDefinition @group Plugin

Namespace

Drupal\Tests\Core\Plugin\Context

Code

public function providerTestIsSatisfiedBy() {
  $data = [];

  // Simple data types.
  $data['both any'] = [
    TRUE,
    new ContextDefinition('any'),
    new ContextDefinition('any'),
  ];
  $data['requirement any'] = [
    TRUE,
    new ContextDefinition('any'),
    new ContextDefinition('integer'),
  ];
  $data['integer, out of range'] = [
    FALSE,
    (new ContextDefinition('integer'))
      ->addConstraint('Range', [
      'min' => 0,
      'max' => 10,
    ]),
    new ContextDefinition('integer'),
    20,
  ];
  $data['integer, within range'] = [
    TRUE,
    (new ContextDefinition('integer'))
      ->addConstraint('Range', [
      'min' => 0,
      'max' => 10,
    ]),
    new ContextDefinition('integer'),
    5,
  ];
  $data['integer, no value'] = [
    TRUE,
    (new ContextDefinition('integer'))
      ->addConstraint('Range', [
      'min' => 0,
      'max' => 10,
    ]),
    new ContextDefinition('integer'),
  ];
  $data['non-integer, within range'] = [
    FALSE,
    (new ContextDefinition('integer'))
      ->addConstraint('Range', [
      'min' => 0,
      'max' => 10,
    ]),
    new ContextDefinition('any'),
    5,
  ];

  // Inherited context definition class.
  $data['both any, inherited context requirement definition'] = [
    TRUE,
    new InheritedContextDefinition('any'),
    new ContextDefinition('any'),
  ];
  $data['specific definition, generic requirement'] = [
    TRUE,
    new ContextDefinition('test_data_type'),
    new ContextDefinition('test_data_type:a_variant'),
  ];
  $data['generic definition, specific requirement'] = [
    FALSE,
    new ContextDefinition('test_data_type:a_variant'),
    new ContextDefinition('test_data_type'),
  ];
  return $data;
}