Unverified Commit 41baf345 authored by larowlan's avatar larowlan
Browse files

Issue #2938186 by navneet0693, John Cook, Eli-T, markconroy, smaz, ckrina,...

Issue #2938186 by navneet0693, John Cook, Eli-T, markconroy, smaz, ckrina, andrewmacpherson, larowlan: Set toolbar warning message to only appear on admin/edit pages
parent b1e477ec
...@@ -34,8 +34,17 @@ function demo_umami_toolbar() { ...@@ -34,8 +34,17 @@ function demo_umami_toolbar() {
// @todo: This can be removed once a generic warning for experimental profiles has been introduced. // @todo: This can be removed once a generic warning for experimental profiles has been introduced.
// @see https://www.drupal.org/project/drupal/issues/2934374 // @see https://www.drupal.org/project/drupal/issues/2934374
$items['experimental-profile-warning'] = [ $items['experimental-profile-warning'] = [
'#type' => 'toolbar_item', '#weight' => 999,
'tab' => [ '#cache' => [
'contexts' => ['route'],
],
];
// Show warning only on administration pages.
$admin_context = \Drupal::service('router.admin_context');
if ($admin_context->isAdminRoute()) {
$items['experimental-profile-warning']['#type'] = 'toolbar_item';
$items['experimental-profile-warning']['tab'] = [
'#type' => 'inline_template', '#type' => 'inline_template',
'#template' => '<a class="toolbar-warning" href="{{ more_info_link }}">This installation is for demonstration purposes only.</a>', '#template' => '<a class="toolbar-warning" href="{{ more_info_link }}">This installation is for demonstration purposes only.</a>',
'#context' => [ '#context' => [
...@@ -44,8 +53,7 @@ function demo_umami_toolbar() { ...@@ -44,8 +53,7 @@ function demo_umami_toolbar() {
'#attached' => [ '#attached' => [
'library' => ['demo_umami/toolbar-warning'], 'library' => ['demo_umami/toolbar-warning'],
], ],
], ];
'#weight' => 999, }
];
return $items; return $items;
} }
...@@ -122,4 +122,51 @@ public function testAppearance() { ...@@ -122,4 +122,51 @@ public function testAppearance() {
$webassert->pageTextContains('Umami'); $webassert->pageTextContains('Umami');
} }
/**
* Tests that the toolbar warning only appears on the admin pages.
*/
public function testDemonstrationWarningMessage() {
$permissions = [
'access content overview',
'administer nodes',
'create recipe content',
'edit any recipe content',
'access toolbar',
];
$account = $this->drupalCreateUser($permissions);
$this->drupalLogin($account);
$web_assert = $this->assertSession();
$nodes = $this->container->get('entity_type.manager')
->getStorage('node')
->loadByProperties(['title' => 'Deep mediterranean quiche']);
/* @var \Drupal\node\Entity\Node $recipe_node */
$recipe_node = reset($nodes);
// Check when editing a node, the warning is visible.
$this->drupalGet($recipe_node->toUrl('edit-form'));
$web_assert->statusCodeEquals('200');
$web_assert->pageTextContains('This installation is for demonstration purposes only.');
// Check when adding a node, the warning is visible.
$this->drupalGet('node/add/recipe');
$web_assert->statusCodeEquals('200');
$web_assert->pageTextContains('This installation is for demonstration purposes only.');
// Check when looking at admin/content, the warning is visible.
$this->drupalGet('admin/content');
$web_assert->statusCodeEquals('200');
$web_assert->pageTextContains('This installation is for demonstration purposes only.');
// Check when viewing a node, the warning is not visible.
$this->drupalGet($recipe_node->toUrl());
$web_assert->statusCodeEquals('200');
$web_assert->pageTextNotContains('This installation is for demonstration purposes only.');
// Check when viewing the homepage, the warning is not visible.
$this->drupalGet('<front>');
$web_assert->statusCodeEquals('200');
$web_assert->pageTextNotContains('This installation is for demonstration purposes only.');
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment