You are here

public function StaticMenuLinkOverridesTest::testDeleteOverrides in Drupal 8

Tests the deleteOverride and deleteOverrides method.

@dataProvider providerTestDeleteOverrides

Parameters

array|string $ids: Either a single ID or multiple ones as array.

array $old_definitions: The definitions before the deleting

array $new_definitions: The definitions after the deleting.

File

core/tests/Drupal/Tests/Core/Menu/StaticMenuLinkOverridesTest.php, line 167

Class

StaticMenuLinkOverridesTest
@coversDefaultClass \Drupal\Core\Menu\StaticMenuLinkOverrides @group Menu

Namespace

Drupal\Tests\Core\Menu

Code

public function testDeleteOverrides($ids, array $old_definitions, array $new_definitions) {
  $config = $this
    ->getMockBuilder('Drupal\\Core\\Config\\Config')
    ->disableOriginalConstructor()
    ->getMock();
  $config
    ->expects($this
    ->at(0))
    ->method('get')
    ->with('definitions')
    ->will($this
    ->returnValue($old_definitions));

  // Only save if the definitions changes.
  if ($old_definitions != $new_definitions) {
    $config
      ->expects($this
      ->at(1))
      ->method('set')
      ->with('definitions', $new_definitions)
      ->will($this
      ->returnSelf());
    $config
      ->expects($this
      ->at(2))
      ->method('save');
  }
  $config_factory = $this
    ->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
  $config_factory
    ->expects($this
    ->once())
    ->method('getEditable')
    ->will($this
    ->returnValue($config));
  $static_override = new StaticMenuLinkOverrides($config_factory);
  if (is_array($ids)) {
    $static_override
      ->deleteMultipleOverrides($ids);
  }
  else {
    $static_override
      ->deleteOverride($ids);
  }
}