function UserSessionTest::testNamePropertyDeprecation
Tests the name property deprecation.
@legacy-covers ::__get @legacy-covers ::__isset @legacy-covers ::__set
Attributes
#[IgnoreDeprecations]
File
-
core/
tests/ Drupal/ Tests/ Core/ Session/ UserSessionTest.php, line 95
Class
Namespace
Drupal\Tests\Core\SessionCode
public function testNamePropertyDeprecation() : void {
$user = new UserSession([
'name' => 'test',
]);
$this->expectDeprecation('Getting the name property is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Session\\UserSession::getAccountName() instead. See https://www.drupal.org/node/3513856');
self::assertEquals($user->name, $user->getAccountName());
$this->expectDeprecation('Checking for the name property is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Use \\Drupal\\Core\\Session\\UserSession::getAccountName() instead. See https://www.drupal.org/node/3513856');
self::assertTrue(isset($user->name));
// Test setting the name property.
$this->expectDeprecation('Setting the name property is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Set the name via the constructor when creating the UserSession instance. See https://www.drupal.org/node/3513856');
$user->name = 'test new';
$this->assertEquals('test new', $user->getAccountName());
// Verify protected properties cannot be accessed.
$this->expectExceptionMessage('Cannot access protected property mail in Drupal\\Core\\Session\\UserSession');
$user->mail;
// Verify dynamic properties can be set and accessed.
$user->foo = 'bar';
$this->assertEquals('bar', $user->foo);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.