Skip to content

Commit 44fe3b4

Browse files
ACMS-4504: Update test accordingly.
1 parent 867f30d commit 44fe3b4

10 files changed

+79
-30
lines changed

modules/acquia_cms_headless/tests/src/Functional/DashboardApiDocumentTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ public function testSection(): void {
5656
$buttonAction = $openApiResource->getAttribute('target');
5757
$this->assertEquals($buttonAction, "_blank");
5858

59-
// Test Explore with Swagger UI with headless role.
59+
// Test Explore with Swagger UI with a headless role.
6060
$this->drupalGet("/admin/config/services/openapi/swagger/jsonapi");
61-
$assertSession->pageTextContains('Access denied!');
61+
$assertSession->pageTextContains('Access denied');
62+
$assertSession->pageTextContains('You are not authorized to access this page.');
6263

63-
// Test Explore with Swagger UI with admin role.
64+
// Test Explore with Swagger UI with an admin role.
6465
$this->visitHeadlessDashboardAdmin();
6566
$this->drupalGet("/admin/config/services/openapi/swagger/jsonapi");
6667
$assertSession->waitForElementVisible('css', '#swagger-ui');

modules/acquia_cms_headless/tests/src/Functional/DashboardApiKeysTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function testSection(): void {
6666

6767
// Get the API Keys operations dropdown elements.
6868
$dropdownList = $consumersFieldset->findAll('css', 'ul li a');
69+
6970
$this->assertCount(5, $dropdownList);
7071

7172
// Click on Generate New Secret button.
@@ -122,7 +123,7 @@ private function testDelete(mixed $consumersFieldset): void {
122123
$assertSession->elementExists('named', ['link', 'Delete'], $consumersFieldset)->click();
123124
$page = $this->getSession()->getPage();
124125
$this->assertNotEmpty($page);
125-
$assertSession->pageTextContains('Access denied!');
126+
$assertSession->pageTextContains('Access denied');
126127
$expectedUrl = $this->baseUrl . '/admin/config/services/consumer/1/delete?destination=/admin/headless/dashboard';
127128
$this->assertSame($expectedUrl, $this->getSession()->getCurrentUrl());
128129
}
@@ -138,7 +139,7 @@ private function testClone(mixed $consumersFieldset): void {
138139
$assertSession->elementExists('named', ['link', 'Clone'], $consumersFieldset)->click();
139140
$page = $this->getSession()->getPage();
140141
$this->assertNotEmpty($page);
141-
$assertSession->pageTextContains('Access denied!');
142+
$assertSession->pageTextContains('Access denied');
142143
$expectedUrl = $this->baseUrl . '/entity_clone/consumer/1?destination=/admin/headless/dashboard';
143144
$this->assertSame($expectedUrl, $this->getSession()->getCurrentUrl());
144145
}

modules/acquia_cms_headless/tests/src/Functional/DashboardApiUsersTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,30 @@ public function testSection(): void {
5252
/** @var \Drupal\FunctionalJavascriptTests\JSWebAssert $assertSession */
5353
$assertSession = $this->assertSession();
5454

55-
// Test API Users section exists, get API Users section.
55+
// Test API Users section exists, get an API Users section.
5656
$usersFieldset = $assertSession->waitForElementVisible('css', $this->sectionSelector);
5757

5858
// Test add API user button link has destination.
5959
$this->assertButtonLink($usersFieldset, '/admin/people/create?destination=/admin/headless/dashboard');
6060

61-
// Test table body exist and has data in same order.
61+
// Test table body exists and has data in the same order.
6262
$this->assertEquals('Headless', $this->getTableBodyColumn(0)->getText());
6363
$this->assertEquals('Headless Administrator', $this->getTableBodyColumn(1)->getText());
6464

6565
// Get the API Users operations dropdown elements.
6666
$dropdownList = $usersFieldset->findAll('css', 'tbody tr:nth-child(1) ul li a');
6767
$this->assertCount(3, $dropdownList);
6868

69-
// Click on Edit button.
69+
// Click on the Edit button.
7070
$expectedUrl = $this->baseUrl . '/user/2/edit?destination=/admin/headless/dashboard';
7171
$usersFieldset->findButton('List additional actions')->click();
72-
$this->testOperation($usersFieldset, 'Edit', $expectedUrl, 'Whoops!');
72+
$this->testOperation($usersFieldset, 'Edit', $expectedUrl, 'Access denied');
7373

7474
// Click on Clone button.
7575
$this->drupalGet("/admin/headless/dashboard");
7676
$usersFieldset->findButton('List additional actions')->click();
7777
$expectedUrl = $this->baseUrl . '/entity_clone/user/2?destination=/admin/headless/dashboard';
78-
$this->testOperation($usersFieldset, 'Clone', $expectedUrl, 'Whoops!');
78+
$this->testOperation($usersFieldset, 'Clone', $expectedUrl, 'Access denied');
7979
}
8080

8181
/**

modules/acquia_cms_headless/tests/src/Functional/DashboardNextjsSitesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function testAddNextjsSite(mixed $nextjsSitesFieldset): void {
127127
$this->assertSession()->elementExists('named', ['link', 'Add Next.js site'], $nextjsSitesFieldset)->click();
128128
$page = $this->getSession()->getPage();
129129
$this->assertNotEmpty($page);
130-
$this->assertSession()->pageTextContains('Access denied!');
130+
$this->assertSession()->pageTextContains('Access denied');
131131
$expectedUrl = $this->baseUrl . '/admin/config/services/next/sites/add?destination=/admin/headless/dashboard';
132132
$this->assertSame($expectedUrl, $this->getSession()->getCurrentUrl());
133133
}

modules/acquia_cms_headless/tests/src/Functional/HeadlessContentTest.php

+22-17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
66
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
77
use Drupal\Tests\acquia_cms_headless\Traits\HeadlessNextJsTrait;
8+
use Drupal\user\Entity\Role;
89

910
/**
1011
* Base class for the Headless Content administrator browser tests.
@@ -26,6 +27,9 @@ class HeadlessContentTest extends WebDriverTestBase {
2627
protected static $modules = [
2728
'acquia_cms_headless',
2829
'node',
30+
'block',
31+
'media_library',
32+
'entity_clone',
2933
];
3034

3135
/**
@@ -54,6 +58,12 @@ protected function setUp(): void {
5458
}
5559
parent::setUp();
5660
$account = $this->drupalCreateUser();
61+
// Create an administrator role with is_admin set to true.
62+
Role::create([
63+
'id' => 'administrator',
64+
'label' => 'Administrator',
65+
'is_admin' => TRUE,
66+
])->save();
5767
$account->addRole('administrator');
5868
$account->save();
5969
$this->drupalLogin($account);
@@ -66,12 +76,7 @@ protected function setUp(): void {
6676
// Set up a content type.
6777
$this->drupalCreateContentType([
6878
'type' => 'test',
69-
'name' => 'Test',
70-
'third_party_settings' => [
71-
"acquia_cms_common" => [
72-
"workflow_id" => "editorial",
73-
],
74-
],
79+
'name' => 'Test'
7580
]);
7681
// Enable pure headless mode.
7782
$this->enableHeadlessMode();
@@ -85,7 +90,7 @@ protected function setUp(): void {
8590
* Content admin test.
8691
*/
8792
public function testContentAdmin(): void {
88-
// Visit content page.
93+
// Visit the content page.
8994
$this->drupalGet("admin/content");
9095

9196
// Validating the primary menu tabs on admin content page.
@@ -114,32 +119,32 @@ public function testContentAdmin(): void {
114119
$assertSession = $this->assertSession();
115120
$assertSession->pageTextContains('Headless Test Page');
116121
// @todo Below commented test is failing in 3.0-rc8 version of Gin theme.
117-
// Howere this was working in 3.0-rc5 will be fixed in ACMS-3456.
118-
/*
122+
// However this was working in 3.0-rc5 will be fixed in ACMS-3456.
119123
$assertSession->linkNotExists('View');
120124
$nodePageMenus = [
121125
'API' => '/jsonapi/node/test/' . $node->uuid(),
122126
'Edit' => '/node/' . $nid . '/edit',
123127
'Preview' => '/node/' . $nid . '/site-preview',
128+
'Delete' => '/node/' . $nid . '/delete',
124129
'Revisions' => '/node/' . $nid . '/revisions',
125130
'Clone' => '/entity_clone/node/' . $nid,
126131
];
127-
$menuList = $this->cssSelect('ul.tabs--primary li');
132+
$menuList = $this->cssSelect('#block-local-tasks ul li');
133+
dump($menuList);
128134
// Check the total count of node tabs.
129135
$this->assertCount(6, $menuList);
130136
$menuOrder = [];
131137
foreach ($menuList as $menu) {
132-
$tabTitle = str_replace(' (active tab)', '', $menu->getText());
133-
if ($tabTitle) {
134-
$menuOrder[] = $tabTitle;
135-
}
138+
$tabTitle = str_replace(' (active tab)', '', $menu->getText());
139+
if ($tabTitle) {
140+
$menuOrder[] = $tabTitle;
141+
}
136142
}
137143
// Assertion for menu order.
138144
$this->assertEquals($menuOrder, array_keys($nodePageMenus));
139-
Assertion test for tabs of node page.
145+
// Assertion test for tabs of node page.
140146
$this->assertTabMenus($nodePageMenus, $path);
141-
*/
142-
// Assert delete buton.
147+
// Assert delete button.
143148
$deleteButton = $this->getSession()->getPage()->findLink('Delete');
144149
$this->assertEquals('Delete', $deleteButton->getText());
145150
$this->assertEquals('/node/' . $nid . '/delete', $deleteButton->getAttribute('href'));

modules/acquia_cms_headless/tests/src/Functional/HeadlessFrontpageTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\Tests\acquia_cms_headless\Functional;
44

55
use Drupal\Tests\BrowserTestBase;
6+
use Drupal\user\Entity\Role;
67

78
/**
89
* Tests for acquia_cms_headless frontpage.
@@ -22,6 +23,8 @@ class HeadlessFrontpageTest extends BrowserTestBase {
2223
*/
2324
protected static $modules = [
2425
'acquia_cms_headless_ui',
26+
'node',
27+
'views',
2528
];
2629

2730
/**
@@ -53,6 +56,12 @@ public function testFrontPageIsLoginPage(): void {
5356
*/
5457
public function testFrontPageIsAdminContentPage(): void {
5558
$account = $this->createUser();
59+
// Create an administrator role with is_admin set to true.
60+
Role::create([
61+
'id' => 'administrator',
62+
'label' => 'Administrator',
63+
'is_admin' => TRUE,
64+
])->save();
5665
$account->addRole('administrator');
5766
$account->save();
5867
// Don't use one-time login links instead submit the login form.

modules/acquia_cms_headless/tests/src/Functional/HeadlessModeEnablementTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\Tests\acquia_cms_headless\Functional;
44

55
use Drupal\Core\Extension\Exception\UnknownExtensionException;
6+
use Drupal\user\Entity\Role;
67

78
/**
89
* Tests for acquia_cms_headless Hybrid mode.

modules/acquia_cms_headless/tests/src/Functional/HeadlessTestBase.php

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
66
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
7+
use Drupal\user\Entity\Role;
78

89
/**
910
* Base class for the HeadlessDashboard web_driver tests.
@@ -20,6 +21,7 @@ abstract class HeadlessTestBase extends WebDriverTestBase {
2021
*/
2122
protected static $modules = [
2223
'acquia_cms_headless',
24+
'entity_clone',
2325
];
2426

2527
/**
@@ -47,6 +49,12 @@ protected function setUp(): void {
4749
$this->markTestSkipped('This test cannot run in an Acquia Cloud IDE.');
4850
}
4951
parent::setUp();
52+
// Create an administrator role with is_admin set to true.
53+
Role::create([
54+
'id' => 'administrator',
55+
'label' => 'Administrator',
56+
'is_admin' => TRUE,
57+
])->save();
5058
$account = $this->drupalCreateUser();
5159
$account->addRole('headless');
5260
$account->save();

modules/acquia_cms_headless/tests/src/Functional/PureHeadlessModeMenuTest.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Drupal\Core\Extension\Exception\UnknownExtensionException;
88
use Drupal\Core\Extension\ModuleExtensionList;
99
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
10+
use Drupal\user\Entity\Role;
1011

1112
/**
1213
* Pure headless mode menu tests.
@@ -30,6 +31,11 @@ class PureHeadlessModeMenuTest extends WebDriverTestBase {
3031
*/
3132
protected static $modules = [
3233
'acquia_cms_headless_ui',
34+
'block_content',
35+
'node',
36+
'media_library',
37+
'menu_ui',
38+
'taxonomy',
3339
];
3440

3541
/**
@@ -74,6 +80,12 @@ protected function setUp(): void {
7480
$this->moduleInstaller = $this->container->get('module_installer');
7581
$this->moduleList = $this->container->get('extension.list.module');
7682
$account = $this->drupalCreateUser();
83+
// Create an administrator role with is_admin set to true.
84+
Role::create([
85+
'id' => 'administrator',
86+
'label' => 'Administrator',
87+
'is_admin' => TRUE,
88+
])->save();
7789
$account->addRole('administrator');
7890
$account->save();
7991
$this->drupalLogin($account);
@@ -160,12 +172,10 @@ public static function providerMenu(): array {
160172
'.toolbar-icon-system-admin-content',
161173
'Content',
162174
[
163-
'Scheduled Content',
164175
'Add content',
165176
'Blocks',
166177
'Files',
167178
'Media',
168-
'Scheduled Media',
169179
'Block Content',
170180
],
171181
],

modules/acquia_cms_headless/tests/src/Traits/DashboardSectionTrait.php

+14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Drupal\Tests\acquia_cms_headless\Traits;
44

55
use Behat\Mink\Element\NodeElement;
6+
use Drupal\user\Entity\Role;
67

78
/**
89
* Trait to test dashboard section.
@@ -16,6 +17,7 @@ trait DashboardSectionTrait {
1617
*/
1718
protected function visitHeadlessDashboardAdmin(): void {
1819
$account = $this->drupalCreateUser();
20+
$this->createAdministratorRole();
1921
$account->addRole('administrator');
2022
$account->save();
2123
$this->drupalLogin($account);
@@ -24,6 +26,18 @@ protected function visitHeadlessDashboardAdmin(): void {
2426
$this->drupalGet("/admin/headless/dashboard");
2527
}
2628

29+
/**
30+
* Create admin role.
31+
*/
32+
public function createAdministratorRole() {
33+
// Create an administrator role with is_admin set to true.
34+
Role::create([
35+
'id' => 'administrator',
36+
'label' => 'Administrator',
37+
'is_admin' => TRUE,
38+
])->save();
39+
}
40+
2741
/**
2842
* Returns the section element.
2943
*/

0 commit comments

Comments
 (0)