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

namespace Drupal\Tests\uw_base_profile\Functional;

5
use Drupal\Core\StringTranslation\StringTranslationTrait;
6
7
8
9
10
11
12
13
14
use Drupal\Tests\BrowserTestBase;

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

15
16
  use StringTranslationTrait;

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

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

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

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

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

    $big_pipe_enabled = \Drupal::moduleHandler()->moduleExists('big_pipe');
    $this->assertFalse($big_pipe_enabled, 'BigPipe module is not enabled.');
57
58
59

    $this->createUsers();

60
    $this->webformTests();
61
62

    $this->createContent();
63
64

    $this->taxonomies();
65

66
    $this->catalogTest();
67

68
    $this->schemaTest();
69

70
    $this->configBlockTest();
71
72

    $this->previewButtonTest();
73

74
    $this->layoutBuilderBrowserTest();
75

76
    $this->globalFooterTest();
Lily Yan's avatar
Lily Yan committed
77

Igor Biki's avatar
Igor Biki committed
78
79
80
81
    $this->menusTest();

    $this->dashboardTest();

82
    $this->ctaBlockTest();
83
84
85
86
87
88
  }

  /**
   * Test Webforms.
   */
  private function webformTests() {
89
90
91
92
93
94
95
96
97
    // 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');

98
99
100
101
102
103
104
105
106
107
108
    // 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' => [
        'uw_role_site_manager',
        'uw_role_content_editor',
        'uw_role_content_author',
      ],
109
110

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

166
167
168
169
170
171
172
173
174
175
176
177
  /**
   * 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',
178
      'administrator',
179
180
181
      'uw_role_site_manager',
      'uw_role_content_editor',
      'uw_role_content_author',
182
183
      'uw_role_form_editor',
      'uw_role_form_results_access',
184
185
186
187
188
189
190
    ];
    foreach ($roles as $role) {
      $user = ['roles' => [$role]];
      $this->drupalUsers[$role] = $this->createUser([], $role, FALSE, $user);
    }
  }

191
192
193
194
195
196
  /**
   * Test content creation.
   */
  private function createContent() {
    $this->drupalLogin($this->drupalUsers['uw_role_content_author']);

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
    // 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',
      ],
212
      // uw_ct_sidebar is tested separately below.
213
    ];
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234

    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');
235
236

      // On node creation, the user is redirected to the layout edit page.
237
238
239
      $this->assertSession()->addressMatches(',^/node/\d+/layout,');
      // Check node title.
      $this->assertSession()->pageTextContains('Edit layout for ' . $edit['edit-title-0-value']);
240
241
242

      // On node edit, the user is not redirected to the layout edit page.
      $this->clickLink('Edit');
243
244
245
      // Store edit link for later use.
      $url = $this->getSession()->getCurrentUrl();
      // Save edit form without making changes.
246
      $this->submitForm([], 'Save');
247
      // Verify that we are not on the layout edit page.
248
249
      $this->assertSession()->pageTextContains($edit['edit-title-0-value'] . ' has been updated');
      $this->assertSession()->pageTextNotContains('Edit layout for');
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275

      // 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'];
        $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)');
      }
276
    }
277
278
279
280
281
282
283
284
285
286
287
288

    // 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.');
289
290
  }

291
292
293
294
295
296
297
298
299
300
301
302
  /**
   * 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);

303
304
305
306
307
308
    $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);

309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
    $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');
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346

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

349
  /**
Liam Morland's avatar
Liam Morland committed
350
351
352
353
354
   * 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.
355
   */
356
  private function catalogTest() {
357
358
359
360
361
    // 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');
362

363
    // Make sure roles at default install are set up as expected.
364
365
366
367
    $roles = [
      'uw_role_content_author',
      'uw_role_content_editor',
      'uw_role_site_manager',
368
369
    ];

370
371
372
373
374
375
376
377
    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.
378
      $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalogs/add', $edit, $this->t('Save'));
379
380
381
382
383
      // 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.
384
      $this->drupalPostForm('admin/structure/taxonomy/manage/uw_vocab_catalog_categories/add', $edit, $this->t('Save'));
385
386
387
388
389
390
      // 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(),
391
        'edit-field-uw-catalog-faculty-21' => 21,
392
        'edit-moderation-state-0-state' => 'uw_wf_needs_review',
393
394
395
      ];
      // Create a catalog item node.
      $this->drupalPostForm('node/add/uw_ct_catalog_item', $edit, 'Save');
396
397
      // Make sure "preview" button does not exist.
      $this->assertSession()->buttonNotExists('Preview');
