[TASK] Add possibility to assert error log entries 86/27886/3
authorOliver Hader <oliver@typo3.org>
Thu, 27 Feb 2014 09:51:23 +0000 (10:51 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 11 Mar 2014 21:55:18 +0000 (22:55 +0100)
During the action tests it might happen, that errors occur.
To assert expected or unexpected error log entries in the
sys_log table, this functionality shall be added to the
functional testing framework.

Resolves: #56369
Releases: 6.2
Change-Id: I07806e69cb7f575c844a3adf442233a82fa01505
Reviewed-on: https://review.typo3.org/27886
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/core/Tests/Functional/DataHandling/AbstractDataHandlerActionTestCase.php

index 2dc70fa..a8b249f 100644 (file)
@@ -42,7 +42,10 @@ abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\F
        protected $dataSetDirectory;
 
        /**
-        * @var int
+        * If this value is NULL, log entries are not considered.
+        * If it's an integer value, the number of log entries is asserted.
+        *
+        * @var NULL|int
         */
        protected $expectedErrorLogEntries = 0;
 
@@ -84,6 +87,7 @@ abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\F
        }
 
        public function tearDown() {
+               $this->assertErrorLogEntries();
                unset($this->actionService);
                parent::tearDown();
        }
@@ -183,6 +187,30 @@ abstract class AbstractDataHandlerActionTestCase extends \TYPO3\CMS\Core\Tests\F
        }
 
        /**
+        * Asserts correct number of warning and error log entries.
+        *
+        * @return void
+        */
+       protected function assertErrorLogEntries() {
+               if ($this->expectedErrorLogEntries === NULL) {
+                       return;
+               }
+               $errorLogEntries = $this->getDatabase()->exec_SELECTgetRows('*', 'sys_log', 'error IN (1,2)');
+               $actualErrorLogEntries = count($errorLogEntries);
+               if ($actualErrorLogEntries === $this->expectedErrorLogEntries) {
+                       $this->assertSame($this->expectedErrorLogEntries, $actualErrorLogEntries);
+               } else {
+                       $failureMessage = 'Expected ' . $this->expectedErrorLogEntries . ' entries in sys_log, but got ' . $actualErrorLogEntries . LF;
+                       foreach ($errorLogEntries as $entry) {
+                               $entryData = unserialize($entry['log_data']);
+                               $entryMessage = vsprintf($entry['details'], $entryData);
+                               $failureMessage .= '* ' . $entryMessage . LF;
+                       }
+                       $this->fail($failureMessage);
+               }
+       }
+
+       /**
         * @param string $tableName
         * @param bool $hasUidField
         * @return array