Skip to content
Snippets Groups Projects

Resolve #3496184: Replace dblog at tests with Logger

Closed Nikolay Shapovalov requested to merge issue/drupal-3496184:3496184-logger-proxy-class into 11.x
Files
6
@@ -6,13 +6,14 @@
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Core\Logger\RfcLogLevel;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Drupal\TestTools\TestLoggerProxy;
/**
* Tests integration of comment with other components.
@@ -32,7 +33,6 @@ class CommentIntegrationTest extends KernelTestBase {
'entity_test',
'user',
'system',
'dblog',
];
/**
@@ -43,7 +43,6 @@ protected function setUp(): void {
$this->installEntitySchema('entity_test');
$this->installEntitySchema('user');
$this->installEntitySchema('comment');
$this->installSchema('dblog', ['watchdog']);
// Create a new 'comment' comment-type.
CommentType::create([
@@ -104,6 +103,10 @@ public function testViewMode(): void {
$host_display_id = 'entity_test.entity_test.default';
$comment_display_id = "comment.comment.$mode";
// Attach logger to 'system' channel, to catch log message.
$logger = new TestLoggerProxy();
\Drupal::service('logger.factory')->get('system')->addLogger($logger);
// Disable the "comment.comment.$mode" display.
EntityViewDisplay::load($comment_display_id)->setStatus(FALSE)->save();
@@ -115,19 +118,16 @@ public function testViewMode(): void {
$this->assertTrue($host_display->get('hidden')[$field_name]);
// Check that the proper warning has been logged.
$arguments = [
'@id' => $host_display_id,
'@name' => $field_name,
'@display' => EntityViewMode::load("comment.$mode")->label(),
'@mode' => $mode,
$expected_message = [
'message' => "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.",
'context' => [
'@id' => $host_display_id,
'@name' => $field_name,
'@display' => EntityViewMode::load("comment.$mode")->label(),
'@mode' => $mode,
],
];
$logged = Database::getConnection()->select('watchdog')
->fields('watchdog', ['variables'])
->condition('type', 'system')
->condition('message', "View display '@id': Comment field formatter '@name' was disabled because it is using the comment view display '@display' (@mode) that was just disabled.")
->execute()
->fetchField();
$this->assertEquals(serialize($arguments), $logged);
$this->assertTrue($logger->hasRecord($expected_message, RfcLogLevel::WARNING));
// Re-enable the comment view display.
EntityViewDisplay::load($comment_display_id)->setStatus(TRUE)->save();
Loading