You are here

public function TmgmtSmartlingLogSettingsTest::testSeverityFilteringEmptyConfig in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 modules/tmgmt_smartling_log_settings/tests/src/Kernel/TmgmtSmartlingLogSettingsTest.php \Drupal\Tests\tmgmt_smartling_log_settings\Kernel\TmgmtSmartlingLogSettingsTest::testSeverityFilteringEmptyConfig()

Test severity level logging: empty config.

File

modules/tmgmt_smartling_log_settings/tests/src/Kernel/TmgmtSmartlingLogSettingsTest.php, line 27

Class

TmgmtSmartlingLogSettingsTest
Test tmgmt_smartling_log_settings functionality.

Namespace

Drupal\Tests\tmgmt_smartling_log_settings\Kernel

Code

public function testSeverityFilteringEmptyConfig() {

  /* @var \Drupal\Core\Config\Config $config */
  $config = $this->container
    ->get('config.factory')
    ->getEditable('tmgmt_smartling_log_settings.settings');
  $config
    ->set('severity_mapping', '');
  $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(8, count(array_filter($log_records, function ($v) {
    return strpos($v, 'smartling_api');
  })), 'Nothing is filtered.');
  $this
    ->assertEquals(8, count(array_filter($log_records, function ($v) {
    return strpos($v, 'tmgmt_smartling');
  })), 'Nothing is filtered.');
}