Skip to content

Commit

Permalink
Merge pull request #94 from Quetzacoalt91/settings-generation
Browse files Browse the repository at this point in the history
Fix missing opening <?php in settings file
  • Loading branch information
Quetzacoalt91 authored Jun 29, 2018
2 parents 7445c30 + f4cd120 commit 8162c3d
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 3 deletions.
2 changes: 1 addition & 1 deletion classes/UpgradeTools/CoreUpgrader/CoreUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ protected function runSqlQuery($upgrade_file, $query)
}
}

protected function writeNewSettings()
public function writeNewSettings()
{
// Do nothing
}
Expand Down
3 changes: 3 additions & 0 deletions classes/UpgradeTools/CoreUpgrader/CoreUpgrader16.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

class CoreUpgrader16 extends CoreUpgrader
{
/**
* Generate a new settings file.
*/
public function writeNewSettings()
{
if (!defined('_PS_CACHE_ENABLED_')) {
Expand Down
4 changes: 2 additions & 2 deletions classes/UpgradeTools/SettingsFileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public function writeSettingsFile($filePath, $data)
$filesystem->copy($filePath, $filePath.'.bck');

$fd = fopen($filePath, 'w');
fwrite($fd, '<?php'.PHP_EOL);
foreach ($data as $name => $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);
}

Expand Down
83 changes: 83 additions & 0 deletions tests/SettingsFileWriterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/*
* 2007-2018 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @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 = "<?php
define('_DB_SERVER_', '127.0.0.1:3307');
define('_DB_NAME_', 'prestashop16');
define('_DB_USER_', 'root');
define('_DB_PREFIX_', 'ps_');
define('_MYSQL_ENGINE_', 'InnoDB');
define('_PS_CACHING_SYSTEM_', 'CacheMemcache');
define('_PS_CACHE_ENABLED_', '0');
define('_COOKIE_KEY_', 'dedeedededede');
define('_COOKIE_IV_', 'wololo');
define('_PS_CREATION_DATE_', '2018-05-16');
define('_PS_VERSION_', '1.6.1.18');
define('_RIJNDAEL_KEY_', 'zrL1GDp2oqDoXFss');
define('_RIJNDAEL_IV_', 'QSt/I95YtA==');
";

$datas = array(
'_DB_SERVER_' => '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 = tempnam(sys_get_temp_dir(), 'PSS');
$this->settingsWriter->writeSettingsFile($file, $datas);

$this->assertSame($fileExpected, file_get_contents($file));
}
}

0 comments on commit 8162c3d

Please sign in to comment.