UserInstallTest.php 1.34 KB
Newer Older
1
2
<?php

3
namespace Drupal\Tests\user\Kernel;
4

5
use Drupal\KernelTests\KernelTestBase;
6
7
8

/**
 * Tests user_install().
9
10
 *
 * @group user
11
 */
12
class UserInstallTest extends KernelTestBase {
13
14
15
16
17
18

  /**
   * Modules to enable.
   *
   * @var array
   */
19
  protected static $modules = ['user'];
20
21
22
23

  /**
   * {@inheritdoc}
   */
24
  protected function setUp(): void {
25
    parent::setUp();
26
27
28
    $this->container->get('module_handler')->loadInclude('user', 'install');
    $this->installEntitySchema('user');
    user_install();
29
30
31
32
33
34
  }

  /**
   * Test that the initial users have correct values.
   */
  public function testUserInstall() {
35
36
37
38
39
40
    $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');
41

42
43
    // Test that the anonymous and administrators languages are equal to the
    // site's default language.
44
45
    $this->assertEquals('en', $anon->language()->getId());
    $this->assertEquals('en', $admin->language()->getId());
46

47
    // Test that the administrator is active.
48
    $this->assertTrue($admin->isActive());
49
    // Test that the anonymous user is blocked.
50
    $this->assertTrue($anon->isBlocked());
51
52
53
  }

}