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

namespace Drupal\Tests\uw_base_profile\Functional;

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

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

17
18
  use StringTranslationTrait;

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

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

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

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

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

57
58
    $disabled_modules = [
      'big_pipe',
59
      'help',
60
      'search',
61
    ];
62
63
64
65
66
67
    // 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';
    }
68
69
70
71
    foreach ($disabled_modules as $module) {
      $enabled = \Drupal::moduleHandler()->moduleExists($module);
      $this->assertFalse($enabled, 'Module ' . $module . ' is not enabled.');
    }
72
73
74

    $this->createUsers();

75
    $this->layoutSectionConfigurationFormTest();
76
    $this->webformTests();
77
    $this->createContent();
78
    $this->taxonomies();
79
80
81
    $this->catalogTest();
    $this->schemaTest();
    $this->configBlockTest();
82
    $this->previewButtonTest();
83
    $this->layoutBuilderBrowserTest();
84
    $this->globalFooterTest();
Igor Biki's avatar
Igor Biki committed
85
86
    $this->menusTest();
    $this->dashboardTest();
87
    $this->ctaBlockTest();
88
    $this->permissionsTest();
89
    $this->realnameTest();
90
    $this->contactContentTypeTest();
91
    $this->profileContentTypeTest();
92
    $this->ffBlockTest();
93
    $this->mediaTypesTest();
94
    $this->redirectsTest();
95
96
97
98
99
100
  }

  /**
   * Test Webforms.
   */
  private function webformTests() {
101
102
103
104
105
106
107
108
109
    // 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');

110
111
112
113
114
115
116
    // 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' => [
117
        'uw_role_site_owner',
118
119
120
121
        'uw_role_site_manager',
        'uw_role_content_editor',
        'uw_role_content_author',
      ],
122
123

      // Webform.
Liam Morland's avatar
Liam Morland committed
124
125
126
127
      'admin/structure/webform' => [
        'uw_role_form_editor',
        'uw_role_form_results_access',
      ],
128
129
130
131
132
133
134
135
136
137
138
139
      '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
140
141
142
143
      'admin/structure/webform/submissions/manage' => [
        'uw_role_form_editor',
        'uw_role_form_results_access',
      ],
144
145
      // Test Webform.
      'admin/structure/webform/manage/test_form' => ['uw_role_form_editor'],
Liam Morland's avatar
Liam Morland committed
146
147
148
149
      'admin/structure/webform/manage/test_form/results/submissions' => [
        'uw_role_form_editor',
        'uw_role_form_results_access',
      ],
150
151
152
      'admin/structure/webform/manage/test_form/settings' => ['uw_role_form_editor'],
      'form/test-form' => TRUE,
      'webform/test_form/test' => ['uw_role_form_editor'],
153
154
155
    ];
    // Test these paths with each user.
    foreach ($this->drupalUsers as $role => $user) {
156
157
158
159
      // Admin always has access so there is no point testing.
      if ($role === 'administrator') {
        continue;
      }
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
      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);
      }
    }
176
177
  }

178
179
180
181
182
183
184
185
186
187
188
189
  /**
   * 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',
190
      'administrator',
191
      'uw_role_site_owner',
192
193
194
      'uw_role_site_manager',
      'uw_role_content_editor',
      'uw_role_content_author',
195
196
      'uw_role_form_editor',
      'uw_role_form_results_access',
197
198
    ];
    foreach ($roles as $role) {
199
200
201
202
203
      $user = [
        'roles' => [$role],
        'edit-field-uw-first-name-0-value' => $this->randomString(),
        'edit-field-uw-last-name-0-value' => $this->randomString(),
      ];
204
205
206
207
      $this->drupalUsers[$role] = $this->createUser([], $role, FALSE, $user);
    }
  }

208
209
210
211
212
213
  /**
   * Test content creation.
   */
  private function createContent() {
    $this->drupalLogin($this->drupalUsers['uw_role_content_author']);

214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
    // 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'));
    }

234
235
236
237
238
239
    // 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/)');

240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
    // 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',
      ],
255
      // uw_ct_sidebar is tested separately below.
256
    ];
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

    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');
278
279

      // On node creation, the user is redirected to the layout edit page.
280
281
282
      $this->assertSession()->addressMatches(',^/node/\d+/layout,');
      // Check node title.
      $this->assertSession()->pageTextContains('Edit layout for ' . $edit['edit-title-0-value']);
