Chris@0: account = $this->drupalCreateUser(); Chris@0: $this->anonymous = User::create(['uid' => 0]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Test label callback. Chris@0: */ Chris@0: public function testLabelCallback() { Chris@0: $this->assertEqual($this->account->label(), $this->account->getUsername(), 'The username should be used as label'); Chris@0: Chris@0: // Setup a random anonymous name to be sure the name is used. Chris@0: $name = $this->randomMachineName(); Chris@0: $this->config('user.settings')->set('anonymous', $name)->save(); Chris@0: $this->assertEqual($this->anonymous->label(), $name, 'The variable anonymous should be used for name of uid 0'); Chris@0: $this->assertEqual($this->anonymous->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0'); Chris@0: $this->assertEqual($this->anonymous->getUserName(), '', 'The raw anonymous user name should be empty string'); Chris@0: Chris@0: // Set to test the altered username. Chris@0: \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE); Chris@0: Chris@0: $this->assertEqual($this->account->getDisplayName(), '' . $this->account->id() . '', 'The user display name should be altered.'); Chris@0: $this->assertEqual($this->account->getUsername(), $this->account->name->value, 'The user name should not be altered.'); Chris@0: } Chris@0: Chris@0: }