From f1418479b5f66c14de56e335752f0d65a84e0501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Wed, 19 Aug 2020 13:49:17 +0000 Subject: [PATCH] PMCORE-1801 --- gulliver/system/class.form.php | 2 +- tests/unit/gulliver/system/FormTest.php | 43 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 tests/unit/gulliver/system/FormTest.php 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)); + } +}