summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/language/tests/src/Kernel/ContentLanguageSettingsValidationTest.php
blob: 056779a0c2ff8cea4d15d90d38e4ad433cb93c74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php

declare(strict_types=1);

namespace Drupal\Tests\language\Kernel;

use Drupal\entity_test\Entity\EntityTestBundle;
use Drupal\KernelTests\Core\Config\ConfigEntityValidationTestBase;
use Drupal\language\Entity\ContentLanguageSettings;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;

/**
 * Tests validation of content_language_settings entities.
 *
 * @group language
 */
class ContentLanguageSettingsValidationTest extends ConfigEntityValidationTestBase {

  use ContentTypeCreationTrait;

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'entity_test',
    'field',
    'language',
    'node',
    'text',
    'user',
  ];

  /**
   * {@inheritdoc}
   */
  protected bool $hasLabel = FALSE;

  /**
   * {@inheritdoc}
   */
  protected function setUp(): void {
    parent::setUp();
    $this->installEntitySchema('node');
    $this->installConfig('node');

    $this->createContentType(['type' => 'alpha']);
    $this->createContentType(['type' => 'bravo']);

    EntityTestBundle::create(['id' => 'alpha'])->save();
    EntityTestBundle::create(['id' => 'bravo'])->save();

    $this->entity = ContentLanguageSettings::create([
      'target_entity_type_id' => 'node',
      'target_bundle' => 'alpha',
    ]);
    $this->entity->save();
  }

  /**
   * Tests that the target bundle of the language content settings is checked.
   */
  public function testTargetBundleMustExist(): void {
    $this->entity->set('target_bundle', 'superhero');
    $this->assertValidationErrors([
      '' => "The 'target_bundle' property cannot be changed.",
      'target_bundle' => "The 'superhero' bundle does not exist on the 'node' entity type.",
    ]);
  }

  /**
   * {@inheritdoc}
   */
  public function testImmutableProperties(array $valid_values = []): void {
    parent::testImmutableProperties([
      'target_entity_type_id' => 'entity_test_with_bundle',
      'target_bundle' => 'bravo',
    ]);
  }

}