TYPO3 CMS  TYPO3_7-6
DatabaseWriterTest.php
Go to the documentation of this file.
1 <?php
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 
21 {
25  public function getTableReturnsPreviouslySetTable()
26  {
27  $logTable = $this->getUniqueId('logtable_');
29  $subject = $this->getMock(\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class, ['dummy'], [], '', false);
30  $subject->setLogTable($logTable);
31  $this->assertSame($logTable, $subject->getLogTable());
32  }
33 
38  public function writeLogThrowsExceptionIfDatabaseInsertFailed()
39  {
40  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, [], [], '', false);
41  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->will($this->returnValue(false));
43  $logRecordMock = $this->getMock(\TYPO3\CMS\Core\Log\LogRecord::class, [], [], '', false);
45  $subject = $this->getMock(\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class, ['dummy'], [], '', false);
46  $subject->writeLog($logRecordMock);
47  }
48 
52  public function writeLogInsertsToSpecifiedTable()
53  {
54  $logTable = $this->getUniqueId('logtable_');
55  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, [], [], '', false);
56  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->with($logTable, $this->anything());
58  $logRecordMock = $this->getMock(\TYPO3\CMS\Core\Log\LogRecord::class, [], [], '', false);
60  $subject = $this->getMock(\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class, ['dummy'], [], '', false);
61  $subject->setLogTable($logTable);
62  $subject->writeLog($logRecordMock);
63  }
64 
68  public function writeLogInsertsLogRecordWithGivenProperties()
69  {
70  $logRecordData = [
71  'request_id' => $this->getUniqueId('request_id'),
72  'time_micro' => $this->getUniqueId('time_micro'),
73  'component' => $this->getUniqueId('component'),
74  'level' => $this->getUniqueId('level'),
75  'message' => $this->getUniqueId('message'),
76  'data' => '',
77  ];
79  $logRecordFixture = $this->getMock(\TYPO3\CMS\Core\Log\LogRecord::class, [], [], '', false);
80  $logRecordFixture->expects($this->any())->method('getRequestId')->will($this->returnValue($logRecordData['request_id']));
81  $logRecordFixture->expects($this->any())->method('getCreated')->will($this->returnValue($logRecordData['time_micro']));
82  $logRecordFixture->expects($this->any())->method('getComponent')->will($this->returnValue($logRecordData['component']));
83  $logRecordFixture->expects($this->any())->method('getLevel')->will($this->returnValue($logRecordData['level']));
84  $logRecordFixture->expects($this->any())->method('getMessage')->will($this->returnValue($logRecordData['message']));
85  $logRecordFixture->expects($this->any())->method('getData')->will($this->returnValue([]));
86 
88  //$subject = $this->getMock(\TYPO3\CMS\Core\Log\Writer\DatabaseWriter::class, array('dummy'), array(), '', FALSE);
89  $subject = new \TYPO3\CMS\Core\Log\Writer\DatabaseWriter();
90 
91  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, [], [], '', false);
92  $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->with($this->anything(), $logRecordData);
93 
94  $subject->writeLog($logRecordFixture);
95  }
96 }
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']