Skip to content

Commit

Permalink
TE: post review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jocel1 committed Oct 4, 2017
1 parent 5606eb8 commit 71f1c16
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 62 deletions.
2 changes: 1 addition & 1 deletion admin-dev/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
umask(0000); // This will let the permissions be 0775
umask(0000); // This will let the permissions be 0777
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', __DIR__);
}
Expand Down
2 changes: 1 addition & 1 deletion app/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
umask(0000); // This will let the permissions be 0775
umask(0000); // This will let the permissions be 0777

set_time_limit(0);

Expand Down
6 changes: 5 additions & 1 deletion classes/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function __construct(Request $request = null)
}
}

/**
* Reset the request set during the first new Tools($request) call
*/
public static function resetRequest()
{
self::$request = null;
Expand Down Expand Up @@ -2136,7 +2139,8 @@ public static function getMediaServer($filename)
public static function generateHtaccess($path = null, $rewrite_settings = null, $cache_control = null, $specific = '', $disable_multiviews = null, $medias = false, $disable_modsec = null)
{
if (defined('_PS_IN_TEST_')
|| (defined('PS_INSTALLATION_IN_PROGRESS') && $rewrite_settings === null)) {
|| (defined('PS_INSTALLATION_IN_PROGRESS') && $rewrite_settings === null)
) {
return true;
}

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"create-test-db": [
"PrestaShopBundle\\Install\\Install::createTestDB"
"PrestaShopBundle\\Tests\\Utils\\Database::createTestDB"
],
"test-all": [
"composer test",
Expand All @@ -142,22 +142,22 @@
"composer phpunit-controllers"
],
"test": [
"PrestaShopBundle\\Install\\Install::createTestDB",
"PrestaShopBundle\\Tests\\Utils\\Database::createTestDB",
"php -d date.timezone=UTC bin/phpunit -c tests/phpunit.xml"
],
"test-admin": [
"PrestaShopBundle\\Install\\Install::createTestDB",
"PrestaShopBundle\\Tests\\Utils\\Database::createTestDB",
"php -d date.timezone=UTC bin/phpunit -c tests/phpunit-admin.xml"
],
"git-hook-install": "php .github/contrib/install.php",
"git-hook-uninstall": "php .github/contrib/uninstall.php",
"cldr-init": "PrestaShop\\PrestaShop\\Core\\Cldr\\Composer\\Hook::init",
"phpunit-sf": [
"PrestaShopBundle\\Install\\Install::createTestDB",
"PrestaShopBundle\\Tests\\Utils\\Database::createTestDB",
"php -d date.timezone=UTC bin/phpunit -c admin-dev/"
],
"phpunit-controllers": [
"PrestaShopBundle\\Install\\Install::createTestDB",
"PrestaShopBundle\\Tests\\Utils\\Database::createTestDB",
"php -d date.timezone=UTC bin/phpunit -c app/"
]
},
Expand Down
50 changes: 5 additions & 45 deletions src/PrestaShopBundle/Install/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function installDatabase($clear_database = false)
*/
public function generateSf2ProductionEnv()
{
$schemaUpgrade = new UpgradeDatabase(defined('_PS_IN_TEST_')?'test':null);
$schemaUpgrade = new UpgradeDatabase(defined('_PS_IN_TEST_') ? 'test' : null);
$schemaUpgrade->addDoctrineSchemaUpdate();
$output = $schemaUpgrade->execute();

Expand Down Expand Up @@ -356,6 +356,9 @@ public function installCldrDatas()
}
}

/**
* Initialize the prestashop context with default values during tests
*/
public function initializeTestContext()
{
$smarty = null;
Expand Down Expand Up @@ -403,49 +406,6 @@ public function initializeTestContext()
$context->smarty = $smarty;
}

public static function createTestDB() {
define('_PS_IN_TEST_', true);
define('__PS_BASE_URI__', '/');
define('_PS_ROOT_DIR_', __DIR__ . '/../../..');
define('_PS_MODULE_DIR_', _PS_ROOT_DIR_.'/tests/resources/modules/');
require_once(__DIR__.'/../../../install-dev/init.php');

$install = new Install();
\DbPDOCore::createDatabase(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, _DB_NAME_, false);
$install->clearDatabase();
$install->installDatabase();
$install->initializeTestContext();
$install->installDefaultData('test_shop', false, false, true);
$install->populateDatabase();
$install->installCldrDatas();

$install->configureShop(array(
'admin_firstname' => 'puff',
'admin_lastname' => 'daddy',
'admin_password' => 'test',
'admin_email' => '[email protected]',
'configuration_agrement' => true,
'send_informations' => false,
));
$install->installFixtures();
$install->installTheme();
$language = new \Language(1);
Context::getContext()->language = $language;
$install->installModules();
$install->installModulesAddons();

DatabaseDump::create();
}