283
284
      // Check that there is no moderation form.
      $this->assertSession()->linkByHrefNotExists('/admin/uw-content-moderation/');
285
286
287

      // On node edit, the user is not redirected to the layout edit page.
      $this->clickLink('Edit');
288
289
290
      // Store edit link for later use.
      $url = $this->getSession()->getCurrentUrl();
      // Save edit form without making changes.
291
      $this->submitForm([], 'Save');
292
      // Verify that we are not on the layout edit page.
293
294
      $this->assertSession()->pageTextContains($edit['edit-title-0-value'] . ' has been updated');
      $this->assertSession()->pageTextNotContains('Edit layout for');
295

296
297
298
299
300
      // All content types except footer have moderation form.
      if ($content_type !== 'uw_ct_site_footer') {
        $this->assertSession()->linkByHrefExists('/admin/uw-content-moderation/');
      }

301
302
303
304
      // 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'];
305
        // This part done as admin.
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
        $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)');
326

327
328
329
330
331
        // 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"]');

332
333
        // Return to content author.
        $this->drupalLogin($this->drupalUsers['uw_role_content_author']);
334

335
336
337
338
339
340
        // 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"]');

341
        // Parse $url for nid. Save for later use.
342
        preg_match(',/node/(\d+),', $url, $matches);
343
344
345
        $web_page_nid = (int) $matches[1];
        unset($matches);
        $this->assert($web_page_nid > 0, 'Positive nid found.');
346
      }
347
    }
348
349
350
351
352
353
354
355
356
357
358
359

    // 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');
    // Verify that the user is redirected to the layout edit page.
    $this->assertSession()->addressMatches(',^/node/\d+/layout,');
    $this->assertSession()->pageTextContains('You are editing the layout for this Sidebar content item.');
360
361
362
363
364
365
366
367
368
369
370
371

    // 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/');
372
373

    // Check access for moderation form.
374
    $this->clickLink('Unpublish this content');
375
376
377
378
379
    $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.');
380

381
382
383
384
385
386
387
    // 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']);

388
    $this->assert(!UWService::nodeIsHomePage($web_page_nid), 'UWService::nodeIsHomePage() correctly identifies page as not the home page.');
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403

    // Test that certain options are available when not editing home page.
    $this->drupalGet('node/' . $web_page_nid . '/edit');
    $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.
    $this->drupalGet('node/' . $web_page_nid . '/delete');
    $this->assertSession()->statusCodeEquals(200);

404
405
406
    // Make the page the home page.
    $path = \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $web_page_nid);
    \Drupal::service('config.factory')->getEditable('system.site')->set('page.front', $path)->save();
407

408
    $this->assert(UWService::nodeIsHomePage($web_page_nid), 'UWService::nodeIsHomePage() correctly identifies page as the home page.');
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424

    // Test that certain options are not available when editing home page.
    $this->drupalGet('node/' . $web_page_nid . '/edit');
    $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.
    $this->drupalGet('node/' . $web_page_nid . '/delete');
    $this->assertSession()->statusCodeEquals(403);
425
426
  }

427
428
429
430
431
432
433
434
435
436
437
438
  /**
   * 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);

439
440
441
442
443
444
    $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);

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
    $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');
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482

    // 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');
    }
483
484
  }

485
  /**
Liam Morland's avatar
Liam Morland committed
486
487
488
489
490
   * 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.
491
   */
492
  private function catalogTest() {
493
494
495
496
497
    // 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');
498

499
500
501
502
503
504
505
506
    // 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');

507
    // Make sure roles at default install are set up as expected.
508
509
510
511
    $roles = [
      'uw_role_content_author',
      'uw_role_content_editor',
      'uw_role_site_manager',
512
513
    ];

514
515
516
517
518
519
520
521
    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.
522
      $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalogs/add', $edit, $this->t('Save'));
523
524
525
526
527
      // 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.
528
      $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalog_categories/add', $edit, $this->t('Save'));
529
530
531
532
533
534
      // 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(),
535
        'edit-field-uw-catalog-faculty-21' => 21,
536
        'edit-moderation-state-0-state' => 'uw_wf_needs_review',
537
538
539
      ];
      // Create a catalog item node.
      $this->drupalPostForm('node/add/uw_ct_catalog_item', $edit, 'Save');