398
    }
399
  }
400

401
402
403
  /**
   * Test schema_metatag.
   */
404
  private function schemaTest() {
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
    // 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.');
    }

420
421
422
423
    // Make sure the below path exists.
    $this->drupalLogin($this->drupalUsers['administrator']);
    $this->drupalGet('admin/config/search/metatag/settings');
    $this->assertSession()->statusCodeEquals(200);
424
425
426
427
428
429
430
431
432
433
434
435
436

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

437
438
439
440
441
442
443
444
445
446
447
448
    // 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');

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

    // 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');
484
485
486
487
488
489
490
491
492
493

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

496
497
  /**
   * Test config block.
Liam Morland's avatar
Liam Morland committed
498
   *
499
   * Test help text of Block ID and hiding url alias.
500
   * Test timeline block.
501
   */
502
  private function configBlockTest() {
503
504
    $this->drupalLogin($this->drupalUsers['administrator']);

505
506
507
508
509
510
511
512
513
514
    $blocks = [
      'Blockquote',
      'Call to action',
      'Copy text',
      'Expand/collapse',
      'Facts and figures',
      'Full width image',
      'Image gallery',
      'Mailman subscription',
      'Related links',
515
      'Timeline',
516
517
518
519
520
521
522
523
524
525
      'Facebook',
      'Instagram',
      'Remote video',
      'Tableau visualization',
      'Twitter',
    ];

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

527
528
      // On the layout edit page to click 'Add block'.
      $this->clickLink('Add block');
529

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

Liam Morland's avatar
Liam Morland committed
533
      // Click 'Blockquote'.
534
      $this->clickLink($block);
535

Liam Morland's avatar
Liam Morland committed
536
      // Show Configure block.
537
      $this->drupalPlaceBlock('layout_builder_add_block');
538

Liam Morland's avatar
Liam Morland committed
539
      // Check help text of Block ID.
540
541
542
543
544
545
      $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');
    }
546
547
548
549
550
551
552
553

    // 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
554
555
    // Test timeline Step 3: Verify that Blockquote and others are on the
    // layout edit page.
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
    $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');
586
  }
