UwWcmsBasicTest.php 108 KB
Newer Older
1
2
3
4
<?php

namespace Drupal\Tests\uw_base_profile\Functional;

5
use Drupal\Component\Serialization\Json;
6
use Drupal\Core\StringTranslation\StringTranslationTrait;
7
use Drupal\Core\Url;
8
use Drupal\Tests\BrowserTestBase;
9
use Drupal\uw_cfg_common\Service\UWService;
10
11
12
13
14
15
16
17

/**
 * Basic WCMS test.
 *
 * @group UwWcms
 */
class UwWcmsBasicTest extends BrowserTestBase {

18
19
  use StringTranslationTrait;

20
21
22
23
24
  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'uw_fdsu_theme_resp';

25
26
27
28
29
30
31
  /**
   * See https://www.drupal.org/node/1911318.
   *
   * @var string
   */
  protected $profile = 'uw_base_profile';

32
  // phpcs:disable DrupalPractice.Objects.StrictSchemaDisabled.StrictConfigSchema
33
34
35
36
  /**
   * It would be better if we didn't need this, but tests fail without it.
   *
   * @var bool
37
38
39
   *
   * @todo Remove $strictConfigSchema so that the default TRUE is used. Remove
   * this comment and the phpcs:disable comment above when doing this.
40
41
42
   */
  protected $strictConfigSchema = FALSE;

43
44
45
46
47
48
49
  /**
   * Array of user objects keyed by the role they have.
   *
   * @var array
   */
  public $drupalUsers = [];

50
51
52
53
54
55
56
  /**
   * Basic test.
   */
  public function testPage() {
    $this->drupalGet('');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('200 University Avenue West');
57

58
59
    $disabled_modules = [
      'big_pipe',
60
      'help',
61
      'search',
62
    ];
63
64
65
66
67
68
    // If uw_site_dev is disabled when fresh install a site,
    // dblog module should be disabled.
    $uw_site_dev_enabled = \Drupal::moduleHandler()->moduleExists('uw_site_dev');
    if (!$uw_site_dev_enabled) {
      $disabled_modules[] = 'dblog';
    }
69
70
71
72
    foreach ($disabled_modules as $module) {
      $enabled = \Drupal::moduleHandler()->moduleExists($module);
      $this->assertFalse($enabled, 'Module ' . $module . ' is not enabled.');
    }
73
74
75

    $this->createUsers();

76
    $this->layoutSectionConfigurationFormTest();
77
    $this->webformTests();
78
    $this->createContent();
79
    $this->taxonomies();
80
81
82
    $this->catalogTest();
    $this->schemaTest();
    $this->configBlockTest();
83
    $this->previewButtonTest();
84
    $this->layoutBuilderBrowserTest();
85
    $this->globalFooterTest();
Igor Biki's avatar
Igor Biki committed
86
87
    $this->menusTest();
    $this->dashboardTest();
88
    $this->ctaBlockTest();
89
90
91
92
    // Testing permissions is very time-consuming. So, normally do not run it.
    // @code
    // $this->permissionsTest();
    // @endcode
93
    $this->realnameTest();
94
    $this->contactContentTypeTest();
95
    $this->profileContentTypeTest();
96
    $this->ffBlockTest();
97
    $this->mediaTypesTest();
98
    $this->redirectsTest();
99
    $this->uwLdapTest();
100
    $this->ckeditorButtonsTest();
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
    $this->bannerBlockTest();
  }