public static function restoreTestDB()
{
if (!file_exists(sys_get_temp_dir().'/'.'ps_dump.sql')) {
throw new DBALException('You need to run \'composer create-test-db\' to create the initial test database');
}

DatabaseDump::restoreDb();
}

/**
* PROCESS : installDefaultData
* Create default shop and languages
Expand Down Expand Up @@ -476,7 +436,7 @@ public function installDefaultData($shop_name, $iso_country = false, $all_langua
}
}
}
$iso_codes_to_install = array_flip(array_flip($iso_codes_to_install));
$iso_codes_to_install = array_unique($iso_codes_to_install);
} else {
$iso_codes_to_install = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/PrestaShopBundle/Tests/DatabaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@

namespace PrestaShop\PrestaShop\Tests\TestCase;
use PHPUnit_Framework_TestCase;
use PrestaShopBundle\Install\Install;
use PrestaShopBundle\Tests\Utils\Database;

abstract class DatabaseTestCase extends PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
Install::restoreTestDB();
Database::restoreTestDB();
}
}
86 changes: 86 additions & 0 deletions src/PrestaShopBundle/Tests/Utils/Database.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
* 2007-2017 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:
* https://opensource.org/licenses/OSL-3.0
* 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-2017 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/

namespace PrestaShopBundle\Tests\Utils;

use Doctrine\DBAL\DBALException;
use PrestaShopBundle\Install\DatabaseDump;
use PrestaShopBundle\Install\Install;

class Database
{
/**
* Create the initialize database used for test
*/
public static function createTestDB()
{
define('_PS_IN_TEST_', true);
define('__PS_BASE_URI__', '/');
define('_PS_ROOT_DIR_', __DIR__ . '/../../../../');
define('_PS_MODULE_DIR_', _PS_ROOT_DIR_ . '/tests/resources/modules/');
require_once(__DIR__ . '/../../../../install-dev/init.php');

$install = new Install();
\DbPDOCore::createDatabase(_DB_SERVER_, _DB_USER_, _DB_PASSWD_, _DB_NAME_, false);
$install->clearDatabase();
$install->installDatabase();
$install->initializeTestContext();
$install->installDefaultData('test_shop', false, false, true);
$install->populateDatabase();
$install->installCldrDatas();

$install->configureShop(array(
'admin_firstname' => 'puff',
'admin_lastname' => 'daddy',
'admin_password' => 'test',
'admin_email' => '[email protected]',
'configuration_agrement' => true,
'send_informations' => false,
));
$install->installFixtures();
$install->installTheme();
$language = new \Language(1);
\Context::getContext()->language = $language;
$install->installModules();
$install->installModulesAddons();

DatabaseDump::create();
}

/**
* Restore the test database in its initial state from a dump generated during createTestDB
*
* @throws DBALException
*/
public static function restoreTestDB()
{
if (!file_exists(sys_get_temp_dir() . '/' . 'ps_dump.sql')) {
throw new DBALException('You need to run \'composer create-test-db\' to create the initial test database');
}

DatabaseDump::restoreDb();
}
}
4 changes: 2 additions & 2 deletions tests/Integration/PrestaShopBundle/Test/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

namespace PrestaShop\PrestaShop\Tests\Integration\PrestaShopBundle\Test;

use PrestaShopBundle\Install\Install;
use PrestaShopBundle\Tests\Utils\Database;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as TestCase;

Expand All @@ -49,7 +49,7 @@ class WebTestCase extends TestCase

public static function setUpBeforeClass()
{
Install::restoreTestDB();
Database::restoreTestDB();
}

public function setUp()
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/classes/CartGetOrderTotalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use Db;
use Group;
use Order;
use PrestaShopBundle\Install\Install;
use PrestaShopBundle\Tests\Utils\Database;
use Product;
use Tools;
use Tax;
Expand All @@ -56,7 +56,7 @@ public static function setUpBeforeClass()
{
parent::setUpBeforeClass();

Install::restoreTestDB();
Database::restoreTestDB();

// Some tests might have cleared the configuration
Configuration::loadConfiguration();
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

namespace PrestaShop\PrestaShop\Tests\TestCase;
use PHPUnit_Framework_TestCase;
use PrestaShopBundle\Install\Install;
use PrestaShopBundle\Tests\Utils\Database;

class IntegrationTestCase extends PHPUnit_Framework_TestCase
{
public static function setUpBeforeClass()
{
Install::restoreTestDB();
Database::restoreTestDB();
require_once(__DIR__ . '/../../config/config.inc.php');
}
}
2 changes: 1 addition & 1 deletion tests/bootstrap-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
define('_PS_ROOT_DIR_', __DIR__ . '/..');
define('_PS_IN_TEST_', true);
umask(0000); // This will let the permissions be 0775
umask(0000); // This will let the permissions be 0777
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', __DIR__."/admin-dev");
}
Expand Down

0 comments on commit 71f1c16

Please sign in to comment.