function MenuStorageTest::testMaxIdLengthException

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Kernel/Menu/MenuStorageTest.php \Drupal\Tests\system\Kernel\Menu\MenuStorageTest::testMaxIdLengthException()
  2. 10 core/modules/system/tests/src/Kernel/Menu/MenuStorageTest.php \Drupal\Tests\system\Kernel\Menu\MenuStorageTest::testMaxIdLengthException()
  3. 11.x core/modules/system/tests/src/Kernel/Menu/MenuStorageTest.php \Drupal\Tests\system\Kernel\Menu\MenuStorageTest::testMaxIdLengthException()

Tests MenuStorage::MAX_ID_LENGTH is enforced.

File

core/modules/system/tests/src/Kernel/Menu/MenuStorageTest.php, line 27

Class

MenuStorageTest
Tests MenuStorage.

Namespace

Drupal\Tests\system\Kernel\Menu

Code

public function testMaxIdLengthException() {
    $id = $this->randomMachineName(MenuStorage::MAX_ID_LENGTH + 1);
    $this->expectException(ConfigEntityIdLengthException::class);
    $this->expectExceptionMessage(sprintf('Configuration entity ID %s exceeds maximum allowed length of %s characters.', $id, MenuStorage::MAX_ID_LENGTH));
    Menu::create([
        'id' => $id,
    ])->save();
}

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