  /**
   * Tests for Custom block banner.
   */
  private function bannerBlockTest() {
    $this->drupalLogin($this->drupalUsers['uw_role_site_manager']);
    $this->drupalGet('node/1/layout');
    $this->assertSession()->statusCodeEquals(200);
    $this->clickLink('Add block');
    $this->clickLink('Banner images');

    // Check 'Banner' group.
    // Banner is required.
    $banner_required = $this->getSession()->getPage()->find('xpath', "//strong[contains(text(), 'Banner')]");
    $this->assertEquals('form-required', $banner_required->getAttribute('class'));
    $this->assertEquals('edit-settings-block-form-field-uw-banner-item', $banner_required->getParent()->getAttribute('data-drupal-selector'));

    // 'No Banner added yet' exists.
    $this->assertSession()->pageTextContains('No Banner added yet.');

    // The help texts exist.
    $this->assertSession()->pageTextContains('You may add 1 to 8 banners. If more than one banner is added, they will be displayed in a carousel. For ideal display, all banners should have the same dimensions.');
    $this->assertSession()->pageTextContains('Note that all options beyond a single image banner are unsupported at this time, and are provided for future use.');

    // Check 'Add Image banner', 'Add Local video banner'
    // and 'Add Vimeo video banner'.
    $elements = [
      'Image',
      'Local video',
      'Vimeo video',
    ];
    foreach ($elements as $element) {
      $this->assertTrue($this->xpath('//input[@type="submit" and @value="Add ' . $element . ' banner"]'), 'Add banner using ' . $element);
    }

    // Check 'Settings' group.
    // 'Settings' is required.
    $settings_required = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Settings')]");
    $classes = explode(' ', $settings_required->getParent()->getParent()->getAttribute('class'));
    $class_required_fields = in_array('required-fields', $classes);
    $this->assertTrue($class_required_fields);

    // 'Slide speed' is required.
    $slide_speed_required = $this->getSession()->getPage()->find('xpath', "//label[contains(text(), 'Slide speed')]");
    $this->assertEquals('js-form-required form-required', $slide_speed_required->getAttribute('class'));
    $this->assertFieldByXPath('//input[@value="7000" and @name="settings[block_form][field_uw_slide_speed][0][value]"]', NULL, 'Default value is 7000ms.');
    $this->assertSession()->pageTextContains('Enter the time, in milliseconds, that should elapse between slides when the slideshow is playing.');

    // 'Transition speed' is required.
    $slide_speed_required = $this->getSession()->getPage()->find('xpath', "//label[contains(text(), 'Transition speed')]");
    $this->assertEquals('js-form-required form-required', $slide_speed_required->getAttribute('class'));
    $this->assertFieldByXPath('//input[@value="400" and @name="settings[block_form][field_uw_transition_speed][0][value]"]', NULL, 'Default value is 400ms.');
    $this->assertSession()->pageTextContains('Enter the time, in milliseconds, the banner transition should take to complete.');

    // Autoplay is checked by default.
    $this->assertSession()->checkboxChecked('edit-settings-block-form-field-uw-autoplay-value');
    $this->assertSession()->pageTextContains('Controls whether or not the slideshow starts immediately on page load.');

    // 'Text overlay style' is required.
    $text_style = $this->getSession()->getPage()->find('xpath', "//label[contains(text(), 'Text overlay style')]");
    $this->assertEquals('js-form-required form-required', $text_style->getAttribute('class'));
    // The selected list match the expected list.
    $expected_options = [
      'full-width' => 'Full banner width, bottom, theme colour background ("FDSU" style)',
      'inset' => 'Inset from banner, bottom, black background ("home page" style)',
      'split' => 'Split top and bottom, black and white backgrounds ("single page" style)',
      'full-overlay' => 'Full black overlay, centered text ("conference" style)',
    ];
    $options = $this->getOptions('settings[block_form][field_uw_text_overlay_style]');
    foreach ($expected_options as $key => $expected_option) {
      $this->assertEqual($options[$key], $expected_option);
    }
    // Full banner is selected as default.
    $this->assertFieldByXPath('//option[@value="full-width" and @selected="selected"]', NULL, 'Full banner width, bottom, theme colour background ("FDSU" style) is selected.');
    $this->assertSession()->pageTextContains('Note that all options other than "FDSU" style are unsupported at this time, and are provided for future use.');

    // Click 'Add Image banner'.
    $this->click('#edit-settings-block-form-field-uw-banner-item-add-more-add-more-button-uw-para-image-banner');
    $image = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Image')]");
    $this->assertEquals('fieldset-legend js-form-required form-required', $image->getAttribute('class'));
    $this->assertSession()->pageTextContains('No media items are selected.');
    $this->assertSession()->buttonExists('Add media');
    $fields = [
      'Link' => 'Provide an optional link for this banner.',
      'Big text' => 'Big text appears at a larger size, and, if both are set, above the small text.',
      'Small text' => 'Small text appears at a smaller size, and, if both are set, below the big text.',
    ];
    foreach ($fields as $key => $field) {
      $this->assertSession()->fieldExists($key);
      $this->assertSession()->pageTextContains($field);
    }

    // Click 'Add Local video banner'.
    $this->click('#edit-settings-block-form-field-uw-banner-item-add-more-add-more-button-uw-para-local-video-banner');
    $local_video = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Video')]");
    $this->assertEquals('fieldset-legend js-form-required form-required', $local_video->getAttribute('class'));
    $this->assertSession()->pageTextContains('No media items are selected.');
    $this->assertSession()->buttonExists('Add media');
    $fallback_iamge = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Fallback image')]");
    $this->assertEquals('fieldset-legend js-form-required form-required', $fallback_iamge->getAttribute('class'));
    $this->assertSession()->pageTextContains('No media items are selected.');
    $this->assertSession()->buttonExists('Add media');
    $fields = [
      'Link' => 'Provide an optional link for this banner.',
      'Big text' => 'Big text appears at a larger size, and, if both are set, above the small text.',
      'Small text' => 'Small text appears at a smaller size, and, if both are set, below the big text.',
    ];
    foreach ($fields as $key => $field) {
      $this->assertSession()->fieldExists($key);
      $this->assertSession()->pageTextContains($field);
    }

    // Click 'Add Vimeo video banner'.
    $this->click('#edit-settings-block-form-field-uw-banner-item-add-more-add-more-button-uw-para-vimeo-video-banner');
    $vimeo_video = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Vimeo video')]");
    $this->assertEquals('fieldset-legend js-form-required form-required', $vimeo_video->getAttribute('class'));
    $this->assertSession()->pageTextContains('No media items are selected.');
    $this->assertSession()->buttonExists('Add media');
    $this->assertSession()->linkExists('media add page');
    $vimeo_video = $this->getSession()->getPage()->find('xpath', "//label[contains(text(), 'Use existing media')]");
    $this->assertEquals('js-form-required form-required', $vimeo_video->getAttribute('class'));
    $this->assertSession()->fieldExists('settings[block_form][field_uw_banner_item][2][subform][field_uw_ban_fallback_image][0][target_id]');
    $this->assertSession()->linkExists('media list');
    $fields = [
      'Link' => 'Provide an optional link for this banner.',
      'Big text' => 'Big text appears at a larger size, and, if both are set, above the small text.',
      'Small text' => 'Small text appears at a smaller size, and, if both are set, below the big text.',
    ];
    foreach ($fields as $key => $field) {
      $this->assertSession()->fieldExists($key);
      $this->assertSession()->pageTextContains($field);
    }

236
237
238
239
240
241
  }

