Unverified Commit 243e2910 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3151520 by adityasingh, pavnish, daffie, alexpott: Replace the database...

Issue #3151520 by adityasingh, pavnish, daffie, alexpott: Replace the database query with an entity query in UserInstallTest

(cherry picked from commit 5ded5317)
parent d63ddf19
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@

namespace Drupal\Tests\user\Kernel;

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

/**
@@ -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());
  }

}