function ContextHandlerTest::providerTestCheckRequirements

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::providerTestCheckRequirements()
  2. 10 core/tests/Drupal/Tests/Core/Plugin/ContextHandlerTest.php \Drupal\Tests\Core\Plugin\ContextHandlerTest::providerTestCheckRequirements()
  3. 11.x 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 83

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->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
    $context_any->expects($this->atLeastOnce())
        ->method('getContextDefinition')
        ->willReturn(new ContextDefinition('any'));
    $requirement_specific = new ContextDefinition('string');
    $requirement_specific->setConstraints([
        'Blank' => [],
    ]);
    $context_constraint_mismatch = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
    $context_constraint_mismatch->expects($this->atLeastOnce())
        ->method('getContextDefinition')
        ->willReturn(new ContextDefinition('foo'));
    $context_datatype_mismatch = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
    $context_datatype_mismatch->expects($this->atLeastOnce())
        ->method('getContextDefinition')
        ->willReturn(new ContextDefinition('fuzzy'));
    $context_definition_specific = new ContextDefinition('string');
    $context_definition_specific->setConstraints([
        'Blank' => [],
    ]);
    $context_specific = $this->createMock('Drupal\\Core\\Plugin\\Context\\ContextInterface');
    $context_specific->expects($this->atLeastOnce())
        ->method('getContextDefinition')
        ->willReturn($context_definition_specific);
    $data = [];
    $data[] = [
        [],
        [],
        TRUE,
    ];
    $data[] = [
        [],
        [
            $requirement_any,
        ],
        FALSE,
    ];
    $data[] = [
        [],
        [
            $requirement_optional,
        ],
        TRUE,
    ];
    $data[] = [
        [],
        [
            $requirement_any,
            $requirement_optional,
        ],
        FALSE,
    ];
    $data[] = [
        [
            $context_any,
        ],
        [
            $requirement_any,
        ],
        TRUE,
    ];
    $data[] = [
        [
            $context_constraint_mismatch,
        ],
        [
            $requirement_specific,
        ],
        FALSE,
    ];
    $data[] = [
        [
            $context_datatype_mismatch,
        ],
        [
            $requirement_specific,
        ],
        FALSE,
    ];
    $data[] = [
        [
            $context_specific,
        ],
        [
            $requirement_specific,
        ],
        TRUE,
    ];
    return $data;
}

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