540
541
      // Make sure "preview" button does not exist.
      $this->assertSession()->buttonNotExists('Preview');
542
    }
543
  }
544

545
546
547
  /**
   * Test schema_metatag.
   */
548
  private function schemaTest() {
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
    // 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.');
    }

564
565
566
567
    // Make sure the below path exists.
    $this->drupalLogin($this->drupalUsers['administrator']);
    $this->drupalGet('admin/config/search/metatag/settings');
    $this->assertSession()->statusCodeEquals(200);
568
569
570
571
572
573
574
575
576
577
578
579
580

    // 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');

581
582
583
584
585
586
587
588
589
590
591
592
    // 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');

593
594
595
596
597
598
599
600
601
602
603
604
    // 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');

605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
    // 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');

629
630
631
632
633
634
635
636
637
638
639
640
    // 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');

641
642
643
644
645
646
647
648
649
650
651
    // 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');
652
653
654
655
656
657
658
659
660
661

    // 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');
    }
662
  }
Igor Biki's avatar
Igor Biki committed
663

664
665
  /**
   * Test config block.
Liam Morland's avatar
Liam Morland committed
666
   *
667
   * Test help text of Block ID and hiding url alias.
668
   * Test timeline block.
669
   */
670
  private function configBlockTest() {
671
672
    $this->drupalLogin($this->drupalUsers['administrator']);

673
674
675
676
    $blocks = [
      'Blockquote',
      'Call to action',
      'Copy text',
Liam Morland's avatar
Liam Morland committed
677
      'Facebook',
678
679
      'Facts and figures',
      'Full width image',
680
      'Google Maps',
681
      'Image gallery',
Liam Morland's avatar
Liam Morland committed
682
      'Instagram',
683
684
685
686
      'Mailman subscription',
      'Related links',
      'Remote video',
      'Tableau visualization',
Liam Morland's avatar
Liam Morland committed
687
      'Timeline',
688
689
690
691
692
693
      'Twitter',
    ];

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

695
696
      // On the layout edit page to click 'Add block'.
      $this->clickLink('Add block');
697

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

Liam Morland's avatar
Liam Morland committed
701
      // Click 'Blockquote'.
702
      $this->clickLink($block);
703

Liam Morland's avatar
Liam Morland committed
704
      // Show Configure block.
705
      $this->drupalPlaceBlock('layout_builder_add_block');
706

Liam Morland's avatar
Liam Morland committed
707
      // Check help text of Block ID.
708
709
710
711
712
      $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');
713
714

      // Test Tableau block.
715
      switch ($block) {
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
        case 'Google Maps':
          // Create Google Maps block.
          $edit = [
            'edit-settings-label' => $this->randomString(),
            'edit-settings-block-form-field-gmaps-embedded-url-0-uri' => 'https://www.google.com/maps/embed?pb=' . $this->randomMachineName(),
            'edit-settings-block-form-field-gmaps-height-0-value' => rand(150, 1000),
          ];
          $this->submitForm($edit, 'Add block');

          // Test that the Google Maps block markup appears on the page.
          $this->assertSession()->pageTextContains($edit['edit-settings-label']);
          $this->assertFieldByXPath('//div[@class="uw-google-maps"]/div[text()="Enable JavaScript to view map."]');
          $this->assertFieldByXPath('//div[@class="uw-google-maps"]/iframe[@height="' . $edit['edit-settings-block-form-field-gmaps-height-0-value'] . '" and @src="' . $edit['edit-settings-block-form-field-gmaps-embedded-url-0-uri'] . '"]');
          break;

731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
        case 'Tableau visualization':
          // Create Tableau block.
          $edit = [
            'edit-settings-label' => $this->randomString(),
            'edit-settings-block-form-field-uw-tbl-server' => 'Public',
            'edit-settings-block-form-field-uw-tbl-site-name-0-value' => $this->randomString(),
            'edit-settings-block-form-field-uw-tbl-tableau-name-0-value' => $this->randomString(),
            'edit-settings-block-form-field-uw-tbl-tableau-height-0-value' => rand(100, 1000),
            'edit-settings-block-form-field-uw-tbl-display-tabs' => 'Yes',
          ];
          $this->submitForm($edit, 'Add block');

          // Test that the appropriate Tableau block markup appears on the page.
          $this->assertSession()->pageTextContains($edit['edit-settings-label']);
          $this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="host_url" and @value="https://public.tableau.com/"]');
          $this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="site_root" and @value="' . $edit['edit-settings-block-form-field-uw-tbl-site-name-0-value'] . '"]');
          $this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="name" and @value="' . $edit['edit-settings-block-form-field-uw-tbl-tableau-name-0-value'] . '"]');
          $this->assertFieldByXPath('//object[@class="tableauViz"]/param[@name="tabs" and @value="yes"]');
          $this->assertFieldByXPath('//div[@class="uw-tableau__wrapper"]/script');
          $this->assertRaw("vizElement.style.height = '" . $edit['edit-settings-block-form-field-uw-tbl-tableau-height-0-value'] . "px';");
          break;
