You are here

public function ModulesWeightTest::testGetModulesList in Modules weight 8.2

Same name and namespace in other branches
  1. 8 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) {

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

  // Testing the function.
  $this
    ->assertSame($expected, $modules_weight
    ->getModulesList($show_core_modules));
}