function UserSessionTest::testHasPermissionLegacy

Tests deprecation when permission is not a string.

@covers ::hasPermission @group legacy

File

core/tests/Drupal/Tests/Core/Session/UserSessionTest.php, line 91

Class

UserSessionTest
@coversDefaultClass \Drupal\Core\Session\UserSession @group Session

Namespace

Drupal\Tests\Core\Session

Code

public function testHasPermissionLegacy() : void {
    $this->expectDeprecation('Calling Drupal\\Core\\Session\\UserSession::hasPermission() with a $permission parameter of type other than string is deprecated in drupal:10.3.0 and will cause an error in drupal:11.0.0. See https://www.drupal.org/node/3411485');
    $this->assertFalse((new UserSession())->hasPermission(NULL));
    $this->expectDeprecation('Calling Drupal\\user\\Entity\\User::hasPermission() with a $permission parameter of type other than string is deprecated in drupal:10.3.0 and will cause an error in drupal:11.0.0. See https://www.drupal.org/node/3411485');
    $reflection = new \ReflectionClass(User::class);
    $user = $reflection->newInstanceWithoutConstructor();
    $this->assertFalse($user->hasPermission(NULL));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.