Verified Commit 74bdd70d authored by Théodore Biadala's avatar Théodore Biadala
Browse files

Issue #3501934 by plopesc, oily, berdir: Navigation Top Bar should display...

Issue #3501934 by plopesc, oily, berdir: Navigation Top Bar should display Edit button as the primary action when viewing a forward revision
parent a80fcb94
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public function build(): array {
  protected function getFeaturedPageActions(array $page_actions): ?array {
    $featured_page_actions = [];
    $current_route_name = $this->routeMatch->getRouteName();
    $canonical_pattern = '/^entity\.(.+?)\.canonical$/';
    $canonical_pattern = '/^entity\.(.+?)\.(canonical|latest_version)$/';
    if (preg_match($canonical_pattern, $current_route_name, $matches)) {
      $entity_type = $matches[1];
      $edit_route = "entity.$entity_type.edit_form";
+76 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\navigation\Functional;

use Drupal\node\NodeInterface;
use Drupal\Tests\content_moderation\Functional\ModerationStateTestBase;

/**
 * Tests the top bar behavior along with content moderation.
 *
 * @group navigation
 */
class NavigationTopBarContentModerationTest extends ModerationStateTestBase {

  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'content_moderation',
    'node',
    'navigation_top_bar',
  ];

  /**
   * Node used to check top bar options.
   *
   * @var \Drupal\node\NodeInterface
   */
  protected NodeInterface $node;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();

    $this->adminUser
      ->addRole($this->drupalCreateRole(['access navigation']))
      ->save();
    $this->drupalLogin($this->adminUser);
    $this->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE);
    $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content');

    $this->node = $this->drupalCreateNode([
      'type' => 'moderated_content',
      'moderation_state' => 'published',
    ]);
  }

  /**
   * Tests the interaction of page actions and content moderation.
   */
  public function testContentModerationPageActions(): void {
    $this->drupalGet($this->node->toUrl());
    $this->assertSession()->elementNotContains('xpath', '//*[@id="top-bar-page-actions"]/ul', 'Latest version');

    // Publish a new draft.
    $this->node->setNewRevision(TRUE);
    $this->node->setTitle($this->node->getTitle() . ' - draft');
    $this->node->moderation_state->value = 'draft';
    $this->node->save();

    $this->drupalGet($this->node->toUrl());
    $this->assertSession()->elementContains('xpath', '//*[@id="top-bar-page-actions"]/ul', 'Latest version');

    // Confirm that Edit option is featured  in Latest version page.
    $this->clickLink('Latest version');
    $this->assertSession()->elementNotContains('xpath', '//*[@id="top-bar-page-actions"]/ul', 'Edit');
    $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/a[contains(@class, 'toolbar-button--icon--thin-pencil')]", "Edit");
  }

}
+1 −2
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ class NavigationTopBarTest extends PageCacheTagsTestBase {
    'navigation',
    'node',
    'layout_builder',
    'field_ui',
    'file',
    'test_page_test',
  ];

@@ -57,6 +55,7 @@ protected function setUp(): void {
      'access administration pages',
      'access navigation',
      'bypass node access',
      'configure any layout',
    ]);
    $this->drupalLogin($this->adminUser);