entity_type_access_conditions-1.0.1/tests/src/Traits/EntityTypeAccessTestTrait.php
tests/src/Traits/EntityTypeAccessTestTrait.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\entity_type_access_conditions\Traits;
/**
* Provides methods for testing with conditions.
*/
trait EntityTypeAccessTestTrait {
/**
* Returns a test condition plugin.
*
* @return array
* A test condition plugin configuration.
*/
protected function getTestCondition(): array {
return [
'id' => 'test_condition',
'condition_met' => TRUE,
'negate' => FALSE,
];
}
/**
* Returns a second test condition plugin.
*
* @return array
* A test condition plugin configuration.
*/
protected function getSecondTestCondition(): array {
return [
'id' => 'test_condition_two',
'condition_met' => TRUE,
'negate' => FALSE,
];
}
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// Register our test condition plugin.
$this->container->get('plugin.manager.condition')->addDiscovery(
new class() {
/**
* Mocking the condition manager getDefinitions method.
*/
public function getDefinitions(): array {
return [
'test_condition' => [
'id' => 'test_condition',
'label' => 'Test Condition',
'class' => 'Drupal\views_access_conditions_test\Plugin\Condition\TestCondition',
],
'test_condition_two' => [
'id' => 'test_condition_two',
'label' => 'Test Condition Two',
'class' => 'Drupal\views_access_conditions_test\Plugin\Condition\TestConditionTwo',
],
];
}
}
);
}
}
