diff --git a/t3lib/class.t3lib_tcemain.php b/t3lib/class.t3lib_tcemain.php index 9c48ee81be38dfec65e250af08eddb501c225101..c0730d57ec66f92853619dd32dda96dbb83a5993 100644 --- a/t3lib/class.t3lib_tcemain.php +++ b/t3lib/class.t3lib_tcemain.php @@ -7059,7 +7059,11 @@ class t3lib_TCEmain { $details = ''; } if ($error > 0) { - $this->errorLog[] = '[' . $type . '.' . $action . '.' . $details_nr . ']: ' . $details; + $detailMessage = $details; + if (is_array($data)) { + $detailMessage = vsprintf($details, $data); + } + $this->errorLog[] = '[' . $type . '.' . $action . '.' . $details_nr . ']: ' . $detailMessage; } return $this->BE_USER->writelog($type, $action, $error, $details_nr, $details, $data, $table, $recuid, $recpid, $event_pid, $NEWid); } diff --git a/tests/Unit/t3lib/class.t3lib_tcemainTest.php b/tests/Unit/t3lib/class.t3lib_tcemainTest.php index 0bdb5dd87795d3ca45591f868bd43ce238730f90..9437c391571d337ea7e406846be86844fc9b620e 100644 --- a/tests/Unit/t3lib/class.t3lib_tcemainTest.php +++ b/tests/Unit/t3lib/class.t3lib_tcemainTest.php @@ -323,5 +323,58 @@ class t3lib_tcemainTest extends tx_phpunit_testcase { $fixture->process_datamap(); } + + ///////////////////////////////////// + // Tests concerning log + ///////////////////////////////////// + + /** + * @test + */ + public function logCallsWriteLogOfBackendUserIfLoggingIsEnabled() { + $backendUser = $this->getMock('t3lib_beUserAuth'); + $backendUser->expects($this->once())->method('writelog'); + $this->fixture->enableLogging = TRUE; + $this->fixture->BE_USER = $backendUser; + $this->fixture->log('', 23, 0, 42, 0, 'details'); + } + + /** + * @test + */ + public function logDoesNotCallWriteLogOfBackendUserIfLoggingIsDisabled() { + $backendUser = $this->getMock('t3lib_beUserAuth'); + $backendUser->expects($this->never())->method('writelog'); + $this->fixture->enableLogging = FALSE; + $this->fixture->BE_USER = $backendUser; + $this->fixture->log('', 23, 0, 42, 0, 'details'); + } + + /** + * @test + */ + public function logAddsEntryToLocalErrorLogArray() { + $backendUser = $this->getMock('t3lib_beUserAuth'); + $this->fixture->BE_USER = $backendUser; + $this->fixture->enableLogging = TRUE; + $this->fixture->errorLog = array(); + $logDetailsUnique = uniqid('details'); + $this->fixture->log('', 23, 0, 42, 1, $logDetailsUnique); + $this->assertStringEndsWith($logDetailsUnique, $this->fixture->errorLog[0]); + } + + /** + * @test + */ + public function logFormatsDetailMessageWithAdditionalDataInLocalErrorArray() { + $backendUser = $this->getMock('t3lib_beUserAuth'); + $this->fixture->BE_USER = $backendUser; + $this->fixture->enableLogging = TRUE; + $this->fixture->errorLog = array(); + $logDetails = uniqid('details'); + $this->fixture->log('', 23, 0, 42, 1, '%1s' . $logDetails . '%2s', -1, array('foo', 'bar')); + $expected = 'foo' . $logDetails . 'bar'; + $this->assertStringEndsWith($expected, $this->fixture->errorLog[0]); + } } ?> \ No newline at end of file