Chris@17: installSchema('dblog', ['watchdog']); Chris@17: $this->installSchema('system', ['key_value_expire', 'sequences']); Chris@17: $this->installConfig(['system']); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Tests that cron correctly applies the database log row limit. Chris@17: */ Chris@17: public function testDbLogCron() { Chris@17: $row_limit = 100; Chris@17: // Generate additional log entries. Chris@17: $this->generateLogEntries($row_limit + 10); Chris@17: // Verify that the database log row count exceeds the row limit. Chris@17: $count = db_query('SELECT COUNT(wid) FROM {watchdog}')->fetchField(); Chris@17: $this->assertGreaterThan($row_limit, $count, format_string('Dblog row count of @count exceeds row limit of @limit', ['@count' => $count, '@limit' => $row_limit])); Chris@17: Chris@17: // Get the number of enabled modules. Cron adds a log entry for each module. Chris@17: $list = $this->container->get('module_handler')->getImplementations('cron'); Chris@17: $module_count = count($list); Chris@17: $cron_detailed_count = $this->runCron(); Chris@17: $this->assertEquals($module_count + 2, $cron_detailed_count, format_string('Cron added @count of @expected new log entries', ['@count' => $cron_detailed_count, '@expected' => $module_count + 2])); Chris@17: Chris@17: // Test disabling of detailed cron logging. Chris@17: $this->config('system.cron')->set('logging', 0)->save(); Chris@17: $cron_count = $this->runCron(); Chris@17: $this->assertEquals(1, $cron_count, format_string('Cron added @count of @expected new log entries', ['@count' => $cron_count, '@expected' => 1])); Chris@17: } Chris@17: Chris@17: /** Chris@17: * Runs cron and returns number of new log entries. Chris@17: * Chris@17: * @return int Chris@17: * Number of new watchdog entries. Chris@17: */ Chris@17: private function runCron() { Chris@17: // Get last ID to compare against; log entries get deleted, so we can't Chris@17: // reliably add the number of newly created log entries to the current count Chris@17: // to measure number of log entries created by cron. Chris@17: $last_id = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField(); Chris@17: Chris@17: // Run a cron job. Chris@17: $this->container->get('cron')->run(); Chris@17: Chris@17: // Get last ID after cron was run. Chris@17: $current_id = db_query('SELECT MAX(wid) FROM {watchdog}')->fetchField(); Chris@17: Chris@17: return $current_id - $last_id; Chris@17: } Chris@17: Chris@17: }