  /**
   * Test Webforms.
   */
  private function webformTests() {
242
243
244
245
246
247
248
249
250
    // Create test Webform.
    $this->drupalLogin($this->drupalUsers['uw_role_form_editor']);
    $edit = [
      'id' => 'test_form',
      'title' => 'Test Form',
      'status' => 'open',
    ];
    $this->drupalPostForm('admin/structure/webform/add', $edit, 'Save');

251
252
253
254
255
256
257
    // The variable $test_paths stores Drupal paths and permission information.
    // In this array, the keys are paths. If the value is TRUE, everyone has
    // access. Otherwise, the value must be an array of roles that have access.
    // Other roles do not have access.
    $test_paths = [
      '' => TRUE,
      'admin' => [
258
        'uw_role_site_owner',
259
260
261
262
        'uw_role_site_manager',
        'uw_role_content_editor',
        'uw_role_content_author',
      ],
263
264

      // Webform.
Liam Morland's avatar
Liam Morland committed
265
266
267
268
      'admin/structure/webform' => [
        'uw_role_form_editor',
        'uw_role_form_results_access',
      ],
269
270
271
272
273
274
275
276
277
278
279
280
      'admin/structure/webform/add' => ['uw_role_form_editor'],
      'admin/structure/webform/addons' => ['uw_role_form_editor'],
      'admin/structure/webform/config' => ['uw_role_form_editor'],
      'admin/structure/webform/config/advanced' => ['uw_role_form_editor'],
      'admin/structure/webform/config/elements' => ['uw_role_form_editor'],
      'admin/structure/webform/config/exporters' => ['uw_role_form_editor'],
      'admin/structure/webform/config/handlers' => ['uw_role_form_editor'],
      'admin/structure/webform/config/libraries' => ['uw_role_form_editor'],
      'admin/structure/webform/config/options/manage' => ['uw_role_form_editor'],
      'admin/structure/webform/config/submissions' => ['uw_role_form_editor'],
      'admin/structure/webform/config/variants' => ['uw_role_form_editor'],
      'admin/structure/webform/help' => TRUE,
Liam Morland's avatar
Liam Morland committed
281
282
283
284
      'admin/structure/webform/submissions/manage' => [
        'uw_role_form_editor',
        'uw_role_form_results_access',
      ],
285
286
      // Test Webform.
      'admin/structure/webform/manage/test_form' => ['uw_role_form_editor'],
Liam Morland's avatar
Liam Morland committed
287
288
289
290
      'admin/structure/webform/manage/test_form/results/submissions' => [
        'uw_role_form_editor',
        'uw_role_form_results_access',
      ],
291
292
293
      'admin/structure/webform/manage/test_form/settings' => ['uw_role_form_editor'],
      'form/test-form' => TRUE,
      'webform/test_form/test' => ['uw_role_form_editor'],
294
295
296
    ];
    // Test these paths with each user.
    foreach ($this->drupalUsers as $role => $user) {
297
298
299
300
      // Admin always has access so there is no point testing.
      if ($role === 'administrator') {
        continue;
      }
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
      if ($user) {
        $this->drupalLogin($user);
      }
      elseif ($this->loggedInUser) {
        $this->drupalLogout();
      }
      foreach ($test_paths as $path => $permissions) {
        // Get the expected HTTP response code.
        $expected_code = ($permissions === TRUE || in_array($role, $permissions, TRUE)) ? 200 : 403;
        // Test this path for the HTTP response code.
        $this->drupalGet($path);
        $this_code = $this->getSession()->getStatusCode();
        $message = sprintf('Response status code for %s on path %s is %d; %d expected.', $role, $path, $this_code, $expected_code);
        $this->assert(intval($this_code) === $expected_code, $message);
      }
    }
317
318
  }

319
320
321
322
323
324
325
326
327
328
329
330
  /**
   * Populate $drupalUsers with an array of users with various roles.
   */
  private function createUsers() {
    // Test if property is already populated.
    if ($this->drupalUsers) {
      return;
    }
    // Create users.
    $this->drupalUsers = ['anonymous user' => NULL];
    $roles = [
      'authenticated user',
331
      'administrator',
332
      'uw_role_site_owner',
333
334
335
      'uw_role_site_manager',
      'uw_role_content_editor',
      'uw_role_content_author',
336
337
      'uw_role_form_editor',
      'uw_role_form_results_access',
338
339
    ];
    foreach ($roles as $role) {
340
341
342
343
344
      $user = [
        'roles' => [$role],
        'edit-field-uw-first-name-0-value' => $this->randomString(),
        'edit-field-uw-last-name-0-value' => $this->randomString(),
      ];
345
346
347
348
      $this->drupalUsers[$role] = $this->createUser([], $role, FALSE, $user);
    }
  }

349
350
351
352
353
354
  /**
   * Test content creation.
   */
  private function createContent() {
    $this->drupalLogin($this->drupalUsers['uw_role_content_author']);

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
    // Make sure audience taxonomy to blog, catalog,
    // event and news item content types.
    $types = [
      'blog' => 'node/add/uw_ct_blog',
      'catalog' => 'node/add/uw_ct_catalog_item',
      'event' => 'node/add/uw_ct_event',
      'news-item' => 'node/add/uw_ct_news_item',
    ];
    foreach ($types as $key => $type) {
      $this->drupalGet($type);
      $this->assertSession()->statusCodeEquals(200);
      // Blog, event, news item have taxonomies fieldset.
      if ($key != 'catalog') {
        $taxonomies = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Taxonomies')]");
        $this->assertEquals('edit-group-uw-' . $key . '-tags', $taxonomies->getParent()->getParent()->getAttribute('id'));
      }
      $audience = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Audience')]");
      $this->assertEquals('edit-field-uw-audience--wrapper', $audience->getParent()->getParent()->getAttribute('id'));
    }

375
376
377
378
379
380
    // Test field_uw_event_map exists.
    $this->drupalGet('node/add/uw_ct_event');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertFieldByXPath('//input[@type="url" and @id="edit-field-uw-event-map-0-uri"]', NULL, 'Map link field exists.');
    $this->assertSession()->pageTextContains('Optional: provide a link to a map with the event location (e.g. https://uwaterloo.ca/map/)');

381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
    // Array of content types.
    // Keys: Content types.
    // Values: Array of extra fields and their types.
    $content_types = [
      'uw_ct_web_page' => [],
      'uw_ct_site_footer' => [],
      'uw_ct_blog' => ['edit-field-uw-blog-summary-0-value' => 'string'],
      'uw_ct_news_item' => ['edit-field-uw-news-summary-0-value' => 'string'],
      'uw_ct_event' => [
        'edit-field-uw-event-summary-0-value' => 'string',
        'edit-field-uw-event-date-0-value-date' => 'date',
        'edit-field-uw-event-date-0-value-time' => 'time',
        'edit-field-uw-event-date-0-end-value-date' => 'date',
        'edit-field-uw-event-date-0-end-value-time' => 'time',
      ],
396
      // uw_ct_sidebar is tested separately below.
397
    ];
398

399
    $content_nids = [];
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
    foreach ($content_types as $content_type => $extra_fields) {
      // Create node.
      $edit = [
        'edit-title-0-value' => $this->randomString(),
      ];
      foreach ($extra_fields as $field => $type) {
        switch ($type) {
          case 'date':
            $edit[$field] = date('Y-m-d');
            break;

          case 'time':
            $edit[$field] = date('H:i:s');
            break;

          default:
            $edit[$field] = $this->randomString();
        }
      }
      $this->drupalPostForm('node/add/' . $content_type, $edit, 'Save');
420
421
      // Make sure no 'Revert to default' on the above content type layout page.
      $this->assertSession()->buttonNotExists('Revert to defaults');
422

423
424
425
426
427
428
429
      // Get the node ID of the newly-created node, store in $content_nids.
      $nid = $this->xpath('//a[text() = "View"]');
      preg_match('/^node\/(\d+)$/', $nid[0]->getAttribute('data-drupal-link-system-path'), $matches);
      $nid = (int) $matches[1];
      $this->assert($nid > 0, 'Positive nid found.');
      $content_nids[$content_type] = $nid;

430
      // On node creation, the user is redirected to the layout edit page.
431
      $this->assertSession()->addressMatches('/^\/[a-z0-9-\/]+\/layout$/');
432
433
      // Check node title.
      $this->assertSession()->pageTextContains('Edit layout for ' . $edit['edit-title-0-value']);
434
435
      // Check that there is no moderation form.
      $this->assertSession()->linkByHrefNotExists('/admin/uw-content-moderation/');
436
437
438

      // On node edit, the user is not redirected to the layout edit page.
      $this->clickLink('Edit');
439
440
      // Store edit link for later use.
      $url = $this->getSession()->getCurrentUrl();
441

442
      // Save edit form without making changes.
443
      $this->submitForm([], 'Save');
444
      // Verify that we are not on the layout edit page.
445
446
      $this->assertSession()->pageTextContains($edit['edit-title-0-value'] . ' has been updated');
      $this->assertSession()->pageTextNotContains('Edit layout for');
447

448
449
450
451
452
      // All content types except footer have moderation form.
      if ($content_type !== 'uw_ct_site_footer') {
        $this->assertSession()->linkByHrefExists('/admin/uw-content-moderation/');
      }

453
454
455
456
      // Test "Menu Settings", "Place in site hierarchy" and "Add menu link".
      // This is custom WCMS functionality in uw_sites_all.
      if ($content_type === 'uw_ct_web_page') {
        $title = $edit['edit-title-0-value'];
457
        // This part done as admin.
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
        $this->drupalLogin($this->drupalUsers['administrator']);
        // By default, "Place in site hierarchy" is unchecked. There should be
        // no menu item.
        $this->drupalGet('admin/structure/menu/manage/main');
        $this->assertSession()->pageTextNotContains($title);
        // Check "Place in site hierarchy", creating enabled menu item.
        $edit = [
          'menu[enabled]' => TRUE,
          // The title defaults via JS to the page title. Specify since no JS.
          'menu[title]' => $title,
        ];
        $this->drupalPostForm($url, $edit, 'Save');
        $this->drupalGet('admin/structure/menu/manage/main');
        $this->assertSession()->pageTextContains($title);
        $this->assertSession()->pageTextNotContains($title . ' (disabled)');
        // Uncheck "Add menu link", making menu item be disabled.
        $edit = ['menu[place_in_menu]' => FALSE];
        $this->drupalPostForm($url, $edit, 'Save');
        $this->drupalGet('admin/structure/menu/manage/main');
        $this->assertSession()->pageTextContains($title . ' (disabled)');
478

479
480
481
482
483
        // Check that home page menu entry can be edited by admin.
        $this->assertSession()->elementExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-enabled');
        $this->assertSession()->elementExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-weight');
        $this->assertSession()->elementExists('css', 'a[href$="/admin/structure/menu/link/uw_base_profile.front_page/edit"]');

484
485
        // Return to content author.
        $this->drupalLogin($this->drupalUsers['uw_role_content_author']);
486

487
488
489
490
491
        // Check that home page menu entry cannot be edited by content author.
        $this->drupalGet('admin/structure/menu/manage/main');
        $this->assertSession()->elementNotExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-enabled');
        $this->assertSession()->elementNotExists('css', '#edit-links-menu-plugin-iduw-base-profilefront-page-weight');
        $this->assertSession()->elementNotExists('css', 'a[href$="/admin/structure/menu/link/uw_base_profile.front_page/edit"]');
492
      }
493
    }
494
495
496
497
498
499
500
501
502

    // Test uw_ct_sidebar. There is no title in the content type, only a node
    // reference field.
    $edit = [
      // The actual title is ignored, but has to be present. The number in
      // brackets is used as the nid of the page to attach this sidebar to.
      'edit-field-uw-attach-page-0-target-id' => 'Title (1)',
    ];
    $this->drupalPostForm('node/add/uw_ct_sidebar', $edit, 'Save');
503
504
505
    // Make sure no 'Revert to defaults' button on sidebar layout page.
    $this->assertSession()->buttonNotExists('Revert to defaults');

506
    // Verify that the user is redirected to the layout edit page.
507
    $this->assertSession()->addressMatches('/^\/[a-z0-9-\/]+\/layout$/');
508
    $this->assertSession()->pageTextContains('You are editing the layout for this Sidebar content item.');
509
510
511
512
513
514
515
516
517
518
519
520

    // On home page, most users do not have content moderation link.
    $this->drupalGet('');
    $this->assertSession()->linkByHrefNotExists('/admin/uw-content-moderation/');
    // Grant permission and the user has access.
    user_role_grant_permissions('uw_role_content_author', ['bypass home page protection']);
    $this->drupalGet('');
    $this->assertSession()->linkByHrefExists('/admin/uw-content-moderation/');
    // On home page, admin has content moderation link.
    $this->drupalLogin($this->drupalUsers['administrator']);
    $this->drupalGet('');
    $this->assertSession()->linkByHrefExists('/admin/uw-content-moderation/');
521
522

    // Check access for moderation form.
523
    $this->clickLink('Unpublish this content');
524
525
526
527
528
    $this->assertSession()->statusCodeEquals(200);
    $url = $this->getSession()->getCurrentUrl();
    // Check that moderation form URL is in the expected format.
    $match = preg_match(',/admin/uw-content-moderation/\d+/\d+/\d+$,', $url);
    $this->assert($match, 'Moderation form URL is in the expected format.');
529

530
531
532
533
534
535
536
    // Test home page protection.
    //
    // Login as Site Manager. Test that various controls are available, then
    // make the page the home page and test again. Also test
    // UWService::nodeIsHomePage().
    $this->drupalLogin($this->drupalUsers['uw_role_site_manager']);

537
    $this->assert(!UWService::nodeIsHomePage($content_nids['uw_ct_web_page']), 'UWService::nodeIsHomePage() correctly identifies page as not the home page.');
538
539

    // Test that certain options are available when not editing home page.
540
    $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/edit');
541
542
543
544
545
546
547
548
549
    $this->assertSession()->elementExists('css', '#edit-path-0');
    // Cannot test for #edit-menu because an empty 'div' with that exists.
    $this->assertSession()->elementExists('css', '#edit-menu-enabled');
    $this->assertSession()->elementExists('css', '#edit-menu-place-in-menu');
    // Test that the home page cannot be the parent of any item.
    $this->assertSession()->elementNotExists('css', 'option[value="main:uw_base_profile.front_page"]');
    // Delete link exists.
    $this->assertSession()->elementExists('css', 'a#edit-delete');
    // Access to delete page.
550
    $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/delete');
551
552
    $this->assertSession()->statusCodeEquals(200);

553
    // Make the page the home page.
554
    $path = \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $content_nids['uw_ct_web_page']);
555
    \Drupal::service('config.factory')->getEditable('system.site')->set('page.front', $path)->save();
556

557
    $this->assert(UWService::nodeIsHomePage($content_nids['uw_ct_web_page']), 'UWService::nodeIsHomePage() correctly identifies page as the home page.');
558
559

