You are here

public function NodeRevisionDeleteTest::testUpdateTimeMaxNumberConfig in Node Revision Delete 8

Tests the updateTimeMaxNumberConfig() method.

@covers ::updateTimeMaxNumberConfig @dataProvider providerUpdateTimeMaxNumberConfig

Parameters

array $third_party_settings: The content type third party settings.

array $content_types_list: A list with node types objects.

int $max_number: The maximum number for $config_name parameter.

File

tests/src/Unit/NodeRevisionDeleteTest.php, line 687

Class

NodeRevisionDeleteTest
Tests the NodeRevisionDelete class methods.

Namespace

Drupal\Tests\node_revision_delete\Unit

Code

public function testUpdateTimeMaxNumberConfig(array $third_party_settings, array $content_types_list, $max_number) {

  // Mock NodeRevisionDelete.
  $controller = $this
    ->getNodeRevisionDeleteMock($content_types_list);

  // Config mock.
  $config = $this
    ->createMock('Drupal\\Core\\Config\\Config');

  // Config::get mock.
  $config
    ->expects($this
    ->any())
    ->method('get')
    ->with('third_party_settings')
    ->willReturnOnConsecutiveCalls(...$third_party_settings);
  $config
    ->expects($this
    ->any())
    ->method('set')
    ->with('third_party_settings', $this
    ->anything())
    ->willReturnSelf();
  $config
    ->expects($this
    ->any())
    ->method('save');
  $cant = count($content_types_list);
  $map_node_type = [];
  for ($i = 0; $i < $cant; $i++) {
    $map_node_type[] = [
      'node.type.' . $content_types_list[$i]
        ->id(),
      $config,
    ];
  }

  // Mocking get method.
  $this->configFactory
    ->expects($this
    ->any())
    ->method('getEditable')
    ->will($this
    ->returnValueMap($map_node_type));

  // Testing the method.
  $this
    ->assertNull($controller
    ->updateTimeMaxNumberConfig('minimum_age_to_delete', $max_number));
  $this
    ->assertNull($controller
    ->updateTimeMaxNumberConfig('when_to_delete', $max_number));
}