Skip to content
Snippets Groups Projects
Verified Commit 0dd821ab authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3495577 by nikolay shapovalov, nicxvan: Move helpers in menu_test.module and delete it

parent 18a39f8c
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Module that implements various hooks for menu tests.
*/
declare(strict_types=1);
/**
* Sets a static variable for the testMenuName() test.
*
* Used to change the menu_name parameter of a menu.
*
* @param string $new_name
* (optional) If set, will change the $menu_name value.
*
* @return string
* The $menu_name value to use.
*/
function menu_test_menu_name($new_name = '') {
static $menu_name = 'original';
if ($new_name) {
$menu_name = $new_name;
}
return $menu_name;
}
/**
* Title callback: Concatenates the title and case number.
*
* @param string $title
* Title string.
* @param int $case_number
* (optional) The current case number which it tests (defaults to 3).
*
* @return string
* A string containing the title and case number.
*
* @see menu_test_menu()
*/
function menu_test_title_callback($title, $case_number = 3) {
// phpcs:ignore Drupal.Semantics.FunctionT.NotLiteralString
return t($title) . ' - Case ' . $case_number;
}
......@@ -7,6 +7,7 @@
use Drupal\Core\Url;
use Drupal\Core\Cache\RefinableCacheableDependencyInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\menu_test\MenuTestHelper;
/**
* Hook implementations for menu_test.
......@@ -21,7 +22,7 @@ public function menuLinksDiscoveredAlter(&$links): void {
// Many of the machine names here are slightly different from the route name.
// Since the machine name is arbitrary, this helps ensure that core does not
// add mistaken assumptions about the correlation.
$links['menu_test.menu_name_test']['menu_name'] = menu_test_menu_name();
$links['menu_test.menu_name_test']['menu_name'] = MenuTestHelper::menuName();
$links['menu_test.context']['title'] = \Drupal::config('menu_test.menu_item')->get('title');
// Adds a custom menu link.
$links['menu_test.custom'] = [
......
<?php
declare(strict_types=1);
namespace Drupal\menu_test;
/**
* Helper class for the menu API tests.
*/
final class MenuTestHelper {
/**
* Sets a static variable for the testMenuName() test.
*
* Used to change the menu_name parameter of a menu.
*
* @param string $new_name
* (optional) If set, will change the $menu_name value.
*
* @return string
* The $menu_name value to use.
*/
public static function menuName(string $new_name = ''): string {
static $menu_name = 'original';
if ($new_name) {
$menu_name = $new_name;
}
return $menu_name;
}
}
......@@ -5,6 +5,7 @@
namespace Drupal\Tests\system\Functional\Menu;
use Drupal\Core\Url;
use Drupal\menu_test\MenuTestHelper;
use Drupal\Tests\BrowserTestBase;
/**
......@@ -121,7 +122,7 @@ protected function doTestMenuName(): void {
// Change the menu_name parameter in menu_test.module, then force a menu
// rebuild.
menu_test_menu_name('changed');
MenuTestHelper::menuName('changed');
$menu_link_manager->rebuild();
$menu_links = $menu_link_manager->loadLinksByRoute('menu_test.menu_name_test');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment