Skip to content
Snippets Groups Projects
Commit 72df1995 authored by Marc Egger's avatar Marc Egger
Browse files

Fix Unittests: add index to backup file if it already exists

parent 0251e34f
No related branches found
No related tags found
2 merge requests!302Develop,!296Marc: Form/Report As File, Path class, Config class, Typo3 v9 compatability
Pipeline #3946 failed
...@@ -584,7 +584,7 @@ class FormAsFile ...@@ -584,7 +584,7 @@ class FormAsFile
} }
return $jsonFileNames = array_reduce($files, function ($result, $file) { return $jsonFileNames = array_reduce($files, function ($result, $file) {
$fileInfo = pathinfo($file); $fileInfo = pathinfo($file);
if ($fileInfo['extension'] === 'json') { if (array_key_exists('extension', $fileInfo) && $fileInfo['extension'] === 'json') {
$result[] = $fileInfo['filename']; $result[] = $fileInfo['filename'];
} }
return $result; return $result;
...@@ -681,10 +681,16 @@ class FormAsFile ...@@ -681,10 +681,16 @@ class FormAsFile
} }
} }
// throw exception if backup file exists
$cwdToBackupFile = Path::join($cwdToBackup, $formName . '.' . date('YmdHis') . ".$tag.json"); $cwdToBackupFile = Path::join($cwdToBackup, $formName . '.' . date('YmdHis') . ".$tag.json");
if (file_exists($cwdToBackupFile)) {
Thrower::userFormException('Error while trying to backup form file.', "Backup file already exists: $cwdToBackupFile"); // add index to filename if backup file with current timestamp already exists
$index = 1;
while (file_exists($cwdToBackupFile)) {
$cwdToBackupFile = Path::join($cwdToBackup, $formName . '.' . date('YmdHis') . ".$index.$tag.json");
$index ++;
if ($index > 100) {
Thrower::userFormException('Error while trying to backup form file.', 'Infinite loop.');
}
} }
return $cwdToBackupFile; return $cwdToBackupFile;
} }
......
...@@ -215,11 +215,18 @@ class ReportAsFile ...@@ -215,11 +215,18 @@ class ReportAsFile
} }
} }
// throw exception if backup file exists
$cwdToBackupFile = Path::join($cwdToBackup, basename($cwdToReportFile, REPORT_FILE_EXTENSION) . '.' . date('YmdHis') . ".json"); $cwdToBackupFile = Path::join($cwdToBackup, basename($cwdToReportFile, REPORT_FILE_EXTENSION) . '.' . date('YmdHis') . ".json");
if (file_exists($cwdToBackupFile)) {
Thrower::userFormException('Error while trying to backup report file.', "Backup file already exists: $cwdToBackupFile"); // add index to filename if backup file with current timestamp already exists
$index = 1;
while (file_exists($cwdToBackupFile)) {
$cwdToBackupFile = Path::join($cwdToBackup, basename($cwdToReportFile, REPORT_FILE_EXTENSION) . '.' . date('YmdHis') . ".$index.json");
$index ++;
if ($index > 100) {
Thrower::userFormException('Error while trying to backup report file.', 'Infinite loop.');
}
} }
return $cwdToBackupFile; return $cwdToBackupFile;
} }
......
# QFQ Tests
## PhpUnit
### Run unit tests from CLI:
Make sure dev dependencies are installed:
```shell script
# in extension directory
composer update --dev
```
Run all tests:
```shell script
# in extension directory
vendor/bin/phpunit --configuration phpunit.xml
```
Run single test:
```shell script
# in extension directory
vendor/bin/phpunit --configuration phpunit.xml --filter <test_name>
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment