X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fuser%2Ftests%2Fsrc%2FFunctional%2FUserEntityCallbacksTest.php;fp=web%2Fcore%2Fmodules%2Fuser%2Ftests%2Fsrc%2FFunctional%2FUserEntityCallbacksTest.php;h=feea805afd1146bf3e3bb445db837a188011a688;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php b/web/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php new file mode 100644 index 000000000..feea805af --- /dev/null +++ b/web/core/modules/user/tests/src/Functional/UserEntityCallbacksTest.php @@ -0,0 +1,64 @@ +account = $this->drupalCreateUser(); + $this->anonymous = User::create(['uid' => 0]); + } + + /** + * Test label callback. + */ + public function testLabelCallback() { + $this->assertEqual($this->account->label(), $this->account->getUsername(), 'The username should be used as label'); + + // Setup a random anonymous name to be sure the name is used. + $name = $this->randomMachineName(); + $this->config('user.settings')->set('anonymous', $name)->save(); + $this->assertEqual($this->anonymous->label(), $name, 'The variable anonymous should be used for name of uid 0'); + $this->assertEqual($this->anonymous->getDisplayName(), $name, 'The variable anonymous should be used for display name of uid 0'); + $this->assertEqual($this->anonymous->getUserName(), '', 'The raw anonymous user name should be empty string'); + + // Set to test the altered username. + \Drupal::state()->set('user_hooks_test_user_format_name_alter', TRUE); + + $this->assertEqual($this->account->getDisplayName(), '' . $this->account->id() . '', 'The user display name should be altered.'); + $this->assertEqual($this->account->getUsername(), $this->account->name->value, 'The user name should not be altered.'); + } + +}