summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/system/tests/src/Kernel/ModuleAdminLinksHelperTest.php
blob: 7dfb8df98e1054ce0cbc085944604aeb9492b2c7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php

declare(strict_types=1);

namespace Drupal\Tests\system\Kernel;

use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;

/**
 * Tests the ModuleAdminLinksHelper.
 *
 * @coversDefaultClass \Drupal\system\ModuleAdminLinksHelper
 * @group system
 */
class ModuleAdminLinksHelperTest extends KernelTestBase {

  use UserCreationTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'link',
    'menu_link_content',
    'menu_test',
    'router_test',
    'system',
    'user',
  ];

  /**
   * {@inheritdoc}
   */
  public function setUp(): void {
    parent::setUp();
    $this->setUpCurrentUser([], [
      'access administration pages',
    ]);
    $this->installEntitySchema('menu_link_content');
  }

  /**
   * @covers ::getModuleAdminLinks
   */
  public function testGetModuleAdminLinks(): void {
    // Rebuild the menu links.
    $this->container->get('plugin.manager.menu.link')->rebuild();

    $adminLinksHelper = $this->container->get('system.module_admin_links_helper');

    // Test a module that has admin links.
    $links = $adminLinksHelper->getModuleAdminLinks('menu_test');

    $this->assertCount(1, $links);
    $this->assertEquals('menu_test.menu_name_test', $links[0]['url']->getRouteName());

    // Test a module that has no admin links.
    $links = $adminLinksHelper->getModuleAdminLinks('link');

    $this->assertCount(0, $links);
  }

}