Commit 8faa8777 authored by David Suissa's avatar David Suissa
Browse files

Issue #3540400 by dydave, maxilein, chrisfromredfin: Fixed compatibility with...

Issue #3540400 by dydave, maxilein, chrisfromredfin: Fixed compatibility with Project Browser '2.1.x' following the latest changes to the its configuration schema.
parent d074962a
Loading
Loading
Loading
Loading
Loading
+51 −1
Original line number Diff line number Diff line
@@ -48,6 +48,42 @@ variables:
  # # Convenient for debugging: Enable in issue forks for testing.
  # _SHOW_ENVIRONMENT_VARIABLES: 1

#
# Composer overrides and configuration.
#   - Require 'project_browser' to test integration with 'admin_toolbar_tools'.
#
composer:
  after_script:
    - composer require drupal/project_browser
composer (max PHP version):
  after_script:
    - composer require drupal/project_browser
composer (previous minor):
  after_script:
    - composer require drupal/project_browser
composer (next minor):
  after_script:
    - composer require drupal/project_browser
composer (previous major):
  after_script:
    - composer require drupal/project_browser
# composer (next major):
#   after_script:
#     - composer require drupal/project_browser

# #
# # CSPELL overrides and configuration.
# #
# cspell:
#   # Require spellcheck to pass.
#   allow_failure: false

# #
# # ESLINT overrides and configuration.
# #
# eslint:
#   # Require eslint to pass.
#   allow_failure: false

#
# PHPCS overrides and configuration.
@@ -56,8 +92,22 @@ phpcs:
  # Require phpcs to pass.
  allow_failure: false

# #
# # PHPSTAN overrides and configuration.
# #
# phpstan:
#   # Require phpstan to pass.
#   allow_failure: false

# #
# # PHPUNIT overrides and configuration.
# #
# phpunit:
#   # Require phpunit to pass.
#   allow_failure: false

#
# Stylelint overrides and configuration.
# STYLELINT overrides and configuration.
#
stylelint:
  # Require stylelint to pass.