752
      }
753
    }
754
755
756
757
758
759
760
761

    // Test timeline Step 1: Visit the home page layout.
    $this->drupalGet('node/1/layout');
    $this->assertSession()->statusCodeEquals(200);

    // Test timeline Step 2: Look on the layout edit page to click 'Add block'.
    $this->clickLink('Add block');

Liam Morland's avatar
Liam Morland committed
762
763
    // Test timeline Step 3: Verify that Blockquote and others are on the
    // layout edit page.
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
    $this->assertSession()->pageTextContains('Choose a block');

    // Test timeline Step 4: Look on the page for the 'Timeline' link.
    $this->assertSession()->linkExists('Timeline');

    // Test timeline Step 5: Click 'Timeline'.
    $this->clickLink('Timeline');

    // Test timeline Step 6: Show Configure block (pop-up window).
    $this->drupalPlaceBlock('layout_builder_add_block');

    // Test timeline Step 7: Check all fields and buttons of timeline block.
    $this->assertSession()->pageTextContains('Title');
    $this->assertFieldById('edit-settings-label');
    $this->assertSession()->pageTextContains('Timeline style');
    $this->assertFieldById('edit-settings-block-form-field-uw-timeline-style');
    $this->assertSession()->pageTextContains('Timeline sort');
    $this->assertFieldById('edit-settings-block-form-field-uw-timeline-sort');
    $this->assertSession()->pageTextContains('Date');
    $this->assertFieldById('edit-settings-block-form-field-uw-timeline-0-subform-field-uw-timeline-date-0-value-date');
    $this->assertSession()->pageTextContains('Headline');
    $this->assertFieldById('edit-settings-block-form-field-uw-timeline-0-subform-field-uw-timeline-headline-0-value');
    $this->assertSession()->pageTextContains('One or both of the "Headline" and "Content" fields must be populated.');
    $this->assertSession()->pageTextContains('PHOTO');
    $this->assertSession()->buttonExists('Add media');
    $this->assertSession()->pageTextContains('One media item remaining.');
    $this->assertSession()->pageTextContains('Link');
    $this->assertSession()->pageTextContains('Links the entire content to a URL. If entered, do not use links inside the content itself.');
    $this->assertSession()->pageTextContains('Content');
    $this->assertSession()->buttonExists('Add Timeline');
794
  }
Liam Morland's avatar
Liam Morland committed
795

796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
  /**
   * Test preview button option.
   */
  private function previewButtonTest() {

    // Administrator login.
    $this->drupalLogin($this->drupalUsers['administrator']);

    // Add new content type.
    $this->drupalGet('admin/structure/types/add');
    // Test that "Preview before submitting" is set to "Disabled".
    $this->assertFieldChecked('edit-preview-mode-0');
    $this->assertNoFieldChecked('edit-preview-mode-1');
    $this->assertNoFieldChecked('edit-preview-mode-2');

811
    $types = $this->getContentTypes();
812
813
814
815
816
817
818
819
    foreach ($types as $type) {
      // Load the node-add page.
      $this->drupalGet('node/add/' . $type);
      // Preview button doesn't exist.
      $this->assertSession()->buttonNotExists('edit-preview');
    }
  }

