Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / system / tests / src / Functional / Update / UpdatePathTestBaseFilledTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Update;
4
5 use Drupal\FunctionalTests\Update\UpdatePathTestBaseTest;
6 use Drupal\node\Entity\Node;
7 use Drupal\node\Entity\NodeType;
8 use Drupal\user\Entity\User;
9
10 /**
11  * Runs UpdatePathTestBaseTest with a dump filled with content.
12  *
13  * @group Update
14  * @group legacy
15  */
16 class UpdatePathTestBaseFilledTest extends UpdatePathTestBaseTest {
17
18   /**
19    * {@inheritdoc}
20    */
21   protected function setDatabaseDumpFiles() {
22     parent::setDatabaseDumpFiles();
23     $this->databaseDumpFiles[0] = __DIR__ . '/../../../../tests/fixtures/update/drupal-8.filled.standard.php.gz';
24   }
25
26   /**
27    * Tests that the content and configuration were properly updated.
28    */
29   public function testUpdatedSite() {
30     $this->runUpdates();
31
32     $spanish = \Drupal::languageManager()->getLanguage('es');
33
34     $expected_node_data = [
35       [1, 'article', 'en', 'Test Article - New title'],
36       [2, 'book', 'en', 'Book page'],
37       [3, 'forum', 'en', 'Forum topic'],
38       [4, 'page', 'en', 'Test page'],
39       [8, 'test_content_type', 'en', 'Test title'],
40     ];
41     foreach ($expected_node_data as $node_data) {
42       $id = $node_data[0];
43       $type = $node_data[1];
44       $langcode = $node_data[2];
45       $title = $node_data[3];
46
47       // Make sure our English nodes still exist.
48       $node = Node::load($id);
49       $this->assertEqual($node->language()->getId(), $langcode);
50       $this->assertEqual($node->getType(), $type);
51       $this->assertEqual($node->getTitle(), $title);
52       // Assert that nodes are all published.
53       $this->assertTrue($node->isPublished());
54       $this->drupalGet('node/' . $id);
55       $this->assertText($title);
56     }
57
58     // Make sure the translated node still exists.
59     $translation = Node::load(8)->getTranslation('es');
60     $this->assertEqual('Test title Spanish', $translation->getTitle());
61
62     // Make sure our alias still works.
63     $this->drupalGet('test-article');
64     $this->assertText('Test Article - New title');
65     $this->assertText('Body');
66     $this->assertText('Tags');
67
68     // Make sure a translated page exists.
69     $this->drupalGet('node/8', ['language' => $spanish]);
70     // Check for text of two comments.
71     $this->assertText('Hola');
72     $this->assertText('Hello');
73     // The user entity reference field is access restricted.
74     $this->assertNoText('Test 12');
75     // Make sure all other field labels are there.
76     for ($i = 1; $i <= 23; $i++) {
77       if ($i != 12) {
78         $this->assertText('Test ' . $i);
79       }
80     }
81
82     // Make sure the translated slogan appears.
83     $this->assertText('drupal Spanish');
84
85     // Make sure the custom block appears.
86     $this->drupalGet('<front>');
87     // Block title.
88     $this->assertText('Another block');
89     // Block body.
90     $this->assertText('Hello');
91
92     // Log in as user 1.
93     $account = User::load(1);
94     $account->passRaw = 'drupal';
95     $this->drupalLogin($account);
96
97     // Make sure we can see the access-restricted entity reference field
98     // now that we're logged in.
99     $this->drupalGet('node/8', ['language' => $spanish]);
100     $this->assertText('Test 12');
101     $this->assertLink('drupal');
102
103     // Make sure the content for node 8 is still in the edit form.
104     $this->drupalGet('node/8/edit');
105     $this->assertText('Test title');
106     $this->assertText('Test body');
107     $this->assertFieldChecked('edit-field-test-1-value');
108     $this->assertRaw('2015-08-16');
109     $this->assertRaw('test@example.com');
110     $this->assertRaw('drupal.org');
111     $this->assertText('0.1');
112     $this->assertText('0.2');
113     $this->assertRaw('+31612345678');
114     $this->assertRaw('+31612345679');
115     $this->assertText('Test Article - New title');
116     $this->assertText('test.txt');
117     $this->assertText('druplicon.small');
118     $this->assertRaw('General discussion');
119     $this->assertText('Test Article - New title');
120     $this->assertText('Test 1');
121     $this->assertRaw('0.01');
122     $this->drupalPostForm('node/8/edit', [], 'Save (this translation)');
123     $this->assertResponse(200);
124     $this->drupalGet('node/8/edit', ['language' => $spanish]);
125     $this->assertText('Test title Spanish');
126     $this->assertText('Test body Spanish');
127
128     // Make sure the user page is correct.
129     $this->drupalGet('user/3');
130     $this->assertText('usuario_test');
131     $this->assertRaw('druplicon.small');
132     $this->assertText('Test file field');
133     $this->assertLink('test.txt');
134
135     // Make sure the user is translated.
136     $this->drupalGet('user/3/translations');
137     $this->assertNoText('Not translated');
138
139     // Make sure the custom field on the user is still there.
140     $this->drupalGet('admin/config/people/accounts/fields');
141     $this->assertText('Test file field');
142
143     // Make sure the test view still exists.
144     $this->drupalGet('admin/structure/views/view/test_view');
145     $this->assertText('Test view');
146
147     // Make sure the book node exists.
148     $this->drupalGet('admin/structure/book');
149     $this->clickLink('Test Article - New title');
150     $this->assertText('Body');
151     $this->assertText('Tags');
152     $this->assertRaw('Text format');
153
154     // Make sure that users still exist.
155     $this->drupalGet('admin/people');
156     $this->assertText('usuario_test');
157     $this->assertText('drupal');
158     $this->drupalGet('user/1/edit');
159     $this->assertRaw('drupal@example.com');
160
161     // Make sure the content view works.
162     $this->drupalGet('admin/content');
163     $this->assertText('Test title');
164
165     // Make sure our custom blocks show up.
166     $this->drupalGet('admin/structure/block');
167     $this->assertText('Another block');
168     $this->assertText('Test block');
169     $this->drupalGet('admin/structure/block/block-content');
170     $this->assertText('Another block');
171     $this->assertText('Test block');
172
173     // Make sure our custom visibility conditions are correct.
174     $this->drupalGet('admin/structure/block/manage/testblock');
175     $this->assertNoFieldChecked('edit-visibility-language-langcodes-es');
176     $this->assertFieldChecked('edit-visibility-language-langcodes-en');
177     $this->assertNoFieldChecked('edit-visibility-node-type-bundles-book');
178     $this->assertFieldChecked('edit-visibility-node-type-bundles-test-content-type');
179
180     // Make sure our block is still translated.
181     $this->drupalGet('admin/structure/block/manage/testblock/translate/es/edit');
182     $this->assertRaw('Test block spanish');
183
184     // Make sure our custom text format exists.
185     $this->drupalGet('admin/config/content/formats');
186     $this->assertText('Test text format');
187     $this->drupalGet('admin/config/content/formats/manage/test_text_format');
188     $this->assertResponse('200');
189
190     // Make sure our feed still exists.
191     $this->drupalGet('admin/config/services/aggregator');
192     $this->assertText('Test feed');
193     $this->drupalGet('admin/config/services/aggregator/fields');
194     $this->assertText('field_test');
195
196     // Make sure our view appears in the overview.
197     $this->drupalGet('admin/structure/views');
198     $this->assertText('test_view');
199     $this->assertText('Test view');
200
201     // Make sure our custom forum exists.
202     $this->drupalGet('admin/structure/forum');
203     $this->assertText('Test forum');
204
205     // Make sure our custom menu exists.
206     $this->drupalGet('admin/structure/menu');
207     $this->assertText('Test menu');
208
209     // Make sure our custom menu exists.
210     $this->drupalGet('admin/structure/menu/manage/test-menu');
211     $this->clickLink('Admin');
212     // Make sure the translation for the menu is still correct.
213     $this->drupalGet('admin/structure/menu/manage/test-menu/translate/es/edit');
214     $this->assertRaw('Menu test');
215     // Make sure our custom menu link exists.
216     $this->drupalGet('admin/structure/menu/item/1/edit');
217     $this->assertFieldChecked('edit-enabled-value');
218
219     // Make sure our comment type exists.
220     $this->drupalGet('admin/structure/comment');
221     $this->assertText('Test comment type');
222     $this->drupalGet('admin/structure/comment/manage/test_comment_type/fields');
223     $this->assertText('comment_body');
224
225     // Make sure our contact form exists.
226     $this->drupalGet('admin/structure/contact');
227     $this->assertText('Test contact form');
228     $this->drupalGet('admin/structure/types');
229     $this->assertText('Test content type description');
230     $this->drupalGet('admin/structure/types/manage/test_content_type/fields');
231
232     // Make sure fields are the right type.
233     $this->assertLink('Text (formatted, long, with summary)');
234     $this->assertLink('Boolean');
235     $this->assertLink('Comments');
236     $this->assertLink('Date');
237     $this->assertLink('Email');
238     $this->assertLink('Link');
239     $this->assertLink('List (float)');
240     $this->assertLink('Telephone number');
241     $this->assertLink('Entity reference');
242     $this->assertLink('File');
243     $this->assertLink('Image');
244     $this->assertLink('Text (plain, long)');
245     $this->assertLink('List (text)');
246     $this->assertLink('Text (formatted, long)');
247     $this->assertLink('Text (plain)');
248     $this->assertLink('List (integer)');
249     $this->assertLink('Number (integer)');
250     $this->assertLink('Number (float)');
251
252     // Make sure our form mode exists.
253     $this->drupalGet('admin/structure/display-modes/form');
254     $this->assertText('New form mode');
255
256     // Make sure our view mode exists.
257     $this->drupalGet('admin/structure/display-modes/view');
258     $this->assertText('New view mode');
259     $this->drupalGet('admin/structure/display-modes/view/manage/node.new_view_mode');
260     $this->assertResponse(200);
261
262     // Make sure our other language is still there.
263     $this->drupalGet('admin/config/regional/language');
264     $this->assertText('Spanish');
265
266     // Make sure our custom date format exists.
267     $this->drupalGet('admin/config/regional/date-time');
268     $this->assertText('Test date format');
269     $this->drupalGet('admin/config/regional/date-time/formats/manage/test_date_format');
270     $this->assertOptionSelected('edit-langcode', 'es');
271
272     // Make sure our custom image style exists.
273     $this->drupalGet('admin/config/media/image-styles/manage/test_image_style');
274     $this->assertText('Test image style');
275     $this->assertText('Desaturate');
276     $this->assertText('Convert PNG');
277
278     // Make sure our custom responsive image style exists.
279     $this->drupalGet('admin/config/media/responsive-image-style/test');
280     $this->assertResponse(200);
281     $this->assertText('Test');
282
283     // Make sure our custom shortcut exists.
284     $this->drupalGet('admin/config/user-interface/shortcut');
285     $this->assertText('Test shortcut');
286     $this->drupalGet('admin/config/user-interface/shortcut/manage/test/customize');
287     $this->assertText('All content');
288
289     // Make sure our language detection settings are still correct.
290     $this->drupalGet('admin/config/regional/language/detection');
291     $this->assertFieldChecked('edit-language-interface-enabled-language-user-admin');
292     $this->assertFieldChecked('edit-language-interface-enabled-language-url');
293     $this->assertFieldChecked('edit-language-interface-enabled-language-session');
294     $this->assertFieldChecked('edit-language-interface-enabled-language-user');
295     $this->assertFieldChecked('edit-language-interface-enabled-language-browser');
296
297     // Make sure strings are still translated.
298     $this->drupalGet('admin/structure/views/view/content/translate/es/edit');
299     $this->assertText('Contenido');
300     $this->drupalPostForm('admin/config/regional/translate', ['string' => 'Full comment'], 'Filter');
301     $this->assertText('Comentario completo');
302
303     // Make sure our custom action is still there.
304     $this->drupalGet('admin/config/system/actions');
305     $this->assertText('Test action');
306     $this->drupalGet('admin/config/system/actions/configure/test_action');
307     $this->assertText('test_action');
308     $this->assertRaw('drupal.org');
309
310     // Make sure our ban still exists.
311     $this->drupalGet('admin/config/people/ban');
312     $this->assertText('8.8.8.8');
313
314     // Make sure our vocabulary exists.
315     $this->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/overview');
316
317     // Make sure our terms exist.
318     $this->assertText('Test root term');
319     $this->assertText('Test child term');
320     $this->drupalGet('taxonomy/term/3');
321     $this->assertResponse('200');
322
323     // Make sure the terms are still translated.
324     $this->drupalGet('taxonomy/term/2/translations');
325     $this->assertLink('Test root term - Spanish');
326
327     // Make sure our contact form exists.
328     $this->drupalGet('admin/structure/contact');
329     $this->assertText('Test contact form');
330     $this->drupalGet('admin/structure/contact/manage/test_contact_form');
331     $this->assertText('test@example.com');
332     $this->assertText('Hello');
333     $this->drupalGet('admin/structure/contact/manage/test_contact_form/translate/es/edit');
334     $this->assertText('Hola');
335     $this->assertRaw('Test contact form Spanish');
336
337     // Make sure our modules are still enabled.
338     $expected_enabled_modules = [
339       'action',
340       'aggregator',
341       'ban',
342       'basic_auth',
343       'block',
344       'block_content',
345       'book',
346       'breakpoint',
347       'ckeditor',
348       'color',
349       'comment',
350       'config',
351       'config_translation',
352       'contact',
353       'content_translation',
354       'contextual',
355       'datetime',
356       'dblog',
357       'editor',
358       'field',
359       'field_ui',
360       'file',
361       'filter',
362       'hal',
363       'help',
364       'history',
365       'image',
366       'language',
367       'link',
368       'locale',
369       'menu_ui',
370       'migrate',
371       'migrate_drupal',
372       'node',
373       'options',
374       'page_cache',
375       'path',
376       'quickedit',
377       'rdf',
378       'responsive_image',
379       'rest',
380       'search',
381       'serialization',
382       'shortcut',
383       'simpletest',
384       'statistics',
385       'syslog',
386       'system',
387       'taxonomy',
388       'telephone',
389       'text',
390       'toolbar',
391       'tour',
392       'tracker',
393       'update',
394       'user',
395       'views_ui',
396       'forum',
397       'menu_link_content',
398       'views',
399       'standard',
400     ];
401     foreach ($expected_enabled_modules as $module) {
402       $this->assertTrue($this->container->get('module_handler')->moduleExists($module), 'The "' . $module . '" module is still enabled.');
403     }
404
405     // Make sure our themes are still enabled.
406     $expected_enabled_themes = [
407       'bartik',
408       'classy',
409       'seven',
410       'stark',
411     ];
412     foreach ($expected_enabled_themes as $theme) {
413       $this->assertTrue($this->container->get('theme_handler')->themeExists($theme), 'The "' . $theme . '" is still enabled.');
414     }
415
416     // Ensure that the Book module's node type does not have duplicated enforced
417     // dependencies.
418     // @see system_post_update_fix_enforced_dependencies()
419     $book_node_type = NodeType::load('book');
420     $this->assertEqual(['enforced' => ['module' => ['book']]], $book_node_type->get('dependencies'));
421   }
422
423   /**
424    * {@inheritdoc}
425    */
426   protected function replaceUser1() {
427     // Do not replace the user from our dump.
428   }
429
430 }