    // Test that certain options are not available when editing home page.
560
    $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/edit');
561

562
563
564
565
566
567
568
569
570
571
572
    $this->assertSession()->elementNotExists('css', '#edit-path-0');
    $this->assertSession()->elementNotExists('css', '#edit-promote-wrapper');
    $this->assertSession()->elementNotExists('css', '#edit-sticky-wrapper');
    // Cannot test for #edit-menu because an empty 'div' with that exists.
    $this->assertSession()->elementNotExists('css', '#edit-menu-enabled');
    $this->assertSession()->elementNotExists('css', '#edit-menu-place-in-menu');
    // Test that the home page cannot be the parent of any item.
    $this->assertSession()->elementNotExists('css', 'option[value="main:uw_base_profile.front_page"]');
    // No delete link.
    $this->assertSession()->elementNotExists('css', 'a#edit-delete');
    // No access to delete page.
573
    $this->drupalGet('node/' . $content_nids['uw_ct_web_page'] . '/delete');
574
    $this->assertSession()->statusCodeEquals(403);
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610

    // Test that admin has access to all Layout Builder configuration paths
    // and site manager has access to only some paths.
    $layout_builder_lock_test_users = [
      'administrator',
      'uw_role_site_manager',
    ];
    $layout_builder_lock_test_content_types = [
      'uw_ct_blog',
      'uw_ct_event',
      'uw_ct_news_item',
    ];
    foreach ($layout_builder_lock_test_users as $user) {
      $this->drupalLogin($this->drupalUsers[$user]);
      foreach ($layout_builder_lock_test_content_types as $content_type) {
        $nid = $content_nids[$content_type];
        $this->drupalGet('node/' . $nid . '/layout');
        $paths = [
          'layout_builder/choose/section/overrides/node.' . $nid . '/0' => FALSE,
          'layout_builder/choose/section/overrides/node.' . $nid . '/1' => TRUE,
          'layout_builder/choose/section/overrides/node.' . $nid . '/2' => TRUE,
          'layout_builder/choose/section/overrides/node.' . $nid . '/3' => FALSE,
          'layout_builder/configure/section/overrides/node.' . $nid . '/0' => FALSE,
          'layout_builder/configure/section/overrides/node.' . $nid . '/1' => TRUE,
          'layout_builder/configure/section/overrides/node.' . $nid . '/2' => FALSE,
        ];
        foreach ($paths as $path => $access) {
          if ($access || $user === 'administrator') {
            $this->assertSession()->linkByHrefExists($path);
          }
          else {
            $this->assertSession()->linkByHrefNotExists($path);
          }
        }
      }
    }
611
612
  }

