Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/473 webform submission test #479

Merged
merged 30 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5adabcd
Start on #464: enabling and disabling modules and access to their con…
ekes May 26, 2024
e730977
Add logging out to trait.
ekes May 26, 2024
ea512a0
Test broke in 10.3 because of new logout route option for CSRF.
ekes May 28, 2024
9558a4b
Merge branch 'feature/group_context_domain_1_0_0' into feature/464-ac…
ekes May 28, 2024
2fe816e
Remove unnecessary (wrong type) translation.
ekes May 28, 2024
dc0b1d3
Who knows maybe this works with 10.2 otherwise it's 10.3 only.
ekes May 28, 2024
6fa126e
Move shared relationship into optional.
ekes May 30, 2024
12ce439
Fuller check of permissions paths.
ekes May 30, 2024
2ac7b31
Add "all" (not quite see comment) admin paths checks.
ekes May 30, 2024
f990bda
See if we can test on github against 10.3
ekes May 30, 2024
f79fcd3
Test now covers all access by content type options.
ekes Jun 1, 2024
54bf8bf
Add blogs tests (and remove permissions not available from module).
ekes Jun 1, 2024
02bad63
Add blogs tests (and remove permissions not available from module).
ekes Jun 1, 2024
31ec617
Merge branch 'feature/tests-microsite-blogs' into feature/464-access-…
ekes Jun 1, 2024
e5752ed
Test up to submission.
ekes Jun 1, 2024
ae0ff65
Merge branch 'feature/464-access-tests-enable-disable-modules' into f…
ekes Jun 1, 2024
a41ec67
Test access to webform node submissions in group / domain #473.
ekes Jun 2, 2024
10de358
Switch branch used for installing microsites to one that installs 10.3
ekes Jun 5, 2024
8154fc5
It's a composer require string?
ekes Jun 5, 2024
424427c
Oops, pay attention to the branch names.
ekes Jun 5, 2024
5ca117f
Script is adding -dev, but it didn't seem to work before. Maybe just …
ekes Jun 5, 2024
45feacd
Fixing Github Actions
stephen-cox Jun 6, 2024
3ebcc30
Merge branch 'feature/464-access-tests-enable-disable-modules' into f…
ekes Jun 7, 2024
e20f6e7
Merged 4.x
stephen-cox Jun 11, 2024
76a48e8
Resolve merge conflicts.
FinnERLewis Jul 23, 2024
656200a
Resolve merge conflicts.
FinnERLewis Jul 23, 2024
46382a4
Fix some coding standards.
FinnERLewis Jul 23, 2024
ddeb4d0
Update tests to confirm we expect a 403 on a microsite when a site ad…
FinnERLewis Jul 23, 2024
47e5913
Fix coding standards, line lengths!
FinnERLewis Jul 23, 2024
9103259
Fix coding standards, line lenghts warning.
FinnERLewis Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ dependencies:
# LocalGov Drupal
- group_webform:group_webform
- localgov_forms:localgov_forms
- localgov_microsites_group:localgov_microsites_group
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
<?php

namespace Drupal\Tests\localgov_microsites_group_webform\Functional;

use Drupal\Core\Url;
use Drupal\localgov_microsites_group\DomainFromGroupTrait;
use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\localgov_microsites_group\Functional\LoginOutTrait;
use Drupal\Tests\localgov_microsites_group\Traits\GroupCreationTrait;
use Drupal\Tests\localgov_microsites_group\Traits\InitializeGroupsTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;

