BlockContentValidationTest.php in Drupal 10
File
core/modules/block_content/tests/src/Functional/BlockContentValidationTest.php
View source
<?php
namespace Drupal\Tests\block_content\Functional;
use Drupal\Component\Render\FormattableMarkup;
class BlockContentValidationTest extends BlockContentTestBase {
protected $defaultTheme = 'stark';
public function testValidation() {
$description = $this
->randomMachineName();
$block = $this
->createBlockContent($description, 'basic');
$violations = $block
->validate();
$this
->assertCount(0, $violations);
$block
->save();
$block = $this
->createBlockContent($description, 'basic');
$violations = $block
->validate();
$this
->assertCount(1, $violations);
$this
->assertEquals('info', $violations[0]
->getPropertyPath());
$this
->assertEquals(new FormattableMarkup('A custom block with block description %value already exists.', [
'%value' => $block
->label(),
]), $violations[0]
->getMessage());
}
}