Skip to content

Commit

Permalink
Updates existing tests to align with new permission. Note that these …
Browse files Browse the repository at this point in the history
…existing tests effectively test the RouteSubscriber functionality.
  • Loading branch information
ryguyk committed Jan 6, 2025
1 parent d1b44e1 commit 4ab5be0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions tests/phpunit/va_gov_form_builder/Traits/TestFormLoads.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ trait TestFormLoads {
/**
* Logs-in a user with appropriate privileges.
*/
private function loginDigitalFormUser() {
private function loginFormBuilderUser() {
$this->drupalLogin($this->createUser([
'edit any digital_form content',
'access form builder',
]));
}

Expand All @@ -26,7 +26,7 @@ private function loginDigitalFormUser() {
*/
private function sharedTestFormLoads($url, $expectedText) {
// Log in a user with permission.
$this->loginDigitalFormUser();
$this->loginFormBuilderUser();

// Navigate to page.
$this->drupalGet($url);
Expand Down
22 changes: 13 additions & 9 deletions tests/phpunit/va_gov_form_builder/functional/Form/IntroTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace tests\phpunit\va_gov_form_builder\functional\Form;

use tests\phpunit\va_gov_form_builder\Traits\TestFormLoads;
use Tests\Support\Classes\VaGovExistingSiteBase;

/**
Expand All @@ -13,39 +14,42 @@
* @coversDefaultClass \Drupal\va_gov_form_builder\Form\Intro
*/
class IntroTest extends VaGovExistingSiteBase {
use TestFormLoads;

/**
* {@inheritdoc}
*/
private static $modules = ['va_gov_form_builder'];

/**
* Returns the url for this form (for the given node)
*/
private function getFormPageUrl() {
return '/form-builder/intro';
}

/**
* Set up the environment for each test.
*/
public function setUp(): void {
parent::setUp();

$this->drupalLogin($this->createUser(['edit any digital_form content']));
$this->drupalGet('/form-builder/intro');
$this->loginFormBuilderUser();
$this->drupalGet($this->getFormPageUrl());
}

/**
* Test that the form is accessible to a user with the correct privilege.
*/
public function testFormLoads() {
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Working with the Form Builder');
$this->sharedTestFormLoads($this->getFormPageUrl(), 'Working with the Form Builder');
}

/**
* Test that the form is not accessible to a user without privilege.
*/
public function testFormDoesNotLoad() {
// Log out the good user and log in a user without permission.
$this->drupalLogin($this->createUser([]));
$this->drupalGet('/form-builder/intro');

$this->assertSession()->statusCodeNotEquals(200);
$this->sharedTestFormDoesNotLoad($this->getFormPageUrl());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function reloadNode() {
public function setUp(): void {
parent::setUp();

$this->loginDigitalFormUser();
$this->loginFormBuilderUser();

// Create a node that doesn't have any chapters.
$this->node = $this->createNode([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private function getFormPageUrl() {
public function setUp(): void {
parent::setUp();

$this->loginDigitalFormUser();
$this->loginFormBuilderUser();
$this->drupalGet($this->getFormPageUrl());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FormBuilderPageTemplateTest extends VaGovExistingSiteBase {
public function setUp(): void {
parent::setUp();

$this->drupalLogin($this->createUser(['edit any digital_form content']));
$this->drupalLogin($this->createUser(['access form builder']));

// Form Builder entry.
$this->drupalGet('/form-builder');
Expand Down

0 comments on commit 4ab5be0

Please sign in to comment.