/**
* Tests webforms attached to a node in a group.
*
* @group localgov_microsites_group
*/
class MicrositeWebformAccessTest extends BrowserTestBase {

use InitializeGroupsTrait;
use NodeCreationTrait;
use LoginOutTrait;
use GroupCreationTrait, DomainFromGroupTrait {
GroupCreationTrait::getEntityTypeManager insteadof DomainFromGroupTrait;
}

/**
* Will be removed when issue #3204455 on Domain Site Settings gets merged.
*
* See https://www.drupal.org/project/domain_site_settings/issues/3204455.
*
* @var bool
*
* @see \Drupal\Core\Config\Development\ConfigSchemaChecker
* phpcs:disable DrupalPractice.Objects.StrictSchemaDisabled.StrictConfigSchema
*/
protected $strictConfigSchema = FALSE;

/**
* {@inheritdoc}
*/
protected $profile = 'minimal';

/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';

/**
* {@inheritdoc}
*/
protected static $modules = [
'localgov_microsites_group_webform',
];

/**
* {@inheritdoc}
*/
protected $domains = [];

/**
* {@inheritdoc}
*/
protected $webforms = [];

/**
* {@inheritdoc}
*/
protected $adminUser = [];

/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();

$this->createMicrositeGroups(['uid' => 1], 2);
$this->createMicrositeGroupsDomains($this->groups);
$this->domains[1] = $this->getDomainFromGroup($this->groups[1]);
$this->domains[2] = $this->getDomainFromGroup($this->groups[2]);

$this->adminUser[1] = $this->createUser();
$this->adminUser[2] = $this->createUser();
$this->groups[1]->addMember($this->adminUser[1], ['group_roles' => 'microsite-admin']);
$this->groups[2]->addMember($this->adminUser[2], ['group_roles' => 'microsite-admin']);

$this->webforms[1] = $this->createNode([
'type' => 'localgov_webform',
'title' => $this->randomMachineName(12),
'localgov_submission_confirm' => $this->randomMachineName(),
'localgov_submission_email' => '[email protected]',
'localgov_webform' => [
'target_id' => 'microsite_contact',
'default_data' => '',
'status' => 'open',
'open' => '',
'close' => '',
],
'status' => NodeInterface::PUBLISHED,
'uid' => $this->adminUser[1]->id(),
]);
$this->webforms[1]->save();
$this->webforms[2] = $this->createNode([
'type' => 'localgov_webform',
'title' => $this->randomMachineName(12),
'localgov_submission_confirm' => $this->randomMachineName(),
'localgov_submission_email' => '[email protected]',
'localgov_webform' => [
'target_id' => 'microsite_contact',
'default_data' => '',
'status' => 'open',
'open' => '',
'close' => '',
],
'status' => NodeInterface::PUBLISHED,
'uid' => $this->adminUser[2]->id(),
]);
$this->webforms[2]->save();
$this->groups[1]->addRelationship($this->webforms[1], 'group_node:localgov_webform');
$this->groups[2]->addRelationship($this->webforms[2], 'group_node:localgov_webform');
}

/**
* Test access and submission.
*/
public function testMicrositeNodeWebform() {
$submissions = [];

// Check form 1 only on domain 1 and make a submission.
$this->drupalGet($this->domains[1]->getUrl() . $this->webforms[1]->toUrl()->toString());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($this->webforms[1]->label());
$submissions[1] = [
'full_name' => $this->randomString(),
'email_address' => $this->randomMachineName() . '@example.com',
'message' => $this->randomString(),
];
$this->submitForm($submissions[1], 'Submit');
$this->assertSession()->pageTextContains($this->webforms[1]->localgov_submission_confirm->value);
$this->drupalGet($this->domains[1]->getUrl() . $this->webforms[2]->toUrl()->toString());
$this->assertSession()->statusCodeEquals(403);

// Check form 2 only on domain 2 and make a submission.
$this->drupalGet($this->domains[2]->getUrl() . $this->webforms[1]->toUrl()->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . $this->webforms[2]->toUrl()->toString());
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains($this->webforms[2]->label());
$submissions[2] = [
'full_name' => $this->randomString(),
'email_address' => $this->randomMachineName() . '@example.com',
'message' => $this->randomString(),
];
$this->submitForm($submissions[2], 'Submit');
// Check anon does not have access to the submission.
$this->assertSession()->pageTextContains($this->webforms[2]->localgov_submission_confirm->value);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform.results_submissions', [
'node' => $this->webforms[2]->id(),
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform.user.submission', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform.user.submission.edit', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform_submission.canonical', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform_submission.edit_form', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);

// Check admin 1 has access to domain 1 submission.
$this->micrositeDomainLogin($this->domains[1], $this->adminUser[1]);
$this->drupalGet($this->domains[1]->getUrl() . Url::fromRoute('entity.node.webform.results_submissions', [
'node' => $this->webforms[1]->id(),
])->toString());
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet($this->domains[1]->getUrl() . Url::fromRoute('entity.node.webform.user.submission', [
'node' => $this->webforms[1]->id(),
'webform_submission' => 1,
])->toString());
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet($this->domains[1]->getUrl() . Url::fromRoute('entity.node.webform.user.submission.edit', [
'node' => $this->webforms[1]->id(),
'webform_submission' => 1,
])->toString());
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet($this->domains[1]->getUrl() . Url::fromRoute('entity.node.webform_submission.canonical', [
'node' => $this->webforms[1]->id(),
'webform_submission' => 1,
])->toString());
$this->assertSession()->statusCodeEquals(200);
$this->drupalGet($this->domains[1]->getUrl() . Url::fromRoute('entity.node.webform_submission.edit_form', [
'node' => $this->webforms[1]->id(),
'webform_submission' => 1,
])->toString());
$this->assertSession()->statusCodeEquals(200);

