class ModulesWeightTest in Modules weight 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/ModulesWeightTest.php \Drupal\Tests\modules_weight\Unit\ModulesWeightTest
Tests the ModulesWeight class methods.
@group modules_weight @coversDefaultClass \Drupal\modules_weight\ModulesWeight
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\modules_weight\Unit\ModulesWeightTest
Expanded class hierarchy of ModulesWeightTest
File
- tests/
src/ Unit/ ModulesWeightTest.php, line 14
Namespace
Drupal\Tests\modules_weight\UnitView source
class ModulesWeightTest extends UnitTestCase {
/**
* Tests the modules list with ModulesWeight::getModulesList().
*
* @param string $expected
* The expected result from calling the function.
* @param bool $show_core_modules
* Force to show the core modules.
*
* @covers ::getModulesList
* @dataProvider providerGetModulesList
*/
public function testGetModulesList($expected, $show_core_modules) {
if (!defined('DRUPAL_MINIMUM_PHP')) {
define('DRUPAL_MINIMUM_PHP', '5.5.9');
}
// Defining the module array.
$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',
];
// ModuleExtensionList mock.
$module_extension_list = $this
->createMock('Drupal\\Core\\Extension\\ModuleExtensionList');
// Mocking getAllInstalledInfo method.
$module_extension_list
->expects($this
->any())
->method('getAllInstalledInfo')
->willReturn($modules);
// ImmutableConfig mock.
$config = $this
->createMock('Drupal\\Core\\Config\\ImmutableConfig');
$weight = [
'standard' => 1000,
'admin_toolbar' => 3,
'modules_weight' => -5,
'views' => 0,
];
// ImmutableConfig::get mock.
$config
->expects($this
->any())
->method('get')
->with('module')
->willReturn($weight);
// Config factory mock.
$config_factory = $this
->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
// ConfigFactoryInterface::get mock.
$config_factory
->expects($this
->any())
->method('get')
->with('core.extension')
->willReturn($config);
// Creating the object.
$modules_weight = new ModulesWeight($config_factory, $module_extension_list);
// Testing the function.
$this
->assertSame($expected, $modules_weight
->getModulesList($show_core_modules));
}
/**
* Data provider for testGetModulesList().
*
* @return array
* An array of arrays, each containing:
* - 'expected' - Expected return from getModulesList().
* - 'show_core_modules' - Force to show the core modules.
*
* @see testGetModulesList()
*/
public function providerGetModulesList() {
// Show core modules.
$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.
$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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ModulesWeightTest:: |
public | function | Data provider for testGetModulesList(). | |
ModulesWeightTest:: |
public | function | Tests the modules list with ModulesWeight::getModulesList(). | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
protected | function | 340 |