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 71% rename from core/modules/user/src/Tests/UserBlocksTest.php rename to core/modules/user/tests/src/Functional/UserBlocksTest.php index 0a4c619da6..6c2ae97609 100644 --- a/core/modules/user/src/Tests/UserBlocksTest.php +++ b/core/modules/user/tests/src/Functional/UserBlocksTest.php @@ -1,16 +1,16 @@ getUsername(); - $edit['pass'] = $user->pass_raw; + $edit['pass'] = $user->passRaw; $this->drupalPostForm('admin/people/permissions', $edit, t('Log in')); $this->assertNoText(t('User login'), 'Logged in.'); @@ -121,46 +121,4 @@ public function testUserLoginBlock() { $this->assertNoText(t('Unrecognized username or password. Forgot your password?')); } - /** - * Test the Who's Online block. - */ - public function testWhosOnlineBlock() { - $block = $this->drupalPlaceBlock('views_block:who_s_online-who_s_online_block'); - - // Generate users. - $user1 = $this->drupalCreateUser(['access user profiles']); - $user2 = $this->drupalCreateUser([]); - $user3 = $this->drupalCreateUser([]); - - // Update access of two users to be within the active timespan. - $this->updateAccess($user1->id()); - $this->updateAccess($user2->id(), REQUEST_TIME + 1); - - // Insert an inactive user who should not be seen in the block, and ensure - // that the admin user used in setUp() does not appear. - $inactive_time = REQUEST_TIME - (15 * 60) - 1; - $this->updateAccess($user3->id(), $inactive_time); - $this->updateAccess($this->adminUser->id(), $inactive_time); - - // Test block output. - \Drupal::currentUser()->setAccount($user1); - $content = entity_view($block, 'block'); - $this->setRawContent(\Drupal::service('renderer')->renderRoot($content)); - $this->assertRaw(t('2 users'), 'Correct number of online users (2 users).'); - $this->assertText($user1->getUsername(), 'Active user 1 found in online list.'); - $this->assertText($user2->getUsername(), 'Active user 2 found in online list.'); - $this->assertNoText($user3->getUsername(), 'Inactive user not found in online list.'); - $this->assertTrue(strpos($this->getRawContent(), $user1->getUsername()) > strpos($this->getRawContent(), $user2->getUsername()), 'Online users are ordered correctly.'); - } - - /** - * Updates the access column for a user. - */ - private function updateAccess($uid, $access = REQUEST_TIME) { - db_update('users_field_data') - ->condition('uid', $uid) - ->fields(['access' => $access]) - ->execute(); - } - } diff --git a/core/modules/user/src/Tests/UserCreateTest.php b/core/modules/user/tests/src/Functional/UserCreateTest.php similarity index 94% rename from core/modules/user/src/Tests/UserCreateTest.php rename to core/modules/user/tests/src/Functional/UserCreateTest.php index 7b534435a0..fb7e996e3f 100644 --- a/core/modules/user/src/Tests/UserCreateTest.php +++ b/core/modules/user/tests/src/Functional/UserCreateTest.php @@ -1,18 +1,22 @@ drupalGet('admin/people'); $this->assertText($edit['name'], 'User found in list of users'); $user = user_load_by_name($name); - $this->assertEqual($user->isActive(), 'User is not blocked'); + $this->assertTrue($user->isActive(), 'User is not blocked'); } // Test that the password '0' is considered a password. diff --git a/core/modules/user/src/Tests/UserPasswordResetTest.php b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php similarity index 97% rename from core/modules/user/src/Tests/UserPasswordResetTest.php rename to core/modules/user/tests/src/Functional/UserPasswordResetTest.php index 528d38bc96..fb25317075 100644 --- a/core/modules/user/src/Tests/UserPasswordResetTest.php +++ b/core/modules/user/tests/src/Functional/UserPasswordResetTest.php @@ -1,11 +1,13 @@ 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 @@ -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 90% rename from core/modules/user/src/Tests/UserRegistrationTest.php rename to core/modules/user/tests/src/Functional/UserRegistrationTest.php index ca7a4f0c89..fb63a5d320 100644 --- a/core/modules/user/src/Tests/UserRegistrationTest.php +++ b/core/modules/user/tests/src/Functional/UserRegistrationTest.php @@ -1,20 +1,20 @@ 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.')); } /**