diff --git a/admin-dev/bootstrap.php b/admin-dev/bootstrap.php index 5240db2ef3ccf..e5b8eba63c3ba 100644 --- a/admin-dev/bootstrap.php +++ b/admin-dev/bootstrap.php @@ -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__); } diff --git a/app/console b/app/console index b4f8c25b4836a..a93e9ae30ec24 100755 --- a/app/console +++ b/app/console @@ -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); diff --git a/classes/Tools.php b/classes/Tools.php index 4bcdc49f17610..c73be276293cd 100644 --- a/classes/Tools.php +++ b/classes/Tools.php @@ -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; @@ -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; } diff --git a/composer.json b/composer.json index 1919623a000cd..121b75eaca861 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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/" ] }, diff --git a/src/PrestaShopBundle/Install/Install.php b/src/PrestaShopBundle/Install/Install.php index b36dd9a85ddd6..1b56f00b0decf 100644 --- a/src/PrestaShopBundle/Install/Install.php +++ b/src/PrestaShopBundle/Install/Install.php @@ -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(); @@ -356,6 +356,9 @@ public function installCldrDatas() } } + /** + * Initialize the prestashop context with default values during tests + */ public function initializeTestContext() { $smarty = null; @@ -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' => 'test@prestashop.com', - '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 @@ -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; } diff --git a/src/PrestaShopBundle/Tests/DatabaseTestCase.php b/src/PrestaShopBundle/Tests/DatabaseTestCase.php index 244e8c94c6644..66605a5e12533 100644 --- a/src/PrestaShopBundle/Tests/DatabaseTestCase.php +++ b/src/PrestaShopBundle/Tests/DatabaseTestCase.php @@ -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(); } } diff --git a/src/PrestaShopBundle/Tests/Utils/Database.php b/src/PrestaShopBundle/Tests/Utils/Database.php new file mode 100644 index 0000000000000..9bce13b2256ea --- /dev/null +++ b/src/PrestaShopBundle/Tests/Utils/Database.php @@ -0,0 +1,86 @@ + + * @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' => 'test@prestashop.com', + '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(); + } +} \ No newline at end of file diff --git a/tests/Integration/PrestaShopBundle/Test/WebTestCase.php b/tests/Integration/PrestaShopBundle/Test/WebTestCase.php index 09e87b7f873d7..8fc8239ea3283 100644 --- a/tests/Integration/PrestaShopBundle/Test/WebTestCase.php +++ b/tests/Integration/PrestaShopBundle/Test/WebTestCase.php @@ -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; @@ -49,7 +49,7 @@ class WebTestCase extends TestCase public static function setUpBeforeClass() { - Install::restoreTestDB(); + Database::restoreTestDB(); } public function setUp() diff --git a/tests/Integration/classes/CartGetOrderTotalTest.php b/tests/Integration/classes/CartGetOrderTotalTest.php index 9b05522cbbde4..5fbf7738ef4f1 100644 --- a/tests/Integration/classes/CartGetOrderTotalTest.php +++ b/tests/Integration/classes/CartGetOrderTotalTest.php @@ -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; @@ -56,7 +56,7 @@ public static function setUpBeforeClass() { parent::setUpBeforeClass(); - Install::restoreTestDB(); + Database::restoreTestDB(); // Some tests might have cleared the configuration Configuration::loadConfiguration(); diff --git a/tests/TestCase/IntegrationTestCase.php b/tests/TestCase/IntegrationTestCase.php index c954d9fa51c37..addf9b8398e32 100644 --- a/tests/TestCase/IntegrationTestCase.php +++ b/tests/TestCase/IntegrationTestCase.php @@ -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'); } } diff --git a/tests/bootstrap-admin.php b/tests/bootstrap-admin.php index b67a908c2af89..19c52287a3369 100644 --- a/tests/bootstrap-admin.php +++ b/tests/bootstrap-admin.php @@ -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"); }