Skip to content
Snippets Groups Projects
Verified Commit d4c85a52 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3495091 by nikolay shapovalov: Use BufferingLogger at SmartDefaultSettingsTest

parent 541f985c
No related branches found
No related tags found
No related merge requests found
...@@ -8,11 +8,14 @@ ...@@ -8,11 +8,14 @@
use Drupal\ckeditor5\HTMLRestrictions; use Drupal\ckeditor5\HTMLRestrictions;
use Drupal\Component\Utility\NestedArray; use Drupal\Component\Utility\NestedArray;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Entity\Entity\EntityViewMode; use Drupal\Core\Entity\Entity\EntityViewMode;
use Drupal\Core\Logger\LogMessageParserInterface;
use Drupal\editor\Entity\Editor; use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat; use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\KernelTestBase; use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\SchemaCheckTestTrait; use Drupal\Tests\SchemaCheckTestTrait;
use Symfony\Component\ErrorHandler\BufferingLogger;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
/** /**
...@@ -64,6 +67,20 @@ class SmartDefaultSettingsTest extends KernelTestBase { ...@@ -64,6 +67,20 @@ class SmartDefaultSettingsTest extends KernelTestBase {
*/ */
protected $database; protected $database;
/**
* The service name for a logger implementation that collects anything logged.
*
* @var string
*/
protected string $testLogServiceName = 'smart_default_settings_test.logger';
/**
* The message's placeholders parser.
*
* @var \Drupal\Core\Logger\LogMessageParserInterface
*/
protected LogMessageParserInterface $parser;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -76,7 +93,6 @@ class SmartDefaultSettingsTest extends KernelTestBase { ...@@ -76,7 +93,6 @@ class SmartDefaultSettingsTest extends KernelTestBase {
'media', 'media',
'media_library', 'media_library',
'views', 'views',
'dblog',
'help', 'help',
'editor_test', 'editor_test',
'ckeditor_test', 'ckeditor_test',
...@@ -90,9 +106,7 @@ protected function setUp(): void { ...@@ -90,9 +106,7 @@ protected function setUp(): void {
$this->manager = $this->container->get('plugin.manager.ckeditor5.plugin'); $this->manager = $this->container->get('plugin.manager.ckeditor5.plugin');
$this->typedConfig = $this->container->get('config.typed'); $this->typedConfig = $this->container->get('config.typed');
$this->smartDefaultSettings = $this->container->get('ckeditor5.smart_default_settings'); $this->smartDefaultSettings = $this->container->get('ckeditor5.smart_default_settings');
$this->database = $this->container->get('database'); $this->parser = $this->container->get('logger.log_message_parser');
$this->installSchema('dblog', ['watchdog']);
FilterFormat::create([ FilterFormat::create([
'format' => 'minimal_ckeditor_wrong_allowed_html', 'format' => 'minimal_ckeditor_wrong_allowed_html',
...@@ -510,22 +524,20 @@ public function test(string $format_id, array $filters_to_drop, array $expected_ ...@@ -510,22 +524,20 @@ public function test(string $format_id, array $filters_to_drop, array $expected_
$this->assertSame($expected_post_update_text_editor_violations, $updated_validation_errors); $this->assertSame($expected_post_update_text_editor_violations, $updated_validation_errors);
} }
$db_logged = $this // Get log messages.
->database $log_messages = $this->container->get($this->testLogServiceName)->cleanLogs();
->select('watchdog', 'w')
->fields('w', ['message', 'variables', 'severity'])
->condition('type', 'ckeditor5')
->orderBy('wid')
->execute()
->fetchAll();
$type_to_status = [ $type_to_status = [
6 => 'status', 6 => 'status',
4 => 'warning', 4 => 'warning',
]; ];
$db_logs = [];
foreach ($db_logged as $log) { // Convert messages array to provider format.
$db_logs[$type_to_status[$log->severity]][] = [$log->message, $log->variables]; $logs = [];
foreach ($log_messages as $log) {
// Remove all from context except message arguments.
$message_arguments = $this->parser->parseMessagePlaceholders($log[1], $log[2]);
$logs[$type_to_status[$log[0]]][] = [$log[1], serialize($message_arguments)];
} }
// Transforms TranslatableMarkup objects to string. // Transforms TranslatableMarkup objects to string.
...@@ -535,10 +547,20 @@ public function test(string $format_id, array $filters_to_drop, array $expected_ ...@@ -535,10 +547,20 @@ public function test(string $format_id, array $filters_to_drop, array $expected_
} }
} }
$this->assertSame($expected_db_logs, $db_logs); $this->assertSame($expected_db_logs, $logs);
$this->assertSame($expected_messages, $messages); $this->assertSame($expected_messages, $messages);
} }
/**
* {@inheritdoc}
*/
public function register(ContainerBuilder $container): void {
parent::register($container);
$container
->register($this->testLogServiceName, BufferingLogger::class)
->addTag('logger');
}
/** /**
* Data provider. * Data provider.
* *
......
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