diff --git a/core/modules/user/src/Tests/UserAdminLanguageTest.php b/core/modules/user/tests/src/Functional/UserAdminLanguageTest.php similarity index 86% rename from core/modules/user/src/Tests/UserAdminLanguageTest.php rename to core/modules/user/tests/src/Functional/UserAdminLanguageTest.php index cd6cc657bf..414f159770 100644 --- a/core/modules/user/src/Tests/UserAdminLanguageTest.php +++ b/core/modules/user/tests/src/Functional/UserAdminLanguageTest.php @@ -1,16 +1,16 @@ adminUser->id() . '/edit'; $this->drupalGet($path); // Ensure administration pages language settings widget is not available. - $this->assertNoFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector not available.'); + $this->assertNull($this->getSession()->getPage()->findField('edit-preferred-admin-langcode')); } /** @@ -64,13 +64,13 @@ public function testUserAdminLanguageConfigurationAvailableWithAdminLanguageNego // Checks with user administration pages language negotiation disabled. $this->drupalGet($path); // Ensure administration pages language settings widget is not available. - $this->assertNoFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector not available.'); + $this->assertNull($this->getSession()->getPage()->findField('edit-preferred-admin-langcode')); // Checks with user administration pages language negotiation enabled. $this->setLanguageNegotiation(); $this->drupalGet($path); // Ensure administration pages language settings widget is available. - $this->assertFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector is available.'); + $this->assertNotNull($this->getSession()->getPage()->findField('edit-preferred-admin-langcode')); } /** @@ -91,13 +91,13 @@ public function testUserAdminLanguageConfigurationAvailableIfAdminLanguageNegoti $path = 'user/' . $this->adminUser->id() . '/edit'; $this->drupalGet($path); // Ensure administration pages language setting is visible for admin. - $this->assertFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector available for admins.'); + $this->assertNotNull($this->getSession()->getPage()->findField( 'edit-preferred-admin-langcode')); // Ensure administration pages language setting is hidden for non-admins. $this->drupalLogin($this->regularUser); $path = 'user/' . $this->regularUser->id() . '/edit'; $this->drupalGet($path); - $this->assertNoFieldByXPath($this->constructFieldXpath('id', 'edit-preferred-admin-langcode'), NULL, 'Administration pages language selector not available for regular user.'); + $this->assertNull($this->getSession()->getPage()->findField('edit-preferred-admin-langcode')); } /** diff --git a/core/modules/user/src/Tests/UserBlocksTest.php b/core/modules/user/tests/src/Functional/UserBlocksTest.php similarity index 97% rename from core/modules/user/src/Tests/UserBlocksTest.php rename to core/modules/user/tests/src/Functional/UserBlocksTest.php index 0a4c619da6..16e719ffea 100644 --- a/core/modules/user/src/Tests/UserBlocksTest.php +++ b/core/modules/user/tests/src/Functional/UserBlocksTest.php @@ -1,16 +1,16 @@ adminUser = $this->drupalCreateUser(['administer blocks']); $this->drupalLogin($this->adminUser); $this->drupalPlaceBlock('user_login_block'); - $this->drupalLogout($this->adminUser); } /** diff --git a/core/modules/user/src/Tests/UserCreateTest.php b/core/modules/user/tests/src/Functional/UserCreateTest.php similarity index 95% rename from core/modules/user/src/Tests/UserCreateTest.php rename to core/modules/user/tests/src/Functional/UserCreateTest.php index 7b534435a0..5e0d2f5c63 100644 --- a/core/modules/user/src/Tests/UserCreateTest.php +++ b/core/modules/user/tests/src/Functional/UserCreateTest.php @@ -1,18 +1,22 @@ drupalLogin($account); $this->account = User::load($account->id()); - $this->account->pass_raw = $account->pass_raw; + $this->account->passRaw = $account->passRaw; $this->drupalLogout(); // Set the last login time that is used to generate the one-time link so @@ -73,7 +82,7 @@ public function testUserPasswordReset() { // Verify that accessing the password reset form without having the session // variables set results in an access denied message. $this->drupalGet(Url::fromRoute('user.reset.form', ['uid' => $this->account->id()])); - $this->assertResponse(403); + $web_assert->statusCodeEquals(403); // Try to reset the password for an invalid account. $this->drupalGet('user/password'); @@ -120,7 +129,7 @@ public function testUserPasswordReset() { $edit = [ 'files[user_picture_0]' => drupal_realpath($image->uri), ]; - $this->drupalPostAjaxForm(NULL, $edit, 'user_picture_0_upload_button'); + $this->drupalPostForm(NULL, $edit, 'Upload'); // Change the forgotten password. $password = user_password(); diff --git a/core/modules/user/src/Tests/UserRegistrationTest.php b/core/modules/user/tests/src/Functional/UserRegistrationTest.php similarity index 88% rename from core/modules/user/src/Tests/UserRegistrationTest.php rename to core/modules/user/tests/src/Functional/UserRegistrationTest.php index ca7a4f0c89..388eaca765 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/tests/src/Functional/UserRegistrationTest.php @@ -1,20 +1,19 @@ 'test@example.com', 'name' => $account->getUsername()]; $this->drupalPostForm('user/register', $edit, t('Create new account')); - $this->assertRaw(SafeMarkup::format('The username %value is already taken.', ['%value' => $account->getUsername()])); + $this->assertRaw(t('The username %value is already taken.', ['%value' => $account->getUsername()])); $edit = ['mail' => $account->getEmail(), 'name' => $this->randomString()]; $this->drupalPostForm('user/register', $edit, t('Create new account')); - $this->assertRaw(SafeMarkup::format('The email address %value is already taken.', ['%value' => $account->getEmail()])); + $this->assertRaw(t('The email address %value is already taken.', ['%value' => $account->getEmail()])); } /** @@ -348,35 +347,27 @@ public function testRegistrationWithUserFields() { // Check that the 'add more' button works. $field_storage->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); $field_storage->save(); - foreach (['js', 'nojs'] as $js) { - $this->drupalGet('user/register'); - $this->assertRegistrationFormCacheTagsWithUserFields(); - // Add two inputs. - $value = rand(1, 255); - $edit = []; - $edit['test_user_field[0][value]'] = $value; - if ($js == 'js') { - $this->drupalPostAjaxForm(NULL, $edit, 'test_user_field_add_more'); - $this->drupalPostAjaxForm(NULL, $edit, 'test_user_field_add_more'); - } - else { - $this->drupalPostForm(NULL, $edit, t('Add another item')); - $this->drupalPostForm(NULL, $edit, t('Add another item')); - } - // Submit with three values. - $edit['test_user_field[1][value]'] = $value + 1; - $edit['test_user_field[2][value]'] = $value + 2; - $edit['name'] = $name = $this->randomMachineName(); - $edit['mail'] = $mail = $edit['name'] . '@example.com'; - $this->drupalPostForm(NULL, $edit, t('Create new account')); - // Check user fields. - $accounts = $this->container->get('entity_type.manager')->getStorage('user') - ->loadByProperties(['name' => $name, 'mail' => $mail]); - $new_user = reset($accounts); - $this->assertEqual($new_user->test_user_field[0]->value, $value, format_string('@js : The field value was correctly saved.', ['@js' => $js])); - $this->assertEqual($new_user->test_user_field[1]->value, $value + 1, format_string('@js : The field value was correctly saved.', ['@js' => $js])); - $this->assertEqual($new_user->test_user_field[2]->value, $value + 2, format_string('@js : The field value was correctly saved.', ['@js' => $js])); - } + $this->drupalGet('user/register'); + $this->assertRegistrationFormCacheTagsWithUserFields(); + // Add two inputs. + $value = random_int(1, 255); + $edit = []; + $edit['test_user_field[0][value]'] = $value; + $this->drupalPostForm(NULL, $edit, t('Add another item')); + $this->drupalPostForm(NULL, $edit, t('Add another item')); + // Submit with three values. + $edit['test_user_field[1][value]'] = $value + 1; + $edit['test_user_field[2][value]'] = $value + 2; + $edit['name'] = $name = $this->randomMachineName(); + $edit['mail'] = $mail = $edit['name'] . '@example.com'; + $this->drupalPostForm(NULL, $edit, t('Create new account')); + // Check user fields. + $accounts = $this->container->get('entity_type.manager')->getStorage('user') + ->loadByProperties(['name' => $name, 'mail' => $mail]); + $new_user = reset($accounts); + $this->assertEquals($new_user->test_user_field[0]->value, $value, t('The field value was correctly saved.')); + $this->assertEquals($new_user->test_user_field[1]->value, $value + 1, t('The field value was correctly saved.')); + $this->assertEquals($new_user->test_user_field[2]->value, $value + 2, t('The field value was correctly saved.')); } /**