function MenuTreeParametersTest::testAddCondition
Same name in other branches
- 8.9.x core/tests/Drupal/Tests/Core/Menu/MenuTreeParametersTest.php \Drupal\Tests\Core\Menu\MenuTreeParametersTest::testAddCondition()
- 10 core/tests/Drupal/Tests/Core/Menu/MenuTreeParametersTest.php \Drupal\Tests\Core\Menu\MenuTreeParametersTest::testAddCondition()
- 11.x core/tests/Drupal/Tests/Core/Menu/MenuTreeParametersTest.php \Drupal\Tests\Core\Menu\MenuTreeParametersTest::testAddCondition()
Tests addCondition().
@covers ::addCondition
File
-
core/
tests/ Drupal/ Tests/ Core/ Menu/ MenuTreeParametersTest.php, line 84
Class
- MenuTreeParametersTest
- Tests the menu link tree parameters value object.
Namespace
Drupal\Tests\Core\MenuCode
public function testAddCondition() {
$parameters = new MenuTreeParameters();
// Verify default value.
$this->assertEquals([], $parameters->conditions);
// Add a condition.
$parameters->addCondition('expanded', 1);
$this->assertEquals([
'expanded' => 1,
], $parameters->conditions);
// Add another condition.
$parameters->addCondition('has_children', 0);
$this->assertEquals([
'expanded' => 1,
'has_children' => 0,
], $parameters->conditions);
// Add a condition with an operator.
$parameters->addCondition('provider', [
'module1',
'module2',
], 'IN');
$this->assertEquals([
'expanded' => 1,
'has_children' => 0,
'provider' => [
[
'module1',
'module2',
],
'IN',
],
], $parameters->conditions);
// Add another condition with an operator.
$parameters->addCondition('id', 1337, '<');
$this->assertEquals([
'expanded' => 1,
'has_children' => 0,
'provider' => [
[
'module1',
'module2',
],
'IN',
],
'id' => [
1337,
'<',
],
], $parameters->conditions);
// It's impossible to add two conditions on the same field; in that case,
// the old condition will be overwritten.
$parameters->addCondition('provider', 'other_module');
$this->assertEquals([
'expanded' => 1,
'has_children' => 0,
'provider' => 'other_module',
'id' => [
1337,
'<',
],
], $parameters->conditions);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.