function MenuTreeParametersTest::testAddExpanded

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Menu/MenuTreeParametersTest.php \Drupal\Tests\Core\Menu\MenuTreeParametersTest::testAddExpanded()
  2. 10 core/tests/Drupal/Tests/Core/Menu/MenuTreeParametersTest.php \Drupal\Tests\Core\Menu\MenuTreeParametersTest::testAddExpanded()
  3. 11.x core/tests/Drupal/Tests/Core/Menu/MenuTreeParametersTest.php \Drupal\Tests\Core\Menu\MenuTreeParametersTest::testAddExpanded()

Tests addExpandedParents().

@covers ::addExpandedParents

File

core/tests/Drupal/Tests/Core/Menu/MenuTreeParametersTest.php, line 58

Class

MenuTreeParametersTest
Tests the menu link tree parameters value object.

Namespace

Drupal\Tests\Core\Menu

Code

public function testAddExpanded() {
    $parameters = new MenuTreeParameters();
    // Verify default value.
    $this->assertEquals([], $parameters->expandedParents);
    // Add actual menu link plugin IDs to be expanded.
    $parameters->addExpandedParents([
        'foo',
        'bar',
        'baz',
    ]);
    $this->assertEquals([
        'foo',
        'bar',
        'baz',
    ], $parameters->expandedParents);
    // Add additional menu link plugin IDs; they should be merged, not replacing
    // the old ones.
    $parameters->addExpandedParents([
        'qux',
        'quux',
    ]);
    $this->assertEquals([
        'foo',
        'bar',
        'baz',
        'qux',
        'quux',
    ], $parameters->expandedParents);
    // Add pre-existing menu link plugin IDs; they should not be added again;
    // this is a set.
    $parameters->addExpandedParents([
        'bar',
        'quux',
    ]);
    $this->assertEquals([
        'foo',
        'bar',
        'baz',
        'qux',
        'quux',
    ], $parameters->expandedParents);
}

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