diff options
author | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-08-18 21:14:58 -0500 |
commit | 2eed7b082f83630301e51f57ca8394de228a8605 (patch) | |
tree | 1d19962d22d30f99317d9276e4bae7744fc93fc2 /tests/setup | |
download | librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.lz librecart-2eed7b082f83630301e51f57ca8394de228a8605.tar.xz librecart-2eed7b082f83630301e51f57ca8394de228a8605.zip |
first commit
Diffstat (limited to 'tests/setup')
-rw-r--r-- | tests/setup/config.php | 41 | ||||
-rw-r--r-- | tests/setup/install.php | 136 |
2 files changed, 177 insertions, 0 deletions
diff --git a/tests/setup/config.php b/tests/setup/config.php new file mode 100644 index 0000000..b148f42 --- /dev/null +++ b/tests/setup/config.php @@ -0,0 +1,41 @@ +<?php +define('VERSION', '2.3.0.3_rc'); +define('ADMIN_USERNAME', ''); +define('ADMIN_PASSWORD', ''); + +/* + * Use the $settings array to change store settings. The key must match the store ID. + */ +$settings = array( + 0 => array( + 'config_maintenance' => 1, + ) +); + +/* + * Use the $module_settings array to install payment, shipping or feed modules + */ +$module_settings = array( + 'payment' => array( + 'cheque' => array( + 'cheque_status' => 1, + 'cheque_payable' => 'OpenCart test store', + 'cheque_order_status_id' => 1, + ), + 'free_checkout' => array( + 'free_checkout_status' => 1, + 'free_checkout_order_status_id' => 1, + ), + ), + 'shipping' => array( + 'item' => array( + 'item_status' => 1, + 'item_cost' => 1.25, + ), + ), + 'feed' => array( + 'google_sitemap' => array( + 'google_sitemap_status' => 1 + ) + ), +); diff --git a/tests/setup/install.php b/tests/setup/install.php new file mode 100644 index 0000000..c797739 --- /dev/null +++ b/tests/setup/install.php @@ -0,0 +1,136 @@ +<?php +/** + * Demo install file allows for config and module settings to be set-up using a single setup file. + * + * Designed to be used with build automation services like Jenkins to save time with demo installation sites, no need + * for admin to login to the store and update settings or installing modules manually for each test build. + * + * @todo support for modules & order totals + * @todo create front end demo user account from config (or re-use current selenium test account) + */ + +// Version +define('CONFIG_ADMIN', __DIR__ . '/../../upload/admin/config.php'); +require('./config.php'); + +require(CONFIG_ADMIN); +require(DIR_SYSTEM . 'library/db.php'); +require(DIR_SYSTEM . 'library/db/' . DB_DRIVER . '.php'); + +$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT); + +/** + * Store settings configuration + */ +foreach ($settings as $store_id => $store_settings) { + $query = $db->query("SELECT * FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "'"); + + $old_store_config = array(); + + foreach ($query->rows as $result) { + if ($result['serialized'] == 1) { + $old_store_config[$result['key']] = json_decode($result['value']); + } else { + $old_store_config[$result['key']] = $result['value']; + + } + } + + $new_store_config = array_merge($old_store_config, $store_settings); + + editSetting('config', $new_store_config, $store_id); +} + +// Startup +require_once(DIR_SYSTEM . 'startup.php'); + +// Registry +$registry = new Registry(); + +// Loader +$loader = new Loader($registry); +$registry->set('load', $loader); + +// Request +$request = new Request(); +$registry->set('request', $request); + +// Cache +$cache = new Cache('file'); +$registry->set('cache', $cache); + +// Session +$session = new Session(); +$registry->set('session', $session); + +// Config +$config = new Config(); +$registry->set('config', $config); + +// Database +$registry->set('db', $db); + +// User +$user = new Cart\User($registry); +$user->login(ADMIN_USERNAME, ADMIN_PASSWORD); + +$registry->set('user', $user); + +foreach ($module_settings as $module_settings_type => $module_settings_data) { + $installed_extensions = getInstalledExtension($module_settings_type); + + foreach ($installed_extensions as $remove_extension) { + $loader->controller($module_settings_type . '/' . $remove_extension . '/uninstall'); + deleteSetting($store_id, $remove_extension); + } + + $db->query("DELETE FROM " . DB_PREFIX . "extension WHERE `type` = '" . $db->escape($module_settings_type) . "' AND `code` = '" . $db->escape($remove_extension) . "'"); + + foreach ($module_settings_data as $module_key => $module_data) { + $db->query("INSERT INTO " . DB_PREFIX . "extension SET `type` = '" . $db->escape($module_settings_type) . "', `code` = '" . $db->escape($module_key) . "'"); + + $loader->model('user/user_group'); + + $loader->controller($module_settings_type . '/' . $module_key . '/install'); + + editSetting($module_key, $module_data); + } +} + +echo "Setting update completed\r\n"; + +function deleteSetting($store_id, $code) { + global $db; + + $db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $db->escape($code) . "'"); +} + +function editSetting($code, $data, $store_id = 0) { + global $db; + + $db->query("DELETE FROM `" . DB_PREFIX . "setting` WHERE store_id = '" . (int)$store_id . "' AND `code` = '" . $db->escape($code) . "'"); + + foreach ($data as $key => $value) { + if (substr($key, 0, strlen($code)) == $code) { + if (!is_array($value)) { + $db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $db->escape($code) . "', `key` = '" . $db->escape($key) . "', `value` = '" . $db->escape($value) . "'"); + } else { + $db->query("INSERT INTO " . DB_PREFIX . "setting SET store_id = '" . (int)$store_id . "', `code` = '" . $db->escape($code) . "', `key` = '" . $db->escape($key) . "', `value` = '" . $db->escape(json_encode($value)) . "', serialized = '1'"); + } + } + } +} + +function getInstalledExtension($type) { + global $db; + + $extension_data = array(); + + $query = $db->query("SELECT * FROM " . DB_PREFIX . "extension WHERE `type` = '" . $db->escape($type) . "' ORDER BY code"); + + foreach ($query->rows as $result) { + $extension_data[] = $result['code']; + } + + return $extension_data; +}
\ No newline at end of file |