[BUGFIX] Markers (%s) are not replaced in TCEmain error messages
authorBart Dubelaar <bartdubelaar@gmail.com>
Fri, 20 Apr 2012 19:17:57 +0000 (21:17 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 30 Jun 2012 12:15:32 +0000 (14:15 +0200)
Change-Id: I33d8840390deba3e8a2ac5a188fd6fb089b91b5f
Fixes: #36290
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/12466
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/class.t3lib_tcemain.php
tests/t3lib/t3lib_tcemainTest.php

index cfff942..dfc9772 100644 (file)
@@ -7083,7 +7083,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);
                }
index 9c5c7ac..2bc0322 100644 (file)
@@ -236,5 +236,58 @@ class t3lib_tcemainTest extends tx_phpunit_testcase {
 
                $this->assertTrue($this->fixture->checkModifyAccessList('tt_content'));
        }
+
+       /////////////////////////////////////
+       // 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