public function TmgmtSmartlingLogSettingsTest::testSeverityFilteringCritical in TMGMT Translator Smartling 8.3
Same name and namespace in other branches
- 8.4 modules/tmgmt_smartling_log_settings/tests/src/Kernel/TmgmtSmartlingLogSettingsTest.php \Drupal\Tests\tmgmt_smartling_log_settings\Kernel\TmgmtSmartlingLogSettingsTest::testSeverityFilteringCritical()
Test severity level logging: error.
File
- modules/
tmgmt_smartling_log_settings/ tests/ src/ Kernel/ TmgmtSmartlingLogSettingsTest.php, line 249
Class
- TmgmtSmartlingLogSettingsTest
- Test tmgmt_smartling_log_settings functionality.
Namespace
Drupal\Tests\tmgmt_smartling_log_settings\KernelCode
public function testSeverityFilteringCritical() {
/* @var \Drupal\Core\Config\Config $config */
$config = $this->container
->get('config.factory')
->getEditable('tmgmt_smartling_log_settings.settings');
$config
->set('severity_mapping', "smartling_api: critical\r\ntmgmt_smartling: debug");
$config
->save();
\Drupal::logger('smartling_api')
->debug('My test message.');
\Drupal::logger('smartling_api')
->info('My test message.');
\Drupal::logger('smartling_api')
->notice('My test message.');
\Drupal::logger('smartling_api')
->warning('My test message.');
\Drupal::logger('smartling_api')
->error('My test message.');
\Drupal::logger('smartling_api')
->critical('My test message.');
\Drupal::logger('smartling_api')
->alert('My test message.');
\Drupal::logger('smartling_api')
->emergency('My test message.');
\Drupal::logger('tmgmt_smartling')
->debug('My test message.');
\Drupal::logger('tmgmt_smartling')
->info('My test message.');
\Drupal::logger('tmgmt_smartling')
->notice('My test message.');
\Drupal::logger('tmgmt_smartling')
->warning('My test message.');
\Drupal::logger('tmgmt_smartling')
->error('My test message.');
\Drupal::logger('tmgmt_smartling')
->critical('My test message.');
\Drupal::logger('tmgmt_smartling')
->alert('My test message.');
\Drupal::logger('tmgmt_smartling')
->emergency('My test message.');
$log_filename = $this->container
->get('file_system')
->realpath('public://syslog.log');
$log_records = explode(PHP_EOL, file_get_contents($log_filename));
$this
->assertEquals(3, count(array_filter($log_records, function ($v) {
return strpos($v, 'smartling_api');
})), 'Messages below critical are filtered.');
$this
->assertEquals(8, count(array_filter($log_records, function ($v) {
return strpos($v, 'tmgmt_smartling');
})), 'Nothing is filtered.');
}