You are here

public function MenuStorageTest::testMaxIdLengthException in Drupal 8

Same name and namespace in other branches
  1. 9 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();
}