3 namespace Drupal\Tests\forum\Kernel;
5 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
6 use Drupal\node\Entity\Node;
7 use Drupal\taxonomy\Entity\Term;
10 * Tests forum validation constraints.
14 class ForumValidationTest extends EntityKernelTestBase {
21 public static $modules = ['node', 'options', 'comment', 'taxonomy', 'forum'];
24 * Tests the forum validation constraints.
26 public function testValidation() {
28 $forum = Term::create([
31 'forum_container' => 0,
35 $container = Term::create([
36 'name' => 'container 1',
38 'forum_container' => 1,
42 $forum_post = Node::create([
44 'title' => 'Do these pants make my butt look big?',
47 $violations = $forum_post->validate();
48 $this->assertEqual(count($violations), 1);
49 $this->assertEqual($violations[0]->getMessage(), 'This value should not be null.');
51 // Add the forum term.
52 $forum_post->set('taxonomy_forums', $forum);
53 $violations = $forum_post->validate();
54 $this->assertEqual(count($violations), 0);
56 // Try to use a container.
57 $forum_post->set('taxonomy_forums', $container);
58 $violations = $forum_post->validate();
59 $this->assertEqual(count($violations), 1);
60 $this->assertEqual($violations[0]->getMessage(), t('The item %forum is a forum container, not a forum. Select one of the forums below instead.', [
61 '%forum' => $container->label(),