function StaticMenuLinkOverridesTest::testSaveOverride

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Menu/StaticMenuLinkOverridesTest.php \Drupal\Tests\Core\Menu\StaticMenuLinkOverridesTest::testSaveOverride()
  2. 8.9.x core/tests/Drupal/Tests/Core/Menu/StaticMenuLinkOverridesTest.php \Drupal\Tests\Core\Menu\StaticMenuLinkOverridesTest::testSaveOverride()
  3. 10 core/tests/Drupal/Tests/Core/Menu/StaticMenuLinkOverridesTest.php \Drupal\Tests\Core\Menu\StaticMenuLinkOverridesTest::testSaveOverride()

Tests the saveOverride method.

@covers ::saveOverride @covers ::loadOverride @covers ::getConfig

File

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

Class

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

Namespace

Drupal\Tests\Core\Menu

Code

public function testSaveOverride() : void {
    $config = $this->getMockBuilder('Drupal\\Core\\Config\\Config')
        ->disableOriginalConstructor()
        ->getMock();
    $definition_save_1 = [
        'definitions' => [
            'test1' => [
                'parent' => 'test0',
                'menu_name' => '',
                'weight' => 0,
                'expanded' => FALSE,
                'enabled' => FALSE,
            ],
        ],
    ];
    $definitions_save_2 = [
        'definitions' => [
            'test1' => [
                'parent' => 'test0',
                'menu_name' => '',
                'weight' => 0,
                'expanded' => FALSE,
                'enabled' => FALSE,
            ],
            'test1__la___ma' => [
                'parent' => 'test1',
                'menu_name' => '',
                'weight' => 0,
                'expanded' => FALSE,
                'enabled' => FALSE,
            ],
        ],
    ];
    $config->expects($this->exactly(4))
        ->method('get')
        ->with('definitions')
        ->willReturnOnConsecutiveCalls([], [], $definition_save_1['definitions'], $definition_save_1['definitions']);
    $definitions = [
        $definition_save_1['definitions'],
        $definitions_save_2['definitions'],
    ];
    $config->expects($this->exactly(count($definitions)))
        ->method('set')
        ->with('definitions', $this->callback(function (array $value) use (&$definitions) : bool {
        return array_shift($definitions) === $value;
    }))
        ->willReturnSelf();
    $config->expects($this->exactly(2))
        ->method('save');
    $config_factory = $this->createMock('Drupal\\Core\\Config\\ConfigFactoryInterface');
    $config_factory->expects($this->once())
        ->method('getEditable')
        ->willReturn($config);
    $static_override = new StaticMenuLinkOverrides($config_factory);
    $static_override->saveOverride('test1', [
        'parent' => 'test0',
    ]);
    $static_override->saveOverride('test1.la__ma', [
        'parent' => 'test1',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.