3 namespace Drupal\redirect_404\Tests;
6 * Tests suppressing 404 logs if the suppress_404 setting is enabled.
10 class Redirect404LogSuppressorTest extends Redirect404TestBase {
13 * Additional modules to enable.
17 public static $modules = ['dblog'];
20 * A user with some relevant administrative permissions.
22 * @var \Drupal\user\UserInterface
27 * A user without any permissions.
29 * @var \Drupal\user\UserInterface
36 public function setUp() {
39 // Create users with specific permissions.
40 $this->adminUser = $this->drupalCreateUser([
41 'administer redirect settings',
42 'administer redirects',
44 $this->webUser = $this->drupalCreateUser([]);
48 * Tests the suppress_404 service.
50 public function testSuppress404Events() {
51 // Cause a page not found and an access denied event.
52 $this->drupalGet('page-not-found');
53 $this->assertResponse(404);
54 $this->drupalLogin($this->webUser);
55 $this->drupalGet('admin/reports/dblog');
56 $this->assertResponse(403);
58 // Assert the events are logged in the dblog reports.
59 $this->assertEqual(db_query("SELECT COUNT(*) FROM {watchdog} WHERE type = 'page not found'")->fetchField(), 1);
60 $this->assertEqual(db_query("SELECT COUNT(*) FROM {watchdog} WHERE type = 'access denied'")->fetchField(), 1);
62 // Login as admin and enable suppress_404 to avoid logging the 404 event.
63 $this->drupalLogin($this->adminUser);
64 $edit = ['suppress_404' => TRUE];
65 $this->drupalPostForm('admin/config/search/redirect/settings', $edit, 'Save configuration');
67 // Cause again a page not found and an access denied event.
68 $this->drupalGet('page-not-found');
69 $this->assertResponse(404);
70 $this->drupalLogin($this->webUser);
71 $this->drupalGet('admin/reports/dblog');
72 $this->assertResponse(403);
74 // Assert only the new access denied event is logged now.
75 $this->drupalLogin($this->adminUser);
76 $this->assertEqual(db_query("SELECT COUNT(*) FROM {watchdog} WHERE type = 'page not found'")->fetchField(), 1);
77 $this->assertEqual(db_query("SELECT COUNT(*) FROM {watchdog} WHERE type = 'access denied'")->fetchField(), 2);