From 38c2ac79f910f7068c6922449ea025e86bf2c0cd Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Mon, 29 Jan 2018 08:26:58 +1000 Subject: [PATCH] Issue #2939904 by alexpott, Mile23: Fix system_get_info() for non-installed modules --- core/modules/system/system.module | 7 ++- .../src/Kernel/System/SystemGetInfoTest.php | 44 +++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 964d7fe91a27..bb82d4b19f3f 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -963,7 +963,12 @@ function system_get_info($type, $name = NULL) { /** @var \Drupal\Core\Extension\ModuleExtensionList $module_list */ $module_list = \Drupal::service('extension.list.module'); if (isset($name)) { - return $module_list->getExtensionInfo($name); + try { + return $module_list->getExtensionInfo($name); + } + catch (\InvalidArgumentException $e) { + return []; + } } else { return $module_list->getAllInstalledInfo(); diff --git a/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php b/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php new file mode 100644 index 000000000000..cd42fa48707d --- /dev/null +++ b/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php @@ -0,0 +1,44 @@ +<?php + +namespace Drupal\Tests\system\Kernel\System; + +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests system_get_info(). + * + * @group system + */ +class SystemGetInfoTest extends KernelTestBase { + + public static $modules = ['system']; + + /** + * Tests system_get_info(). + */ + public function testSystemGetInfo() { + $system_module_info = system_get_info('module', 'system'); + $this->assertSame('System', $system_module_info['name']); + $this->assertSame(['system' => $system_module_info], system_get_info('module')); + + // 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']); + $this->assertSame(['system' => $system_module_info, 'user' => $user_module_info], system_get_info('module')); + + // 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')); + } + +} -- GitLab