Skip to content

Commit

Permalink
Issue #3151520 by adityasingh, pavnish, daffie, alexpott: Replace the…
Browse files Browse the repository at this point in the history
… database query with an entity query in UserInstallTest

(cherry picked from commit 5ded531763f04263b064ea3bf8fb135b53e80d8a)
  • Loading branch information
alexpott committed Jun 29, 2020
1 parent 10b25cf commit 2bffb90
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions modules/user/tests/src/Kernel/UserInstallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Drupal\Tests\user\Kernel;

use Drupal\Core\Database\Database;
use Drupal\KernelTests\KernelTestBase;

/**
Expand Down Expand Up @@ -33,22 +32,22 @@ protected function setUp() {
* Test that the initial users have correct values.
*/
public function testUserInstall() {
$result = Database::getConnection()->query('SELECT u.uid, u.uuid, u.langcode, uf.status FROM {users} u INNER JOIN {users_field_data} uf ON u.uid=uf.uid ORDER BY u.uid')
->fetchAllAssoc('uid');
$anon = $result[0];
$admin = $result[1];
$this->assertFalse(empty($anon->uuid), 'Anon user has a UUID');
$this->assertFalse(empty($admin->uuid), 'Admin user has a UUID');
$user_ids = \Drupal::entityQuery('user')->sort('uid')->execute();
$users = \Drupal::entityTypeManager()->getStorage('user')->loadMultiple($user_ids);
$anon = $users[0];
$admin = $users[1];
$this->assertNotEmpty($anon->uuid(), 'Anon user has a UUID');
$this->assertNotEmpty($admin->uuid(), 'Admin user has a UUID');

// Test that the anonymous and administrators languages are equal to the
// site's default language.
$this->assertEqual($anon->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId());
$this->assertEqual($admin->langcode, \Drupal::languageManager()->getDefaultLanguage()->getId());
$this->assertEquals('en', $anon->language()->getId());
$this->assertEquals('en', $admin->language()->getId());

// Test that the administrator is active.
$this->assertEqual($admin->status, 1);
$this->assertTrue($admin->isActive());
// Test that the anonymous user is blocked.
$this->assertEqual($anon->status, 0);
$this->assertTrue($anon->isBlocked());
}

}

0 comments on commit 2bffb90

Please sign in to comment.