Skip to content
Snippets Groups Projects
Commit 9a6e38c0 authored by catch's avatar catch
Browse files

Issue #3057399 by quietone, Akhil Babu, kristiaanvandeneynde, alexpott,...

Issue #3057399 by quietone, Akhil Babu, kristiaanvandeneynde, alexpott, pradhumanjain2311, smustgrave, catch, poker10, longwave, jimafisk, Newb_Druper, robpowell, dpi, tomdewild: Add user_requirements to check for missing anonymous user
parent 4b44980e
No related branches found
No related tags found
No related merge requests found
<?php
declare(strict_types=1);
namespace Drupal\Tests\user\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests the requirements checks of the User module.
*
* @group user
*/
class UserRequirementsTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that the requirements check can detect a missing anonymous user.
*/
public function testAnonymousUser(): void {
// Remove the anonymous user.
\Drupal::database()
->delete('users')
->condition('uid', 0)
->execute();
$this->drupalLogin($this->rootUser);
$this->drupalGet('/admin/reports/status');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains("The anonymous user does not exist.");
}
}
......@@ -93,6 +93,34 @@ function user_install() {
->save();
}
/**
* Implements hook_requirements().
*/
function user_requirements($phase): array {
if ($phase !== 'runtime') {
return [];
}
$result = (bool) \Drupal::entityQuery('user')
->accessCheck(FALSE)
->condition('uid', 0)
->range(0, 1)
->execute();
if ($result === FALSE) {
return [
'anonymous user' => [
'title' => t('Anonymous user'),
'description' => t('The anonymous user does not exist. See the <a href=":url">restore the anonymous (user ID 0) user record</a> for more information', [
':url' => 'https://www.drupal.org/node/1029506',
]),
'severity' => REQUIREMENT_WARNING,
],
];
}
return [];
}
/**
* Implements hook_update_last_removed().
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment