public function AdminToolbarToolsSortTest::testMenuUpdate in Admin Toolbar 3.x
Same name and namespace in other branches
- 8.2 tests/src/Functional/AdminToolbarToolsSortTest.php \Drupal\Tests\admin_toolbar\Functional\AdminToolbarToolsSortTest::testMenuUpdate()
Tests that menu updates on entity add/update/delete.
File
- tests/
src/ Functional/ AdminToolbarToolsSortTest.php, line 46
Class
- AdminToolbarToolsSortTest
- Tests Admin Toolbar tools functionality.
Namespace
Drupal\Tests\admin_toolbar\FunctionalCode
public function testMenuUpdate() {
// Create and log in an administrative user.
$this->adminUser = $this
->drupalCreateUser([
'access toolbar',
'access administration pages',
'administer site configuration',
'administer menu',
'access media overview',
'administer media',
'administer media fields',
'administer media form display',
'administer media display',
'administer media types',
]);
$this
->drupalLogin($this->adminUser);
$menu = Menu::create([
'id' => 'armadillo',
'label' => 'Armadillo',
]);
$menu
->save();
$this->container
->get('plugin.manager.menu.link')
->rebuild();
$this
->drupalGet('/admin');
// Assert that special menu items are present in the HTML.
$this
->assertSession()
->responseContains('class="toolbar-icon toolbar-icon-admin-toolbar-tools-flush"');
// Assert that adding a media type adds it to the admin toolbar.
$chinchilla_media_type = MediaType::create([
'id' => 'chinchilla',
'label' => 'Chinchilla',
'source' => 'image',
]);
$chinchilla_media_type
->save();
$this
->drupalGet('/admin');
$this
->assertMenuHasHref('/admin/structure/media/manage/chinchilla');
// Assert that adding a menu adds it to the admin toolbar.
$menu = Menu::create([
'id' => 'chupacabra',
'label' => 'Chupacabra',
]);
$menu
->save();
$this
->drupalGet('/admin');
$this
->assertMenuHasHref('/admin/structure/menu/manage/chupacabra');
// Assert that deleting a menu removes it from the admin toolbar.
$this
->assertMenuHasHref('/admin/structure/menu/manage/armadillo');
$menu = Menu::load('armadillo');
$menu
->delete();
$this
->drupalGet('/admin');
$this
->assertMenuDoesNotHaveHref('/admin/structure/menu/manage/armadillo');
// Assert that deleting a content entity bundle removes it from admin menu.
$this
->assertMenuHasHref('/admin/structure/media/manage/chinchilla');
$chinchilla_media_type = MediaType::load('chinchilla');
$chinchilla_media_type
->delete();
$this
->drupalGet('/admin');
$this
->assertMenuDoesNotHaveHref('/admin/structure/media/manage/chinchilla');
}