de2f34650a5fdb80e771e36dfa90636f228f3b34
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Log / Writer / DatabaseWriterTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Functional\Log\Writer;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Core\Bootstrap;
18 use TYPO3\CMS\Core\Database\ConnectionPool;
19 use TYPO3\CMS\Core\Log\LogLevel;
20 use TYPO3\CMS\Core\Log\LogRecord;
21 use TYPO3\CMS\Core\Log\Writer\DatabaseWriter;
22
23 /**
24 * Test case
25 */
26 class DatabaseWriterTest extends \TYPO3\Components\TestingFramework\Core\FunctionalTestCase
27 {
28 /**
29 * @test
30 */
31 public function writeLogInsertsLogRecordWithGivenProperties()
32 {
33 $logRecordData = [
34 'request_id' => Bootstrap::getInstance()->getRequestId(),
35 'time_micro' => 1469740000.0,
36 'component' => 'aComponent',
37 'level' => LogLevel::DEBUG,
38 'message' => 'aMessage',
39 'data' => ''
40 ];
41 $logRecord = new LogRecord(
42 $logRecordData['component'],
43 $logRecordData['level'],
44 $logRecordData['message'],
45 []
46 );
47 $logRecord->setCreated($logRecordData['time_micro']);
48
49 (new DatabaseWriter())->writeLog($logRecord);
50
51 $rowInDatabase = (new ConnectionPool())->getConnectionForTable('sys_log')
52 ->select(
53 array_keys($logRecordData),
54 'sys_log',
55 ['request_id' => $logRecordData['request_id']]
56 )
57 ->fetch();
58
59 $this->assertEquals($logRecordData, $rowInDatabase);
60 }
61 }