613
614
615
616
617
618
619
620
621
622
623
624
  /**
   * Test taxonomies.
   */
  private function taxonomies() {
    $this->drupalLogin($this->drupalUsers['administrator']);

    $this->drupalGet('admin/structure/taxonomy/manage/uw_vocab_faculties_and_schools/overview');
    $this->assertSession()->statusCodeEquals(200);

    $this->drupalGet('admin/structure/taxonomy/manage/uw_vocab_audience/overview');
    $this->assertSession()->statusCodeEquals(200);

625
626
627
628
629
630
    $this->drupalGet('admin/structure/taxonomy/manage/uw_vocab_catalogs/overview');
    $this->assertSession()->statusCodeEquals(200);

    $this->drupalGet('admin/structure/taxonomy/manage/uw_vocab_catalog_categories/overview');
    $this->assertSession()->statusCodeEquals(200);

631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
    $this->drupalGet('admin/config/search/path');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('/catalogs/faculties-and-schools/faculty-');
    $this->assertSession()->pageTextContains('/audience/current-');
    $this->assertSession()->pageTextContains('/events/types/');

    $this->drupalGet('admin/config/search/path/patterns');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Audience path pattern');
    $this->assertSession()->pageTextContains('Vocabulary is uw_vocab_audience');
    $this->assertSession()->pageTextContains('Catalogs path pattern');
    $this->assertSession()->pageTextContains('Vocabulary is uw_vocab_catalogs');
    $this->assertSession()->pageTextContains('Catalog categories path pattern');
    $this->assertSession()->pageTextContains('Vocabulary is uw_vocab_catalog_categories');
    $this->assertSession()->pageTextContains('Faculties and schools path pattern');
    $this->assertSession()->pageTextContains('Vocabulary is uw_vocab_faculties_and_schools');
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668

    // Make sure URL alias fields off of taxonomy forms for all vocabularies.
    $vocabs = [
      'uw_vocab_audience',
      'uw_vocab_blog_tags',
      'uw_vocab_catalog_categories',
      'uw_vocab_catalogs',
      'uw_tax_event_tags',
      'uw_tax_event_type',
      'uw_vocab_faculties_and_schools',
      'uw_vocab_news_tags',
    ];
    foreach ($vocabs as $vocab) {
      // Load the term-add page.
      $this->drupalGet('admin/structure/taxonomy/manage/' . $vocab . '/add');
      $this->assertSession()->statusCodeEquals(200);
      // Check if URL alias field is off of taxomoy form.
      $this->assertSession()->pageTextNotContains('Generate automatic URL alias');
      $this->assertNoFieldById('edit-path-0-pathauto');
      $this->assertSession()->pageTextNotContains('URL alias');
      $this->assertNoFieldById('edit-path-0-alias');
    }
669
670
  }

