Skip to content

Commit

Permalink
UHF-9832: Added test for the user deletion/cancellation form.
Browse files Browse the repository at this point in the history
  • Loading branch information
khalima committed May 6, 2024
1 parent 8c21733 commit aebbd03
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tests/src/Functional/UserCancelFormTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace Drupal\Tests\helfi_platform_config\Functional;

use Drupal\Tests\helfi_api_base\Functional\BrowserTestBase;

/**
* Tests user cancel method form.
*
* @group helfi_platform_config
*/
class UserCancelFormTest extends BrowserTestBase {

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

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

/**
* Tests user cancel method form.
*/
public function testUserCancelForm(): void {
// Create user accounts for testing the delete methods.
$superAdminUser = $this->drupalCreateUser([], 'superAdminUser', TRUE);
$adminUser = $this->drupalCreateUser([
'access user profiles',
'administer users',
'cancel account',
], 'superUser');
$editorUser = $this->drupalCreateUser([
'access user profiles',
'cancel account',
], 'editorUser');
$testUser = $this->drupalCreateUser([], 'testUser');

// Test that the superAdminUser can see all cancellation methods
// for the testUser account.
$this->drupalLogin($superAdminUser);
$this->drupalGet('/user/' . $testUser->id() . '/cancel');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementExists('xpath', '//input[@value="user_cancel_block"]');
$this->assertSession()->elementExists('xpath', '//input[@value="user_cancel_block_unpublish"]');
$this->assertSession()->elementExists('xpath', '//input[@value="user_cancel_reassign"]');
$this->assertSession()->elementExists('xpath', '//input[@value="user_cancel_delete"]');

// Test that the adminUser can see all only cancellation methods, but not
// deletion methods for the testUser account.
$this->drupalLogin($adminUser);
$this->drupalGet('/user/' . $testUser->id() . '/cancel');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementExists('xpath', '//input[@value="user_cancel_block"]');
$this->assertSession()->elementExists('xpath', '//input[@value="user_cancel_block_unpublish"]');
$this->assertSession()->elementNotExists('xpath', '//input[@value="user_cancel_reassign"]');
$this->assertSession()->elementNotExists('xpath', '//input[@value="user_cancel_delete"]');

// Test that the editorUser cannot access the cancel page.
$this->drupalLogin($editorUser);
$this->drupalGet('/user/' . $testUser->id() . '/cancel');
$this->assertSession()->statusCodeEquals(403);
}

}

0 comments on commit aebbd03

Please sign in to comment.