ComponentValidationTest.php
5.85 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
declare(strict_types=1);
namespace Drupal\Tests\drupal_cms_project\Functional;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\drupal_cms_content_type_base\ContentModelTestTrait;
/**
* @group drupal_cms_project
*/
class ComponentValidationTest extends BrowserTestBase {
use ContentModelTestTrait;
use RecipeTestTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$dir = realpath(__DIR__ . '/../../..');
// The recipe should apply cleanly.
$this->applyRecipe($dir);
// Apply it again to prove that it is idempotent.
$this->applyRecipe($dir);
$this->ensureFileExists('47b880a9-c2a4-4ed6-844d-95c6d6677004');
$this->ensureFileExists('671c51f9-7a67-40ce-82de-750f53892f26');
}
public function testContentModel(): void {
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = $this->container->get(EntityDisplayRepositoryInterface::class);
$form_display = $display_repository->getFormDisplay('node', 'project');
$this->assertFalse($form_display->isNew());
$this->assertNull($form_display->getComponent('url_redirects'));
$this->assertFieldsInOrder($form_display, [
'title',
'field_description',
'field_project__client_name',
'field_project__client_logo',
'field_featured_image',
'field_content',
'field_project__client_link',
'field_tags',
]);
$default_display = $display_repository->getViewDisplay('node', 'project');
$this->assertNull($default_display->getComponent('links'));
$this->assertFieldsInOrder($default_display, [
'field_project__client_logo',
'field_featured_image',
'content_moderation_control',
'field_content',
'field_project__client_link',
'field_tags',
]);
$this->assertSharedFieldsInSameOrder($form_display, $default_display);
$card_display = $display_repository->getViewDisplay('node', 'project', 'card');
$this->assertNull($card_display->getComponent('links'));
$this->assertFieldsInOrder($card_display, [
'field_featured_image',
'field_project__client_name',
'field_description',
]);
$featured_image = $card_display->getComponent('field_featured_image');
$this->assertSame('entity_reference_entity_view', $featured_image['type']);
$teaser_display = $display_repository->getViewDisplay('node', 'project', 'teaser');
$this->assertNull($teaser_display->getComponent('links'));
$this->assertFieldsInOrder($teaser_display, [
'field_featured_image',
'field_description',
]);
$this->assertContentModel([
'project' => [
'title' => [
'type' => 'string',
'cardinality' => 1,
'required' => TRUE,
'translatable' => TRUE,
'label' => 'Title',
'input type' => 'text',
'help text' => '',
],
'field_description' => [
'type' => 'string_long',
'cardinality' => 1,
'required' => TRUE,
'translatable' => TRUE,
'label' => 'Description',
'input type' => 'textarea',
'help text' => 'Describe the page content. This appears as the description in search engine results.',
],
'field_featured_image' => [
'type' => 'entity_reference',
'cardinality' => 1,
'required' => FALSE,
'translatable' => FALSE,
'label' => 'Featured image',
'input type' => 'media library',
'help text' => 'Include an image. This appears as the image in search engine results.',
],
'field_content' => [
'type' => 'text_long',
'cardinality' => 1,
'required' => FALSE,
'translatable' => TRUE,
'label' => 'Content',
'input type' => 'wysiwyg',
'help text' => 'The content of this page.',
],
'field_tags' => [
'type' => 'entity_reference',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'required' => FALSE,
'translatable' => FALSE,
'label' => 'Tags',
'input type' => 'tagify',
'help text' => 'Include tags for relevant topics.',
],
'field_project__client_name' => [
'type' => 'string',
'cardinality' => 1,
'required' => FALSE,
'translatable' => TRUE,
'label' => 'Client name',
'input type' => 'text',
'help text' => 'Include the name of the client or organization.',
],
'field_project__client_logo' => [
'type' => 'entity_reference',
'cardinality' => 1,
'required' => FALSE,
'translatable' => FALSE,
'label' => 'Client logo',
'input type' => 'media library',
'help text' => 'Include the logo of the client or organization.'
],
'field_project__client_link' => [
'type' => 'link',
'cardinality' => 1,
'required' => FALSE,
'translatable' => FALSE,
'label' => 'Client link',
'input type' => 'text',
'help text' => 'Include a link to the client or organization website.',
],
],
]);
}
public function testPathAliasPatternPrecedence(): void {
$dir = realpath(__DIR__ . '/../../../../drupal_cms_seo_basic');
$this->applyRecipe($dir);
// Confirm that projects have the expected path aliases.
$node = $this->drupalCreateNode([
'type' => 'project',
'title' => 'Test Project',
]);
$this->assertStringEndsWith("/projects/test-project", $node->toUrl()->toString());
}
}