3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Tests\Selenium
;
7 use PHPUnit\Framework\Attributes\CoversNothing
;
8 use PHPUnit\Framework\Attributes\Large
;
11 use function random_bytes
;
15 class CreateRemoveUserTest
extends TestBase
18 * Create a test database for this test class
20 protected static bool $createDatabase = false;
23 * Username for the user
25 private string $txtUsername;
28 * Password for the user
30 private string $txtPassword;
33 * Setup the browser environment to run the selenium test case
35 protected function setUp(): void
39 $this->skipIfNotSuperUser();
40 $this->txtUsername
= 'test_user_' . bin2hex(random_bytes(4));
41 $this->txtPassword
= 'abc_123';
46 * Creates and removes a user
48 public function testCreateRemoveUser(): void
50 $this->waitForElement('partialLinkText', 'User accounts')->click();
52 // Let the User Accounts page load
55 $this->scrollIntoView('add_user_anchor');
56 $this->waitForElement('id', 'usersForm');
57 $ele = $this->waitForElement('id', 'add_user_anchor');
62 $userField = $this->waitForElement('name', 'username');
63 $userField->sendKeys($this->txtUsername
);
65 $this->selectByLabel($this->byId('select_pred_hostname'), 'Local');
67 $this->scrollIntoView('button_generate_password');
68 $genButton = $this->waitForElement('id', 'button_generate_password');
71 self
::assertNotSame('', $this->byId('text_pma_pw')->getAttribute('value'));
72 self
::assertNotSame('', $this->byId('text_pma_pw2')->getAttribute('value'));
73 self
::assertNotSame('', $this->byId('generated_pw')->getAttribute('value'));
75 $this->byId('text_pma_pw')->sendKeys($this->txtPassword
);
76 $this->byId('text_pma_pw2')->sendKeys($this->txtPassword
);
78 // Make sure the element is visible before clicking
79 $this->scrollIntoView('createdb-1');
80 $this->waitForElement('id', 'createdb-1')->click();
81 $this->waitForElement('id', 'createdb-2')->click();
83 $this->scrollIntoView('addUsersForm_checkall');
84 $this->byId('addUsersForm_checkall')->click();
86 $this->scrollIntoView('adduser_submit');
87 $this->waitForElement('id', 'adduser_submit')->click();
89 $success = $this->waitForElement('cssSelector', '.alert-success');
90 self
::assertStringContainsString('You have added a new user', $success->getText());
92 // Removing the newly added user
93 $this->waitForElement('partialLinkText', 'User accounts')->click();
94 $this->waitForElement('id', 'usersForm');
95 $temp = $this->txtUsername
. 'localhost';
97 $this->byXPath("(//input[@name='selected_usr[]'])[@value='" . $temp . "']")->click();
99 $this->scrollIntoView('deleteUserCard');
100 $this->byId('dropUsersDbCheckbox')->click();
102 $this->byId('buttonGo')->click();
103 $this->waitForElement('id', 'functionConfirmOkButton')->click();
104 $this->acceptAlert();
106 $success = $this->waitForElement('cssSelector', '.alert-success');
107 self
::assertStringContainsString(
108 'The selected users have been deleted',