// Check admin 1 does not have access to domain 2 submission.
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform.results_submissions', [
'node' => $this->webforms[2]->id(),
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform.user.submission', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform.user.submission.edit', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform_submission.canonical', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($this->domains[2]->getUrl() . Url::fromRoute('entity.node.webform_submission.edit_form', [
'node' => $this->webforms[2]->id(),
'webform_submission' => 2,
])->toString());
$this->assertSession()->statusCodeEquals(403);
}

}
34 changes: 18 additions & 16 deletions tests/src/Functional/GroupContentTypeAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ public function testUsersDomainsAdminContentTypeAccess() {
foreach ($check_content['content_types'] as $check_content_type) {
$this->drupalGet($group1_domain->getUrl() . '/group/' . $group1->id() . '/content/create/group_node%3A' . $check_content_type);
$this->assertSession()->statusCodeEquals($check_content['status']);
// phpcs:ignore
#$this->drupalGet($group1_domain->getUrl() . '/node/add/' . $check_content_type);
// phpcs:ignore
// this->assertSession()->statusCodeEquals($check_content['status']);
// Currently, the microsite admin is not allowed to add content via
// /node/add.
$this->drupalGet($group1_domain->getUrl() . '/node/add/' . $check_content_type);
$this->assertSession()->statusCodeEquals('403');
}
}

Expand All @@ -177,10 +177,10 @@ public function testUsersDomainsAdminContentTypeAccess() {
foreach ($check_content['content_types'] as $check_content_type) {
$this->drupalGet($group1_domain->getUrl() . '/group/' . $group1->id() . '/content/create/group_node%3A' . $check_content_type);
$this->assertSession()->statusCodeEquals($check_content['status']);
// phpcs:ignore
#$this->drupalGet($group1_domain->getUrl() . '/node/add/' . $check_content_type);
// phpcs:ignore
#$this->assertSession()->statusCodeEquals($check_content['status']);
// Currently, the microsite admin is not allowed to add content via
// /node/add.
$this->drupalGet($group1_domain->getUrl() . '/node/add/' . $check_content_type);
$this->assertSession()->statusCodeEquals('403');
}
}

Expand All @@ -189,10 +189,10 @@ public function testUsersDomainsAdminContentTypeAccess() {
foreach ($check_content['content_types'] as $check_content_type) {
$this->drupalGet($group2_domain->getUrl() . '/group/' . $group2->id() . '/content/create/group_node%3A' . $check_content_type);
$this->assertSession()->statusCodeEquals(200);
// phpcs:ignore
#$this->drupalGet($group2_domain->getUrl() . '/node/add/' . $check_content_type);
// phpcs:ignore
#$this->assertSession()->statusCodeEquals(200);
// Currently, the microsite admin is not allowed to add content via
// /node/add.
$this->drupalGet($group2_domain->getUrl() . '/node/add/' . $check_content_type);
$this->assertSession()->statusCodeEquals('403');
}
}

Expand All @@ -203,10 +203,10 @@ public function testUsersDomainsAdminContentTypeAccess() {
foreach ($check_content['content_types'] as $check_content_type) {
$this->drupalGet($group1_domain->getUrl() . '/group/' . $group1->id() . '/content/create/group_node%3A' . $check_content_type);
$this->assertSession()->statusCodeEquals($check_content['status']);
// phpcs:ignore
#$this->drupalGet($group1_domain->getUrl() . '/node/add/' . $check_content_type);
// phpcs:ignore
#$this->assertSession()->statusCodeEquals($check_content['status']);
// Currently, the microsite admin is not allowed to add content via
// /node/add.
$this->drupalGet($group1_domain->getUrl() . '/node/add/' . $check_content_type);
$this->assertSession()->statusCodeEquals('403');
}
}
$this->micrositeDomainLogout($group1_domain);
Expand Down Expand Up @@ -267,6 +267,7 @@ public function testContentContentTypeAccess() {
$this->assertSession()->statusCodeEquals(403);
$this->drupalGet($group1_domain->getUrl() . $event->toUrl('edit-form')->toString());
$this->assertSession()->statusCodeEquals(403);

// Anon.
$this->micrositeDomainLogout($group1_domain);
$this->drupalGet($group1_domain->getUrl() . $directory->toUrl()->toString());
Expand Down Expand Up @@ -311,6 +312,7 @@ public function testAllModules() {
'localgov_microsites_news',
]);

// Create some group content.
// All modules start disabled.
// Shared paths will be enabled by the first module, so not tested against
// the second.
Expand Down
Loading