671
  /**
Liam Morland's avatar
Liam Morland committed
672
673
674
675
676
   * Catalog tests.
   *
   * Case 1: Make sure workflows exist.
   * Case 2: Make sure roles at default install are set up as expected.
   * Case 3: Make sure "preview" button does not exist.
677
   */
678
  private function catalogTest() {
679
680
681
682
683
    // Make sure work flows exist.
    $this->drupalLogin($this->drupalUsers['administrator']);
    $this->drupalGet('admin/config/workflow/workflows/manage/uw_workflow');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('Catalog item');
684

685
686
687
688
689
690
691
692
    // Make sure only 'Basic' format is checked.
    $this->drupalGet('admin/structure/types/manage/uw_ct_catalog_item/fields/node.uw_ct_catalog_item.field_uw_catalog_summary');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->checkboxChecked('edit-third-party-settings-allowed-formats-uw-tf-basic');
    $this->assertSession()->checkboxNotChecked('edit-third-party-settings-allowed-formats-uw-tf-standard');
    $this->assertSession()->checkboxNotChecked('edit-third-party-settings-allowed-formats-uw-tf-full-html');
    $this->assertSession()->checkboxNotChecked('edit-third-party-settings-allowed-formats-plain-text');

693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
    // Make sure catalog term path pattern.
    $this->drupalGet('admin/config/search/path/patterns/uw_path_catalogs');
    $this->assertSession()->statusCodeEquals(200);
    $this->getSession()->getPage()->findField('edit-type')->getValue('Taxonomy term');
    $this->getSession()->getPage()->findField('edit-pattern')->getValue('catalogs/[term:name]');
    $this->assertSession()->checkboxChecked('edit-bundles-uw-vocab-catalogs');
    $this->getSession()->getPage()->findField('edit-label')->getValue('Catalogs path pattern');
    $this->assertSession()->checkboxChecked('edit-status');

    // Make sure taxonomy views integrator settings in uw_vocab_catalogs.
    $this->drupalGet('admin/structure/taxonomy/manage/uw_vocab_catalogs');
    $this->assertSession()->statusCodeEquals(200);
    $tvi = $this->getSession()->getPage()->find('xpath', "//span[contains(text(), 'Taxonomy Views Integrator Settings')]");
    $this->assertEquals('edit-tvi', $tvi->getParent()->getParent()->getAttribute('id'));
    $this->assertSession()->checkboxChecked('edit-tvi-enable-override');
    $this->assertOptionSelected('edit-tvi-view', 'uw_view_catalog_show_nodes');
    $this->assertOptionSelected('edit-tvi-view-display', 'catalog_a_z_page');
    $this->assertSession()->checkboxChecked('tvi-inherit-check');
    $this->assertSession()->checkboxChecked('tvi-pass-arguments');

713
    // Make sure roles at default install are set up as expected.
714
715
716
717
    $roles = [
      'uw_role_content_author',
      'uw_role_content_editor',
      'uw_role_site_manager',
718
719
    ];

720
721
722
723
724
725
726
727
    foreach ($roles as $role) {
      // Login as the given role.
      $this->drupalLogin($this->drupalUsers[$role]);
      // Prepare $edit for catalog term name.
      $edit = [
        'edit-name-0-value' => $this->randomString(),
      ];
      // Create a catalog term based on the above catalog term name.
728
      $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalogs/add', $edit, $this->t('Save'));
729
730
731
732
733
      // Prepare $edit for catalog categories term name.
      $edit = [
        'edit-name-0-value' => $this->randomString(),
      ];
      // Create a catalog categories term based on the above catalog term name.
734
      $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalog_categories/add', $edit, $this->t('Save'));
735
736
737
738
739
740
      // Prepare $edit for catalog item node.
      $edit = [
        'edit-title-0-value' => $this->randomString(),
        'edit-field-uw-catalog-summary-0-value' => $this->randomString(),
        'edit-field-uw-catalog-popularity-0-value' => rand(1, 9),
        'edit-field-uw-catalog-category-target-id-value-field' => $this->randomString(),
741
        'edit-field-uw-catalog-faculty-21' => 21,
742
        'edit-moderation-state-0-state' => 'uw_wf_needs_review',
743
744
745
      ];
      // Create a catalog item node.
      $this->drupalPostForm('node/add/uw_ct_catalog_item', $edit, 'Save');
746
747
      // Make sure "preview" button does not exist.
      $this->assertSession()->buttonNotExists('Preview');
748
    }
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
    $this->drupalLogin($this->drupalUsers['administrator']);
    // Create the first taxonomy term which the vocab is
    // catalog and the tid should be 35.
    $editCatalog = [
      'edit-name-0-value' => $this->randomMachineName(),
    ];
    $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalogs/add', $editCatalog, $this->t('Save'));
    // Create the second taxonomy term which the vocab is
    // category and the tid should be 36.
    $editCategory = [
      'edit-name-0-value' => 'apple',
    ];
    $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalog_categories/add', $editCategory, $this->t('Save'));

    // Prepare $editNode for creating a catalog item node.
    // Use tid=35 as catalog term and tid=36 (apple) as category term.
    // Select tid=15 (faculty of arts) as faculty term.
    // Select tid=8 (Staff) as audience term.
    $editNode = [
      'edit-title-0-value' => 'Test catalog item',
      'edit-field-uw-catalog-catalog-35' => 35,
      'edit-field-uw-catalog-summary-0-value' => $this->randomString(),
      'edit-field-uw-catalog-popularity-0-value' => rand(1, 9),
      'edit-field-uw-catalog-category-target-id-value-field' => 36,
      'edit-field-uw-catalog-faculty-15' => 15,
      'edit-field-uw-audience-0-8-8' => 8,
      'edit-moderation-state-0-state' => 'uw_wf_needs_review',
    ];
    // Create a catalog item node with needs review.
    $this->drupalPostForm('node/add/uw_ct_catalog_item', $editNode, 'Save');
    // Check all paths related to catalog views exist.
    $this->drupalGet('catalogs');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains('There are no catalogs available.');
    $paths = [
      'taxonomy/term/35',
      'taxonomy/term/35/new',
      'taxonomy/term/35/popular',
      'taxonomy/term/35/audience',
      'taxonomy/term/35/category',
      'taxonomy/term/35/faculty',
      'taxonomy/term/35/audience/staff',
      'taxonomy/term/35/category/apple',
      'taxonomy/term/35/faculty/faculty-of-arts',
    ];
    foreach ($paths as $path) {
      $this->drupalGet($path);
      $this->assertSession()->statusCodeEquals(200);
      // There is no published catalog item node existing.
      $this->assertSession()->pageTextContains('There are no items available.');
    }
800

801
802
803
    // Make sure Metatags display extender is enabled.
    $views_display_extender_settings = \Drupal::config('views.settings')->get('display_extenders');
    $this->assert(in_array('metatag_display_extender', $views_display_extender_settings), 'The metatags display extender is expected to be enabled.');
804
  }
