You are here

public function ContextHandlerTest::providerTestCheckRequirements in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::providerTestCheckRequirements()

Provides data for testCheckRequirements().

File

core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php, line 52
Contains \Drupal\Tests\Core\Plugin\ContextHandlerTest.

Class

ContextHandlerTest
@coversDefaultClass \Drupal\Core\Plugin\Context\ContextHandler @group Plugin

Namespace

Drupal\Tests\Core\Plugin

Code

public function providerTestCheckRequirements() {
  $requirement_optional = new ContextDefinition();
  $requirement_optional
    ->setRequired(FALSE);
  $requirement_any = new ContextDefinition();
  $requirement_any
    ->setRequired(TRUE);
  $context_any = $this
    ->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
  $context_any
    ->expects($this
    ->atLeastOnce())
    ->method('getContextDefinition')
    ->will($this
    ->returnValue(new ContextDefinition('empty')));
  $requirement_specific = new ContextDefinition('specific');
  $requirement_specific
    ->setConstraints(array(
    'bar' => 'baz',
  ));
  $context_constraint_mismatch = $this
    ->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
  $context_constraint_mismatch
    ->expects($this
    ->atLeastOnce())
    ->method('getContextDefinition')
    ->will($this
    ->returnValue(new ContextDefinition('foo')));
  $context_datatype_mismatch = $this
    ->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
  $context_datatype_mismatch
    ->expects($this
    ->atLeastOnce())
    ->method('getContextDefinition')
    ->will($this
    ->returnValue(new ContextDefinition('fuzzy')));
  $context_definition_specific = new ContextDefinition('specific');
  $context_definition_specific
    ->setConstraints(array(
    'bar' => 'baz',
  ));
  $context_specific = $this
    ->getMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
  $context_specific
    ->expects($this
    ->atLeastOnce())
    ->method('getContextDefinition')
    ->will($this
    ->returnValue($context_definition_specific));
  $data = array();
  $data[] = array(
    array(),
    array(),
    TRUE,
  );
  $data[] = array(
    array(),
    array(
      $requirement_any,
    ),
    FALSE,
  );
  $data[] = array(
    array(),
    array(
      $requirement_optional,
    ),
    TRUE,
  );
  $data[] = array(
    array(),
    array(
      $requirement_any,
      $requirement_optional,
    ),
    FALSE,
  );
  $data[] = array(
    array(
      $context_any,
    ),
    array(
      $requirement_any,
    ),
    TRUE,
  );
  $data[] = array(
    array(
      $context_constraint_mismatch,
    ),
    array(
      $requirement_specific,
    ),
    FALSE,
  );
  $data[] = array(
    array(
      $context_datatype_mismatch,
    ),
    array(
      $requirement_specific,
    ),
    FALSE,
  );
  $data[] = array(
    array(
      $context_specific,
    ),
    array(
      $requirement_specific,
    ),
    TRUE,
  );
  return $data;
}