public function MenuTreeParametersTest::testAddCondition in Zircon Profile 8
Same name and namespace in other branches
- 8.0 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 89 - Contains \Drupal\Tests\Core\Menu\MenuTreeParametersTest.
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(array(), $parameters->conditions);
// Add a condition.
$parameters
->addCondition('expanded', 1);
$this
->assertEquals(array(
'expanded' => 1,
), $parameters->conditions);
// Add another condition.
$parameters
->addCondition('has_children', 0);
$this
->assertEquals(array(
'expanded' => 1,
'has_children' => 0,
), $parameters->conditions);
// Add a condition with an operator.
$parameters
->addCondition('provider', array(
'module1',
'module2',
), 'IN');
$this
->assertEquals(array(
'expanded' => 1,
'has_children' => 0,
'provider' => array(
array(
'module1',
'module2',
),
'IN',
),
), $parameters->conditions);
// Add another condition with an operator.
$parameters
->addCondition('id', 1337, '<');
$this
->assertEquals(array(
'expanded' => 1,
'has_children' => 0,
'provider' => array(
array(
'module1',
'module2',
),
'IN',
),
'id' => array(
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(array(
'expanded' => 1,
'has_children' => 0,
'provider' => 'other_module',
'id' => array(
1337,
'<',
),
), $parameters->conditions);
}