function ViewsMenuLinkTest::testMenuLinkOverrides

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php \Drupal\Tests\views\Kernel\Plugin\Display\ViewsMenuLinkTest::testMenuLinkOverrides()
  2. 10 core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php \Drupal\Tests\views\Kernel\Plugin\Display\ViewsMenuLinkTest::testMenuLinkOverrides()
  3. 11.x core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php \Drupal\Tests\views\Kernel\Plugin\Display\ViewsMenuLinkTest::testMenuLinkOverrides()

Test views internal menu link options.

File

core/modules/views/tests/src/Kernel/Plugin/Display/ViewsMenuLinkTest.php, line 55

Class

ViewsMenuLinkTest
Menu link test.

Namespace

Drupal\Tests\views\Kernel\Plugin\Display

Code

public function testMenuLinkOverrides() {
    // Link from views module.
    $views_link = $this->menuLinkManager
        ->getDefinition('views_view:views.test_page_display_menu.page_3');
    $this->assertTrue((bool) $views_link['enabled'], 'Menu link is enabled.');
    $this->assertFalse((bool) $views_link['expanded'], 'Menu link is not expanded.');
    $views_link['enabled'] = 0;
    $views_link['expanded'] = 1;
    $this->menuLinkManager
        ->updateDefinition($views_link['id'], $views_link);
    $views_link = $this->menuLinkManager
        ->getDefinition($views_link['id']);
    $this->assertFalse((bool) $views_link['enabled'], 'Menu link is disabled.');
    $this->assertTrue((bool) $views_link['expanded'], 'Menu link is expanded.');
    $this->menuLinkManager
        ->rebuild();
    $this->assertFalse((bool) $views_link['enabled'], 'Menu link is disabled.');
    $this->assertTrue((bool) $views_link['expanded'], 'Menu link is expanded.');
    // Link from user module.
    $user_link = $this->menuLinkManager
        ->getDefinition('user.page');
    $this->assertTrue((bool) $user_link['enabled'], 'Menu link is enabled.');
    $user_link['enabled'] = 0;
    $views_link['expanded'] = 1;
    $this->menuLinkManager
        ->updateDefinition($user_link['id'], $user_link);
    $this->assertFalse((bool) $user_link['enabled'], 'Menu link is disabled.');
    $this->menuLinkManager
        ->rebuild();
    $this->assertFalse((bool) $user_link['enabled'], 'Menu link is disabled.');
    $this->menuLinkOverrides
        ->reload();
    $views_link = $this->menuLinkManager
        ->getDefinition('views_view:views.test_page_display_menu.page_3');
    $this->assertFalse((bool) $views_link['enabled'], 'Menu link is disabled.');
    $this->assertTrue((bool) $views_link['expanded'], 'Menu link is expanded.');
    $user_link = $this->menuLinkManager
        ->getDefinition('user.page');
    $this->assertFalse((bool) $user_link['enabled'], 'Menu link is disabled.');
}

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