You are here

public function ModulesWeightTest::testGetModulesList in Modules weight 8

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/ModulesWeightTest.php \Drupal\Tests\modules_weight\Unit\ModulesWeightTest::testGetModulesList()

Tests the modules list with ModulesWeight::getModulesList().

@covers ::getModulesList @dataProvider providerGetModulesList

Parameters

string $expected: The expected result from calling the function.

bool $show_core_modules: Force to show the core modules.

File

tests/src/Unit/ModulesWeightTest.php, line 27

Class

ModulesWeightTest
Tests the ModulesWeight class methods.

Namespace

Drupal\Tests\modules_weight\Unit

Code

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));
}