From 7e096d5e5b592cb514f11d546691eebd02318233 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Fri, 29 Jun 2018 12:16:30 +0100 Subject: [PATCH 1/2] Fix missing opening copy($filePath, $filePath.'.bck'); $fd = fopen($filePath, 'w'); + fwrite($fd, ' $value) { - if (false === fwrite($fd, 'define(\''.$name.'\', \''.$this->checkString($value).'\');'."\n")) { + if (false === fwrite($fd, 'define(\''.$name.'\', \''.$this->checkString($value).'\');'.PHP_EOL)) { throw new UpgradeException($this->translator->trans('Error when generating new settings.inc.php file.')); } } - fwrite($fd, '?>'."\n"); fclose($fd); } diff --git a/tests/SettingsFileWriterTest.php b/tests/SettingsFileWriterTest.php new file mode 100644 index 000000000..de0933ba5 --- /dev/null +++ b/tests/SettingsFileWriterTest.php @@ -0,0 +1,86 @@ + + * @copyright 2007-2018 PrestaShop SA + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * International Registered Trademark & Property of PrestaShop SA + */ + +use PHPUnit\Framework\TestCase; + +use PrestaShop\Module\AutoUpgrade\UpgradeTools\SettingsFileWriter; +use PrestaShop\Module\AutoUpgrade\UpgradeContainer; + +class SettingsFileWriterTest extends TestCase +{ + private $container; + private $settingsWriter; + + protected function setUp() + { + parent::setUp(); + $this->container = new UpgradeContainer('/html', '/html/admin'); + $this->settingsWriter = new SettingsFileWriter($this->container->getTranslator()); + } + + public function testSettingsIsProperlyGenerated() + { + $fileExpected = " '127.0.0.1:3307', + '_DB_NAME_' => 'prestashop16', + '_DB_USER_' => 'root', + '_DB_PREFIX_' => 'ps_', + '_MYSQL_ENGINE_' => 'InnoDB', + '_PS_CACHING_SYSTEM_' => 'CacheMemcache', + '_PS_CACHE_ENABLED_' => '0', + '_COOKIE_KEY_' => 'dedeedededede', + '_COOKIE_IV_' => 'wololo', + '_PS_CREATION_DATE_' => '2018-05-16', + '_PS_VERSION_' => '1.6.1.18', + '_RIJNDAEL_KEY_' => 'zrL1GDp2oqDoXFss', + '_RIJNDAEL_IV_' => 'QSt/I95YtA==', + ); + + $file = sys_get_temp_dir().DIRECTORY_SEPARATOR.'temp_settings.php'; + // Create file first + touch($file); + + $this->settingsWriter->writeSettingsFile($file, $datas); + + $this->assertSame($fileExpected, file_get_contents($file)); + } +} From f4cd1202d5acf7395ef9cea9a0cc102b9d9f3b60 Mon Sep 17 00:00:00 2001 From: Thomas Nabord Date: Fri, 29 Jun 2018 14:46:14 +0100 Subject: [PATCH 2/2] Use unique id in temp settings file --- tests/SettingsFileWriterTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/SettingsFileWriterTest.php b/tests/SettingsFileWriterTest.php index de0933ba5..06ede7212 100644 --- a/tests/SettingsFileWriterTest.php +++ b/tests/SettingsFileWriterTest.php @@ -75,10 +75,7 @@ public function testSettingsIsProperlyGenerated() '_RIJNDAEL_IV_' => 'QSt/I95YtA==', ); - $file = sys_get_temp_dir().DIRECTORY_SEPARATOR.'temp_settings.php'; - // Create file first - touch($file); - + $file = tempnam(sys_get_temp_dir(), 'PSS'); $this->settingsWriter->writeSettingsFile($file, $datas); $this->assertSame($fileExpected, file_get_contents($file));