+3 −4
Original line number Diff line number Diff line
@@ -747,9 +747,9 @@ class ExtraLinks extends DeriverBase implements ContainerDeriverInterface {
    if ($this->moduleHandler->moduleExists('project_browser')) {
      if ($this->routeExists('project_browser.browse')) {
        $project_browser_admin_settings = $this->configFactory->get('project_browser.admin_settings');
        // Get the enabled project browser sources.
        $project_browser_enabled_sources = $project_browser_admin_settings->get('enabled_sources');
        if (!empty($project_browser_enabled_sources)) {
        // Get the enabled project browser sources which are saved as keys of
        // the 'enabled_sources' config array.
        $project_browser_enabled_sources = array_keys($project_browser_admin_settings->get('enabled_sources') ?? []);
        // Build a menu link for each enabled project browser source.
        foreach ($project_browser_enabled_sources as $key => $source_id) {
          $links['project_browser.browse.' . $source_id] = [
@@ -768,7 +768,6 @@ class ExtraLinks extends DeriverBase implements ContainerDeriverInterface {
        }
      }
    }
    }

    return $links;
  }
+118 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\admin_toolbar_tools\Functional;

use Drupal\Tests\admin_toolbar\Traits\AdminToolbarHelperTestTrait;
use Drupal\Tests\BrowserTestBase;

/**
 * Test the Admin Toolbar Tools integration with the Project Browser module.
 *
 * Install the Project Browser module and verify that the Admin Toolbar Tools
 * links are correctly displayed in the admin toolbar, in the expected order.
 *
 * @see \Drupal\admin_toolbar_tools\Plugin\Derivative\ExtraLinks
 * @see admin_toolbar/admin_toolbar_tools/admin_toolbar_tools.module
 *
 * @group admin_toolbar
 * @group admin_toolbar_tools
 */
class AdminToolbarToolsProjectBrowserTest extends BrowserTestBase {

  use AdminToolbarHelperTestTrait;

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'stark';

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'admin_toolbar',
    'admin_toolbar_tools',
  ];

  /**
   * A user with access to the Admin Toolbar Tools admin menu links.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $adminUser;

  /**
   * {@inheritdoc}
   *
   * Conditionally install the Project Browser module based on whether a
   * compatible version could be found by the composer job, since versions below
   * 2.1.0 are not supported anymore.
   * Create an admin user with the required permissions to access the Project
   * Browser routes.
   *
   * @see admin_toolbar_tools_form_project_browser_settings_alter()
   * @see composer.json
   */
  protected function setUp(): void {
    parent::setUp();

    /* Custom configuration for Project Browser */

    // Skip the test if the Project Browser module does not exist, because no
    // compatible version was found.
    if (!\Drupal::service('extension.list.module')->exists('project_browser')) {
      $this->markTestSkipped('The Project Browser module does not exist in the file system.');
    }
    // Install the Project Browser module to test the integration.
    \Drupal::service('module_installer')->install(['project_browser']);

    /* Create an admin user */

    $permissions = [
      'access toolbar',
      // Required permission to access Project Browser routes under 'Extend'.
      'administer modules',
    ];
    $this->adminUser = $this->drupalCreateUser($permissions);
  }

  /**
   * Test Admin Toolbar Tools adds Project Browser links in the expected order.
   *
   * Reverse the default installation order of Project Browser sources, saved in
   * its configuration and verify that the admin toolbar links order is updated
   * accordingly after a cache rebuild.
   * Check the 'Extend' and 'Uninstall module' links are displayed in the
   * expected order, as well.
   *
   * @see admin_toolbar_tools_form_project_browser_settings_alter()
   */
  public function testAdminToolbarToolsProjectBrowserExtraLinks(): void {

    // Get default enabled project browser sources and reverse their order.
    $enabled_sources = \Drupal::config('project_browser.admin_settings')->get('enabled_sources');
    $reverse_array = array_reverse($enabled_sources);
    // Save the reversed array as the new enabled sources config.
    \Drupal::configFactory()->getEditable('project_browser.admin_settings')
      ->set('enabled_sources', $reverse_array)
      ->save();

    // Rebuild menu items: Admin Toolbar Tools requires a cache rebuild to
    // update the toolbar menu with the new config setting. See hook form alter
    // in admin_toolbar_tools.module.
    drupal_flush_all_caches();

    // Log in as an admin user to test the admin toolbar links under 'Extend'.
    $this->drupalLogin($this->adminUser);

    // Verify that the 'Extend' link exists and is displayed second after the
    // 'Tools' link added by default by Admin Toolbar Tools.
    $this->assertAdminToolbarMenuLinkExists('admin/modules', 'Extend', 2, 'toolbar-icon-system-modules-list');
    // Verify that the Project Browser links exist in the expected order:
    // They should be reversed compared to the default order: Recipes first.
    $this->assertAdminToolbarMenuLinkExists('admin/modules/browse/recipes', 'Browse Recipes', 1);
    $this->assertAdminToolbarMenuLinkExists('admin/modules/browse/drupalorg_jsonapi', 'Browse Contrib modules', 2);
    $this->assertAdminToolbarMenuLinkExists('admin/modules/uninstall', 'Uninstall module', 3);
  }

}
+10 −2
Original line number Diff line number Diff line
{
  "name": "drupal/admin_toolbar",
  "description": "Provides a drop-down menu interface to the core Drupal Toolbar.",
  "license": "GPL-2.0-or-later",
  "type": "drupal-module",
  "keywords": [
    "Drupal",
    "Toolbar"
  ],
  "homepage": "http://drupal.org/project/admin_toolbar",
  "license": "GPL-2.0-or-later",
  "authors": [
    {
      "name": "Wilfrid Roze (eme)",
@@ -29,10 +28,19 @@
      "name": "Mohamed Anis Taktak (matio89)",
      "homepage": "https://www.drupal.org/u/matio89",
      "role": "Maintainer"
    },
    {
      "name": "David Suissa (DYdave)",
      "homepage": "https://www.drupal.org/u/dydave",
      "role": "Maintainer"
    }
  ],
  "homepage": "http://drupal.org/project/admin_toolbar",
  "support": {
    "issues": "https://www.drupal.org/project/issues/admin_toolbar",
    "source": "https://git.drupalcode.org/project/admin_toolbar"
  },
  "conflict": {
    "drupal/project_browser": "<2.1.0"
  }
}