function MenuValidationTest::providerInvalidMachineNameCharacters

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Kernel/Entity/MenuValidationTest.php \Drupal\Tests\system\Kernel\Entity\MenuValidationTest::providerInvalidMachineNameCharacters()

Menu IDs are atypical: they allow dashes and disallow underscores.

Return value

array[] The test cases.

Overrides ConfigEntityValidationTestBase::providerInvalidMachineNameCharacters

File

core/modules/system/tests/src/Kernel/Entity/MenuValidationTest.php, line 41

Class

MenuValidationTest
Tests validation of menu entities.

Namespace

Drupal\Tests\system\Kernel\Entity

Code

public static function providerInvalidMachineNameCharacters() : array {
  $cases = parent::providerInvalidMachineNameCharacters();
  // Remove the existing test case that verifies a machine name containing
  // dashes is invalid.
  self::assertSame([
    'dash-separated',
    FALSE,
  ], $cases['INVALID: dash separated']);
  unset($cases['INVALID: dash separated']);
  // And instead add a test case that verifies it is allowed for menus.
  $cases['VALID: dash separated'] = [
    'dash-separated',
    TRUE,
  ];
  // Remove the existing test case that verifies a machine name containing
  // underscores is valid.
  self::assertSame([
    'underscore_separated',
    TRUE,
  ], $cases['VALID: underscore separated']);
  unset($cases['VALID: underscore separated']);
  // And instead add a test case that verifies it is disallowed for menus.
  $cases['INVALID: underscore separated'] = [
    'underscore_separated',
    FALSE,
  ];
  return $cases;
}

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