View source
<?php
namespace Drupal\Tests\modules_weight\Unit;
use Drupal\Tests\UnitTestCase;
use Drupal\modules_weight\ModulesWeight;
class ModulesWeightTest extends UnitTestCase {
public function testGetModulesList($expected, $show_core_modules) {
if (!defined('DRUPAL_MINIMUM_PHP')) {
define('DRUPAL_MINIMUM_PHP', '5.5.9');
}
$modules = [];
$modules['admin_toolbar'] = [
'name' => 'Admin Toolbar',
'description' => 'Provides a drop-down menu interface to the core Drupal Toolbar.',
'package' => 'Administration',
];
$modules['standard'] = [
'name' => 'Standard',
'description' => 'Install with commonly used features pre-configured.',
'package' => 'Other',
'hidden' => 1,
];
$modules['views'] = [
'name' => 'Views',
'description' => 'Create customized lists and queries from your database.',
'package' => 'Core',
];
$modules['modules_weight'] = [
'name' => 'Modules Weight',
'description' => 'Allows to change the modules execution order.',
'package' => 'Development',
];
$module_extension_list = $this
->createMock('Drupal\\Core\\Extension\\ModuleExtensionList');
$module_extension_list
->expects($this
->any())
->method('getAllInstalledInfo')
->willReturn($modules);
$config = $this
->createMock('Drupal\\Core\\Config\\ImmutableConfig');
$weight = [
'standard' => 1000,
'admin_toolbar' => 3,
'modules_weight' => -5,
'views' => 0,
];
$config
->expects($this
->any())
->method('get')
->with('module')
->willReturn($weight);
$config_factory = $this
->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
$config_factory
->expects($this
->any())
->method('get')
->with('core.extension')
->willReturn($config);
$modules_weight = new ModulesWeight($config_factory, $module_extension_list);
$this
->assertSame($expected, $modules_weight
->getModulesList($show_core_modules));
}
public function providerGetModulesList() {
$show_core_modules['modules_weight'] = [
'name' => 'Modules Weight',
'description' => 'Allows to change the modules execution order.',
'weight' => -5,
'package' => 'Development',
];
$show_core_modules['views'] = [
'name' => 'Views',
'description' => 'Create customized lists and queries from your database.',
'weight' => 0,
'package' => 'Core',
];
$show_core_modules['admin_toolbar'] = [
'name' => 'Admin Toolbar',
'description' => 'Provides a drop-down menu interface to the core Drupal Toolbar.',
'weight' => 3,
'package' => 'Administration',
];
$not_show_core_modules['modules_weight'] = [
'name' => 'Modules Weight',
'description' => 'Allows to change the modules execution order.',
'weight' => -5,
'package' => 'Development',
];
$not_show_core_modules['admin_toolbar'] = [
'name' => 'Admin Toolbar',
'description' => 'Provides a drop-down menu interface to the core Drupal Toolbar.',
'weight' => 3,
'package' => 'Administration',
];
$tests['show core modules'] = [
$show_core_modules,
TRUE,
];
$tests['not show core modules'] = [
$not_show_core_modules,
FALSE,
];
return $tests;
}
}