function BlockValidationTest::providerInvalidMachineNameCharacters

Same name and namespace in other branches
  1. 11.x core/modules/block/tests/src/Kernel/BlockValidationTest.php \Drupal\Tests\block\Kernel\BlockValidationTest::providerInvalidMachineNameCharacters()
  2. 10 core/modules/block/tests/src/Kernel/BlockValidationTest.php \Drupal\Tests\block\Kernel\BlockValidationTest::providerInvalidMachineNameCharacters()

Block names are atypical in that they allow periods in the machine name.

Return value

array[] The test cases.

Overrides ConfigEntityValidationTestBase::providerInvalidMachineNameCharacters

File

core/modules/block/tests/src/Kernel/BlockValidationTest.php, line 88

Class

BlockValidationTest
Tests validation of block entities.

Namespace

Drupal\Tests\block\Kernel

Code

public static function providerInvalidMachineNameCharacters() : array {
  $cases = parent::providerInvalidMachineNameCharacters();
  // Remove the existing test case that verifies a machine name containing
  // periods is invalid.
  self::assertSame([
    'period.separated',
    FALSE,
  ], $cases['INVALID: period separated']);
  unset($cases['INVALID: period separated']);
  // And instead add a test case that verifies it is allowed for blocks.
  $cases['VALID: period separated'] = [
    'period.separated',
    TRUE,
  ];
  // Add test cases to ensure machine names cannot start or end with a period.
  // @see https://www.drupal.org/node/3244349
  $cases['INVALID: begins with period'] = [
    '.begins_with_period',
    FALSE,
  ];
  $cases['VALID: ends with period'] = [
    'ends_with_period.',
    TRUE,
  ];
  return $cases;
}

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