820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
  /**
   * A function to get all UW content types.
   *
   * @param bool $filter
   *   When TRUE, return only content types that have metatag enabled.
   *
   * @return array
   *   An array of all UW content types filtered by TRUE/FALSE.
   */
  public function getContentTypes(bool $filter = FALSE): array {

    // This is the list of all UW content types, with a TRUE/FALSE, indicating
    // whether or not a metatag tag can be attached to this content type.
    $content_types = [
      'uw_ct_blog' => TRUE,
      'uw_ct_catalog_item' => TRUE,
836
      'uw_ct_contact' => TRUE,
837
838
      'uw_ct_event' => TRUE,
      'uw_ct_news_item' => TRUE,
839
      'uw_ct_profile' => TRUE,
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
      'uw_ct_sidebar' => FALSE,
      'uw_ct_site_footer' => FALSE,
      'uw_ct_web_page' => TRUE,
    ];

    $return_content_types = [];
    foreach ($content_types as $key => $value) {
      if (($filter && $value) || !$filter) {
        $return_content_types[] = $key;
      }
    }

    return $return_content_types;
  }

855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
  /**
   * Test Layout Builder Browser.
   *
   * Test Layout builder browser configuration and its weights.
   */
  private function layoutBuilderBrowserTest() {

    // Administrator login.
    $this->drupalLogin($this->drupalUsers['administrator']);
    // Go to Layout Builder Browser configuration page.
    $this->drupalGet('admin/config/content/layout-builder-browser');
    $this->assertSession()->statusCodeEquals(200);
    // Items include Content, External embeds, Listings,
    // Searches, Teasers and Webforms, and blocks related.
    $items = [
      '.region-title-uw_bc_content',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-blockquote"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-call-to-action"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-copy-text"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-facts-and-figures"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-image"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-mailman"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-related-links"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-timeline"]',
      '.region-title-uw_bc_external_embeds',
880
      'tr[data-drupal-selector="edit-categories-uw-lbb-facebook"]',
881
882
883
884
885
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-google-maps"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-instagram"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-powerbi"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-remote-video"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-tableau"]',
886
      'tr[data-drupal-selector="edit-categories-uw-lbb-twitter"]',
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
      '.region-title-uw_bc_listings',
      'tr[data-drupal-selector="edit-categories-uw-cbl-multi-type-list"]',
      'tr[data-drupal-selector="edit-categories-views-blockuw-view-blogs-blogs-listing-block"]',
      'tr[data-drupal-selector="edit-categories-views-blockuw-view-events-events-listing-block"]',
      'tr[data-drupal-selector="edit-categories-views-blockuw-view-news-items-news-items-listing-block"]',
      '.region-title-uw_bc_searches',
      '.region-title-uw_bc_teasers',
      'tr[data-drupal-selector="edit-categories-uw-cbl-blog-teaser"]',
      'tr[data-drupal-selector="edit-categories-uw-cbl-event-teaser"]',
      'tr[data-drupal-selector="edit-categories-uw-cbl-news-teaser"]',
      '.region-title-uw_bc_webforms',
      'tr[data-drupal-selector="edit-categories-webform-block"]',
    ];
    foreach ($items as $item) {
      $this->assertSession()->elementExists('css', $item);
    }

    // All weights except the below three fields are 0.
    // The weight of blog post list is -2.
    // The weight of event list is -1.
    // The weight of news item list is 1.
    $this->assertOptionSelected('edit-categories-uw-cbl-multi-type-list-weight', '0');
    $this->assertOptionSelected('edit-categories-views-blockuw-view-blogs-blogs-listing-block-weight', '-2');
    $this->assertOptionSelected('edit-categories-views-blockuw-view-events-events-listing-block-weight', '-1');
    $this->assertOptionSelected('edit-categories-views-blockuw-view-news-items-news-items-listing-block-weight', '1');
912
  }
Lily Yan's avatar
Lily Yan committed
913

914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
  /**
   * Test global footer.
   *
   * Test update territorial acknowledgement.
   * Test update the 'Media' link to read 'News'.
   */
  private function globalFooterTest() {
    $this->drupalGet('');
    $this->assertSession()->statusCodeEquals(200);
    // Find all 'News' links.
    $news = $this->getSession()->getPage()->findAll('xpath', "//span[contains(text(), 'News')]");
    // Current we have two 'News' links.
    $this->assertCount(2, $news);
    // Make sure the second 'News' link is 'uwaterloo.ca/news'.
    $this->assertEquals('https://uwaterloo.ca/news/', $news[1]->getParent()->getAttribute('href'));
    // Media link doesn't exist.
    $this->assertSession()->linkNotExists('Media');
    // 'the land granted to the Six Nations' can be found.
    $this->assertSession()->pageTextContains('the land granted to the Six Nations');
933
934
  }

