You are here

public function BlockContentValidationTest::testValidation in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/block_content/src/Tests/BlockContentValidationTest.php \Drupal\block_content\Tests\BlockContentValidationTest::testValidation()

Tests the block content validation constraints.

File

core/modules/block_content/src/Tests/BlockContentValidationTest.php, line 20
Contains \Drupal\block_content\Tests\BlockContentValidationTest.

Class

BlockContentValidationTest
Tests block content validation constraints.

Namespace

Drupal\block_content\Tests

Code

public function testValidation() {

  // Add a block.
  $description = $this
    ->randomMachineName();
  $block = $this
    ->createBlockContent($description, 'basic');

  // Validate the block.
  $violations = $block
    ->validate();

  // Make sure we have no violations.
  $this
    ->assertEqual(count($violations), 0);

  // Save the block.
  $block
    ->save();

  // Add another block with the same description.
  $block = $this
    ->createBlockContent($description, 'basic');

  // Validate this block.
  $violations = $block
    ->validate();

  // Make sure we have 1 violation.
  $this
    ->assertEqual(count($violations), 1);

  // Make sure the violation is on the info property
  $this
    ->assertEqual($violations[0]
    ->getPropertyPath(), 'info');

  // Make sure the message is correct.
  $this
    ->assertEqual($violations[0]
    ->getMessage(), format_string('A custom block with block description %value already exists.', [
    '%value' => $block
      ->label(),
  ]));
}