Merge pull request #19552 from kamil-tekiela/Fix-default-values
[phpmyadmin.git] / tests / end-to-end / CreateRemoveUserTest.php
blob899e053ed38705acbb0884a179fbc6c59e1dd9fe
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Selenium;
7 use PHPUnit\Framework\Attributes\CoversNothing;
8 use PHPUnit\Framework\Attributes\Large;
10 use function bin2hex;
11 use function random_bytes;
13 #[CoversNothing]
14 #[Large]
15 class CreateRemoveUserTest extends TestBase
17 /**
18 * Create a test database for this test class
20 protected static bool $createDatabase = false;
22 /**
23 * Username for the user
25 private string $txtUsername;
27 /**
28 * Password for the user
30 private string $txtPassword;
32 /**
33 * Setup the browser environment to run the selenium test case
35 protected function setUp(): void
37 parent::setUp();
39 $this->skipIfNotSuperUser();
40 $this->txtUsername = 'test_user_' . bin2hex(random_bytes(4));
41 $this->txtPassword = 'abc_123';
42 $this->login();
45 /**
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
53 $this->waitAjax();
55 $this->scrollIntoView('add_user_anchor');
56 $this->waitForElement('id', 'usersForm');
57 $ele = $this->waitForElement('id', 'add_user_anchor');
58 $this->moveto($ele);
59 $ele->click();
61 $this->waitAjax();
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');
69 $genButton->click();
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 . '&amp;#27;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',
109 $success->getText(),