diff --git a/gulliver/system/class.form.php b/gulliver/system/class.form.php index e7acf358f..732275700 100644 --- a/gulliver/system/class.form.php +++ b/gulliver/system/class.form.php @@ -767,7 +767,7 @@ class Form extends XmlForm */ public static function createXMLFileIfNotExists($filepath) { - if (file_exists($filepath)) { + if (file_exists($filepath) && filesize($filepath) > 0) { return; } $pathParts = pathinfo($filepath); diff --git a/tests/unit/gulliver/system/FormTest.php b/tests/unit/gulliver/system/FormTest.php new file mode 100644 index 000000000..d60ad247b --- /dev/null +++ b/tests/unit/gulliver/system/FormTest.php @@ -0,0 +1,43 @@ +assertFileExists($xmlForm); + + // File with content? + $this->assertNotEmpty(file_get_contents($xmlForm)); + + // Delete the file + unlink($xmlForm); + + // Create another empty + touch($xmlForm); + + // The file exists, but is empty, should be regenerated + Form::createXMLFileIfNotExists($xmlForm); + + // File with content? + $this->assertNotEmpty(file_get_contents($xmlForm)); + } +}