805

806
807
808
  /**
   * Test schema_metatag.
   */
809
  private function schemaTest() {
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
    // Make sure the below modules are enabled.
    $modules = [
      'schema_article' => 'Schema.org Article',
      'schema_event' => 'Schema.org Event',
      'schema_metatag' => 'Schema.org Metatag',
      'schema_organization' => 'Schema.org Organization',
      'schema_service' => 'Schema.org Service',
      'schema_web_page' => 'Schema.org WebPage',
    ];

    foreach ($modules as $key => $module) {
      $enabled = \Drupal::moduleHandler()->moduleExists($key);
      $this->assertTrue($enabled, $module . ' module is not enabled.');
    }

825
826
827
828
    // Make sure the below path exists.
    $this->drupalLogin($this->drupalUsers['administrator']);
    $this->drupalGet('admin/config/search/metatag/settings');
    $this->assertSession()->statusCodeEquals(200);
829
830
831
832
833
834
835
836
837
838
839
840
841

    // Make sure content blog post some are checked, and some are not checked.
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-basic');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-advanced');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-open-graph');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-twitter-cards');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-schema-article');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-schema-event');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-schema-organization');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-schema-person');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-schema-service');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-blog-0-schema-web-page');

842
843
844
845
846
847
848
849
850
851
852
853
    // Make sure content catalog item some are checked, and some are not.
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-basic');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-advanced');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-open-graph');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-twitter-cards');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-schema-web-page');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-schema-article');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-schema-event');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-schema-organization');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-schema-person');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-catalog-item-0-schema-service');

