a0db394c6e90f90eacaa8183cdae7d2039c87118
[yaffs-website] / web / core / modules / block_content / src / Tests / BlockContentValidationTest.php
1 <?php
2
3 namespace Drupal\block_content\Tests;
4
5 /**
6  * Tests block content validation constraints.
7  *
8  * @group block_content
9  */
10 class BlockContentValidationTest extends BlockContentTestBase {
11
12   /**
13    * Tests the block content validation constraints.
14    */
15   public function testValidation() {
16     // Add a block.
17     $description = $this->randomMachineName();
18     $block = $this->createBlockContent($description, 'basic');
19     // Validate the block.
20     $violations = $block->validate();
21     // Make sure we have no violations.
22     $this->assertEqual(count($violations), 0);
23     // Save the block.
24     $block->save();
25
26     // Add another block with the same description.
27     $block = $this->createBlockContent($description, 'basic');
28     // Validate this block.
29     $violations = $block->validate();
30     // Make sure we have 1 violation.
31     $this->assertEqual(count($violations), 1);
32     // Make sure the violation is on the info property
33     $this->assertEqual($violations[0]->getPropertyPath(), 'info');
34     // Make sure the message is correct.
35     $this->assertEqual($violations[0]->getMessage(), format_string('A custom block with block description %value already exists.', [
36       '%value' => $block->label(),
37     ]));
38   }
39
40 }