Lily Yan's avatar
Lily Yan committed
935
936
937
938
939
940
941
942
943
944
945
946
  /**
   * Test menu links.
   *
   * Test content management menu links.
   * Test site information menu links.
   */
  private function menusTest() {
    // Administrator login.
    $this->drupalLogin($this->drupalUsers['administrator']);
    // Go to content management menu links.
    $this->drupalGet('admin/structure/menu/manage/uw-menu-content-management');
    $this->assertSession()->statusCodeEquals(200);
947

Lily Yan's avatar
Lily Yan committed
948
949
    // Check content management menu links.
    $content_links = [
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
      'node/add/uw_ct_blog' => 'Blog post',
      'admin/structure/taxonomy/manage/uw_vocab_blog_tags/add' => 'Add blog tag',
      'admin/structure/taxonomy/manage/uw_vocab_blog_tags/overview' => 'List blog tags',
      'node/add/uw_ct_catalog_item' => 'Catalog item',
      'admin/structure/taxonomy/manage/uw_vocab_catalog_categories/add' => 'Add catalog category',
      'admin/structure/taxonomy/manage/uw_vocab_catalogs/add' => 'Add catalog',
      'admin/structure/taxonomy/manage/uw_vocab_catalog_categories/overview' => 'List catalog categories',
      'admin/structure/taxonomy/manage/uw_vocab_catalogs/overview' => 'List catalogs',
      'node/add/uw_ct_event' => 'Event',
      'admin/structure/taxonomy/manage/uw_tax_event_tags/add' => 'Add event tag',
      'admin/structure/taxonomy/manage/uw_tax_event_type/add' => 'Add event type',
      'admin/structure/taxonomy/manage/uw_tax_event_tags/overview' => 'List event tags',
      'admin/structure/taxonomy/manage/uw_tax_event_type/overview' => 'List event types',
      'node/add/uw_ct_news_item' => 'News item',
      'admin/structure/taxonomy/manage/uw_vocab_news_tags/add' => 'Add news tag',
      'admin/structure/taxonomy/manage/uw_vocab_news_tags/overview' => 'List news tags',
966
      'node/add/uw_ct_sidebar' => 'Sidebar',
967
968
969
970
      'node/add/uw_ct_site_footer' => 'Site footer',
      'node/add/uw_ct_web_page' => 'Web page',
      'admin/structure/webform/add' => 'Form',
      'admin/structure/webform/submissions/manage' => 'Manage submissions',
971
      'admin/structure/taxonomy/manage/uw_vocab_audience/add' => 'Audience',
972
      'admin/structure/taxonomy/manage/uw_vocab_audience/overview' => 'List terms',
973
974
975
      /* Conflicting links Manage, there is one found in admin top bar.
      'admin/structure/taxonomy/manage/uw_vocab_audience' => 'Manage',
       */
Lily Yan's avatar
Lily Yan committed
976
977
978
    ];
    foreach ($content_links as $key => $item) {
      $this->assertSession()->linkExists($item);
979
      $this->assertEquals(base_path() . $key, $this->getSession()->getPage()->findLink($item)->getAttribute('href'));
Lily Yan's avatar
Lily Yan committed
980
981
982
983
984
985
    }
    // Go to site information menu links.
    $this->drupalGet('admin/structure/menu/manage/uw-menu-site-management');
    $this->assertSession()->statusCodeEquals(200);
    // Check site information menu links.
    $site_links = [
986
987
      base_path() . 'admin/content-access' => 'Content access',
      base_path() . 'admin/structure/menu' => 'Menus',
988
      base_path() . 'admin/config/user-interface/shortcut' => 'Shortcuts',
Lily Yan's avatar
Lily Yan committed
989
990
991
992
993
994
995
      'mailto:rt-ist-wcms@rt.uwaterloo.ca' => 'Submit request',
      'https://uwaterloo.ca/web-resources/wcms-users/training-and-support/wcms-how-documents' => 'WCMS how-to documents',
    ];
    foreach ($site_links as $key => $item) {
      $this->assertSession()->linkExists($item);
      $this->assertEquals($key, $this->getSession()->getPage()->findLink($item)->getAttribute('href'));
    }
996
997
998
999
1000

    // Test that main menu has weight of -51.
    $this->drupalGet('admin/structure/menu/link/uw_base_profile.front_page/edit');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementExists('css', 'input#edit-weight[value="-51"]');
For faster browsing, not all history is shown. View entire blame