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