View source
<?php
namespace Drupal\admin_menu\Tests;
class AdminMenuDynamicLinksTest extends AdminMenuTestBase {
public static $modules = [
'node',
];
public static function getInfo() {
return [
'name' => 'Dynamic links',
'description' => 'Tests appearance, localization, and escaping of dynamic links.',
'group' => 'Administration menu',
];
}
function testNode() {
$type = $this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$type = $this
->drupalCreateContentType([
'type' => 'special',
'name' => 'Cool & Special',
]);
$permissions = $this->basePermissions + [
'administer content types',
'access content',
'create article content',
'create special content',
];
$this->admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('');
$this
->assertElementByXPath('//div[@id="admin-menu"]', [], t('Administration menu found.'));
$this
->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path)]', [
':path' => 'admin/structure/types',
], "Structure » Content types link found.");
$this
->assertNoRaw('Cool & Special');
$this
->assertRaw(check_plain('Cool & Special'));
$links = [
'admin/structure/types/manage/article' => 'Article',
'admin/structure/types/manage/special' => 'Cool & Special',
];
foreach ($links as $path => $title) {
$this
->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path) and text()=:title]', [
':path' => $path,
':title' => $title,
], "Structure » Content types » {$title} link found.");
}
return;
$links = [
'node/add/article' => 'Article',
'node/add/special' => 'Cool & Special',
];
foreach ($links as $path => $title) {
$this
->assertElementByXPath('//div[@id="admin-menu"]//a[contains(@href, :path) and text()=:title]', [
':path' => $path,
':title' => $title,
], "Add content » {$title} link found.");
}
}
function testNodeAdd() {
$type = $this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$permissions = $this->basePermissions + [
'access content',
];
$this->web_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->web_user);
$this
->assertNoText(t('Add content'));
$permissions = $this->basePermissions + [
'access content overview',
'access content',
'create article content',
];
$this->admin_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->admin_user);
$this
->assertLinkTrailByTitle([
t('Content'),
t('Add content'),
]);
$permissions = $this->basePermissions + [
'access content',
'create article content',
];
$this->web_user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($this->web_user);
$this
->assertLinkTrailByTitle([
t('Add content'),
]);
}
}