Liam Morland's avatar
Liam Morland committed
587

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
  /**
   * 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');

603
    $types = $this->getContentTypes();
604
605
606
607
608
609
610
611
    foreach ($types as $type) {
      // Load the node-add page.
      $this->drupalGet('node/add/' . $type);
      // Preview button doesn't exist.
      $this->assertSession()->buttonNotExists('edit-preview');
    }
  }

612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
  /**
   * 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,
      'uw_ct_event' => TRUE,
      'uw_ct_news_item' => TRUE,
      '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;
  }

645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
  /**
   * 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-expand-collapse"]',
      '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',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-facebook"]',
      '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"]',
      'tr[data-drupal-selector="edit-categories-inline-blockuw-cbl-twitter"]',
      '.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');
703
  }
Lily Yan's avatar
Lily Yan committed
704

705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
  /**
   * 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');
724
725
  }

Lily Yan's avatar
Lily Yan committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
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
  /**
   * 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);
    // Get the path.
    global $base_url;
    $base_url_parts = parse_url($base_url);
    // Check content management menu links.
    $content_links = [
      $base_url_parts['path'] . '/admin/structure/types' => 'Content types',
      $base_url_parts['path'] . '/node/add/uw_ct_blog' => 'Blog post',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_blog_tags/add' => 'Add blog tag',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_blog_tags/overview' => 'List blog tags',
      $base_url_parts['path'] . '/node/add/uw_ct_catalog_item' => 'Catalog item',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_catalog_categories/add' => 'Add catalog category',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_catalogs/add' => 'Add catalog',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_catalog_categories/overview' => 'List catalog categories',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_catalogs/overview' => 'List catalogs',
      $base_url_parts['path'] . '/node/add/uw_ct_event' => 'Event',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_tax_event_tags/add' => 'Add event tag',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_tax_event_type/add' => 'Add event type',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_tax_event_tags/overview' => 'List event tags',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_tax_event_type/overview' => 'List event types',
      $base_url_parts['path'] . '/node/add/uw_ct_news_item' => 'News item',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_news_tags/add' => 'Add news tag',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_news_tags/overview' => 'List news tags',
      $base_url_parts['path'] . '/node/add/uw_ct_site_footer' => 'Site footer',
      $base_url_parts['path'] . '/node/add/uw_ct_web_page' => 'Web page',
      $base_url_parts['path'] . '/admin/structure/webform' => 'Forms',
      $base_url_parts['path'] . '/admin/structure/webform/add' => 'Form',
      $base_url_parts['path'] . '/admin/structure/webform/submissions/manage' => 'Manage submissions',
      $base_url_parts['path'] . '/admin/structure/taxonomy' => 'Global vocabularies',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_audience' => 'Audience',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_audience/add' => 'Add term',
      $base_url_parts['path'] . '/admin/structure/taxonomy/manage/uw_vocab_audience/overview' => 'List terms',
    ];
    foreach ($content_links as $key => $item) {
      $this->assertSession()->linkExists($item);
      $this->assertEquals($key, $this->getSession()->getPage()->findLink($item)->getAttribute('href'));
    }
    // 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 = [
      $base_url_parts['path'] . '/admin/content-access' => 'Content access',
      $base_url_parts['path'] . '/admin/structure/menu' => 'Menus',
      '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'));
    }
  }

790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
  /**
   * Test dashboard.
   *
   * Test default dashboard.
   */
  private function dashboardTest() {
    // Administrator login.
    $this->drupalLogin($this->drupalUsers['administrator']);
    // Go to My Dashboard.
    $this->drupalGet('dashboard/my_dashboard');
    $this->assertSession()->statusCodeEquals(200);
    // 'web-resources-news', 'recent-content' and 'whos-online'
    // are under 'layout--uw-3-col even-split', the rest four
    // are under 'layout--uw-2-col larger-left'.
    $ids = [
      'web-resources-news' => 'uw-contained-width layout layout--uw-3-col even-split',
      'recent-content' => 'uw-contained-width layout layout--uw-3-col even-split',
      'whos-online' => 'uw-contained-width layout layout--uw-3-col even-split',
      'content-list' => 'uw-contained-width layout layout--uw-2-col larger-left',
      'forms-list' => 'uw-contained-width layout layout--uw-2-col larger-left',
      'content-management-menu' => 'uw-contained-width layout layout--uw-2-col larger-left',
      'site-management-menu' => 'uw-contained-width layout layout--uw-2-col larger-left',
    ];
    foreach ($ids as $key => $id) {
      $class = $this->getSession()->getPage()->findById($key)->getParent()->getParent()->getParent()->getAttribute('class');
      $this->assertEquals($id, $class);
    }
    // In section one, the first column is 'web-resources-news', the second is
    // 'recent-content', and the third is 'whos-online'.
    // In section two, the first column is 'content-list' and 'form-list',
    // and the second column is 'content-management-menu' and
    // 'site-management-menu'.
    $section_ids = [
      'web-resources-news' => 'layout__region layout__region--first',
      'recent-content' => 'layout__region layout__region--second',
      'whos-online' => 'layout__region layout__region--third',
      'content-list' => 'layout__region layout__region--first',
      'forms-list' => 'layout__region layout__region--first',
      'content-management-menu' => 'layout__region layout__region--second',
      'site-management-menu' => 'layout__region layout__region--second',
    ];
    foreach ($section_ids as $key => $id) {
      $class = $this->getSession()->getPage()->findById($key)->getParent()->getParent()->getAttribute('class');
      $this->assertEquals($id, $class);
    }
  }

837
838
839
  /**
   * Tests for Custom block CTA.
   */
Igor Biki's avatar
Igor Biki committed
840
  private function ctaBlockTest() {
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
    $this->drupalLogin($this->drupalUsers['administrator']);

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

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

    // Test step 3: Verify that cta block and others are on the
    // layout edit page.
    $this->assertSession()->pageTextContains('Choose a block');

    // Test step 4: Look on the page for the 'Call to action' link.
    $this->assertSession()->linkExists('Call to action');

    // Test step 6: Click 'Call to action'.
    $this->clickLink('Call to action');

    // Use random string as cta label, saving for later compare.
    $cta_label = $this->randomString();

    $this->submitForm([
      'edit-settings-label' => 'Block description title',
      'edit-settings-block-form-field-uw-cta-details-0-subform-field-uw-cta-link-0-uri' => '/home',
      'edit-settings-block-form-field-uw-cta-details-0-subform-field-uw-cta-link-0-title' => $this->randomString(),
      'edit-settings-block-form-field-uw-cta-details-0-subform-field-uw-cta-text-details-0-text-value' => $cta_label,
      'edit-settings-block-form-field-uw-cta-details-0-subform-field-uw-cta-theme' => 'org-default',
    ], 'Add block');

    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->pageTextContains($cta_label);
  }
Igor Biki's avatar
Igor Biki committed
874

875
}