SystemGetInfoTest.php 2.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

namespace Drupal\Tests\system\Kernel\System;

use Drupal\KernelTests\KernelTestBase;

/**
 * Tests system_get_info().
 *
 * @group system
11
 * @group legacy
12 13 14
 */
class SystemGetInfoTest extends KernelTestBase {

15
  public static $modules = ['system'];
16 17 18

  /**
   * Tests system_get_info().
19 20 21
   *
   * @expectedDeprecation system_get_info() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal::service('extension.list.module')->getExtensionInfo() or \Drupal::service('extension.list.module')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919
   * @expectedDeprecation system_get_info() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal::service('extension.list.theme')->getExtensionInfo() or \Drupal::service('extension.list.theme')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919
22 23 24 25
   */
  public function testSystemGetInfo() {
    $system_module_info = system_get_info('module', 'system');
    $this->assertSame('System', $system_module_info['name']);
26
    $this->assertSame(['path_alias' => system_get_info('module', 'path_alias'), 'system' => $system_module_info], system_get_info('module'));
27 28 29 30 31 32 33 34 35 36

    // The User module is not installed so system_get_info() should return
    // an empty array.
    $this->assertSame([], system_get_info('module', 'user'));

    // Install the User module and check system_get_info() returns the correct
    // information.
    $this->container->get('module_installer')->install(['user']);
    $user_module_info = system_get_info('module', 'user');
    $this->assertSame('User', $user_module_info['name']);
37
    $this->assertSame(['path_alias' => system_get_info('module', 'path_alias'), 'system' => $system_module_info, 'user' => $user_module_info], system_get_info('module'));
38 39 40 41 42 43 44 45 46 47 48

    // Test theme info. There are no themes installed yet.
    $this->assertSame([], system_get_info('theme', 'stable'));
    $this->assertSame([], system_get_info('theme'));
    $this->container->get('theme_installer')->install(['stable']);
    $stable_theme_info = system_get_info('theme', 'stable');
    $this->assertSame('Stable', $stable_theme_info['name']);
    $this->assertSame(['stable' => $stable_theme_info], system_get_info('theme'));
  }

}