854
855
856
857
858
859
860
861
862
863
864
865
    // Make sure content contact some are checked, and some are not.
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-basic');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-advanced');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-open-graph');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-twitter-cards');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-schema-person');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-schema-article');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-schema-event');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-schema-organization');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-schema-service');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-contact-0-schema-web-page');

866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
    // Make sure content event some are checked, and some are not checked.
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-basic');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-advanced');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-open-graph');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-twitter-cards');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-schema-event');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-schema-article');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-schema-organization');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-schema-person');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-schema-service');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-event-0-schema-web-page');

    // Make sure content news item some are checked, and some are not checked.
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-basic');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-advanced');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-open-graph');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-twitter-cards');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-schema-article');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-schema-event');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-schema-organization');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-schema-person');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-schema-service');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-news-item-0-schema-web-page');

890
891
892
893
894
895
896
897
898
899
900
901
    // Make sure content profile some are checked, and some are not.
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-basic');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-advanced');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-open-graph');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-twitter-cards');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-schema-person');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-schema-article');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-schema-event');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-schema-organization');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-schema-service');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-profile-0-schema-web-page');

902
903
904
905
906
907
908
909
910
911
912
    // Make sure content web page some are checked, and some are not checked.
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-basic');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-advanced');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-open-graph');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-twitter-cards');
    $this->assertFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-schema-web-page');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-schema-article');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-schema-event');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-schema-organization');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-schema-person');
    $this->assertNoFieldChecked('edit-entity-type-groups-node-uw-ct-web-page-0-schema-service');
913
914
915
916
917
918
919
920
921
922

    // Make sure meta tag info fields exist when
    // add a node of the given content type.
    $types = $this->getContentTypes(TRUE);
    foreach ($types as $type) {
      $this->drupalGet('node/add/' . $type);
      $this->assertSession()->statusCodeEquals(200);
      $this->assertFieldById('edit-field-uw-meta-description-0-value');
      $this->assertSession()->buttonExists('edit-field-uw-meta-image-open-button');
    }
923
  }
Igor Biki's avatar
Igor Biki committed
924

925
926
  /**
   * Test config block.
Liam Morland's avatar
Liam Morland committed
927
   *
928
   * Test help text of Block ID and hiding url alias.
929
   * Test timeline block.
930
   */
931
  private function configBlockTest() {
932
933
    $this->drupalLogin($this->drupalUsers['administrator']);

934
935
936
    $blocks = [
      'Blockquote',
      'Call to action',
937
      'CodePen',
938
      'Copy text',
Liam Morland's avatar
Liam Morland committed
939
      'Facebook',
940
941
      'Facts and figures',
      'Full width image',
942
      'Google Maps',
943
      'Image gallery',
Liam Morland's avatar
Liam Morland committed
944
      'Instagram',
945
      'Mailman subscription',
946
      'PowerBI',
947
948
949
      'Related links',
      'Remote video',
      'Tableau visualization',
Liam Morland's avatar
Liam Morland committed
950
      'Timeline',
951
952
953
954
955
956
      'Twitter',
    ];

    foreach ($blocks as $block) {
      $this->drupalGet('node/1/layout');
      $this->assertSession()->statusCodeEquals(200);
957

958
959
      // On the layout edit page to click 'Add block'.
      $this->clickLink('Add block');
960

961
962
      // Verify that Blockquote and others are on the layout edit page.
      $this->assertSession()->pageTextContains('Choose a block');
963

Liam Morland's avatar
Liam Morland committed
964
      // Click 'Blockquote'.
965
      $this->clickLink($block);
966

Liam Morland's avatar
Liam Morland committed
967
      // Show Configure block.
968
      $this->drupalPlaceBlock('layout_builder_add_block');
969

Liam Morland's avatar
Liam Morland committed
970
      // Check help text of Block ID.
971
972
973
974
975
      $this->assertSession()->pageTextContains('Block ID is an optional setting which is used to support an anchor link to this block');

      // Check if URL alias field exists.
      $this->assertSession()->pageTextNotContains('Generate automatic URL alias');
      $this->assertSession()->pageTextNotContains('URL alias');
976

Liam Morland's avatar
Liam Morland committed
977
      // Test specific blocks.
978
      switch ($block) {
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
        case 'CodePen':
          // Create CodePen block.
          $edit = [
            'edit-settings-label' => $this->randomString(),
            // Letters only, 6-7 characters.
            'edit-settings-block-form-field-codepen-id-0-value' => substr(preg_replace('/[^a-zA-Z]+/', '', $this->randomMachineName(24)), 0, 7),
            'edit-settings-block-form-field-codepen-username-0-value' => $this->randomMachineName(),
            'edit-settings-block-form-field-codepen-displayed-author-0-value' => $this->randomString(),
            // Double-quote not possible because it will make the XPath invalid
            // later in this test. In normal use, double-quote would be allowed.
            'edit-settings-block-form-field-codepen-displayed-title-0-value' => str_replace('"', '', $this->randomString()),
            'edit-settings-block-form-field-codepen-default-tabs' => 'result',
            'edit-settings-block-form-field-codepen-pixel-height-0-value' => rand(150, 1000),
          ];
          $this->submitForm($edit, 'Add block');

          // Test that the CodePen block markup appears on the page.
          $this->assertSession()->pageTextContains($edit['edit-settings-label']);
          $this->assertFieldByXPath('//div[@class="uw-codepen"]/div[
            @class="codepen"
            and @data-height="' . $edit['edit-settings-block-form-field-codepen-pixel-height-0-value'] . '"
            and @data-theme-id="dark"
For faster browsing, not all history is shown. View entire blame