/** * Clean-up oxarticles table + parent::tearDown() */ protected function tearDown() { $configFile = new ConfigFile(OX_BASE_PATH . 'config.inc.php'); Registry::set('oxConfigFile', $configFile); $this->cleanUpTable('oxarticles'); parent::tearDown(); }
/** * Helper method to set the given currencies. * * @param array $aCurrencies The currencies we want to set. */ protected function _setCurrencies($aCurrencies) { if (!empty($aCurrencies) || is_null($aCurrencies)) { $oConfig = Registry::getConfig(); $oConfig->setConfigParam('aCurrencies', $aCurrencies); } }
/** * Standard set up method. Calls parent first. */ public function setUp() { parent::setUp(); $configFile = Registry::get("oxConfigFile"); $configFile->setVar('sShopDir', realpath(__DIR__ . '/TestData')); Registry::set('oxConfigFile', $configFile); $this->environment = new Environment(); }
/** * Resets template, language and menu xml cache */ public function resetCache() { $aTemplates = $this->getModule()->getTemplates(); $oUtils = Registry::getUtils(); $oUtils->resetTemplateCache($aTemplates); $oUtils->resetLanguageCache(); $oUtils->resetMenuCache(); ModuleVariablesLocator::resetModuleVariables(); $this->_clearApcCache(); }
/** * Testing oxcmp_shop::render() */ public function testRenderNoActiveShop() { $oView = $this->getMock("oxView", array("getClassName")); $oView->expects($this->once())->method('getClassName')->will($this->returnValue("test")); $oShop = oxNew('oxShop'); $oShop->oxshops__oxactive = new oxField(0); $oUtils = $this->getMock('oxUtils', array('showOfflinePage')); $oUtils->expects($this->once())->method('showOfflinePage'); Registry::set('oxUtils', $oUtils); $oConfig = $this->getMock("oxConfig", array("getConfigParam", "getActiveView", "getActiveShop")); $oConfig->expects($this->once())->method('getActiveView')->will($this->returnValue($oView)); $oConfig->expects($this->any())->method('getConfigParam')->will($this->returnValue(false)); $oConfig->expects($this->once())->method('getActiveShop')->will($this->returnValue($oShop)); $oCmp = $this->getMock("oxcmp_shop", array("getConfig", "isAdmin"), array(), '', false); $oCmp->expects($this->once())->method('getConfig')->will($this->returnValue($oConfig)); $oCmp->expects($this->once())->method('isAdmin')->will($this->returnValue(false)); $oCmp->render(); }
protected function createModuleClassFile($extensionPath) { $modulesDirectory = Registry::get("oxConfigFile")->getVar("sShopDir"); $moduleClassFilePath = "{$modulesDirectory}/modules/{$extensionPath}.php"; if (!is_dir(dirname($moduleClassFilePath))) { if (!mkdir(dirname($moduleClassFilePath), 0755, true)) { return false; } } $class = basename($extensionPath); $classDefinition = <<<EOT <?php /** * This file is generated by \\Unit\\Core\\ModuleChainsGeneratorTest::testCreateClassChain and it should have * been deleted after the test run. */ class {$class} extends {$class}_parent {} EOT; if (!file_put_contents($moduleClassFilePath, $classDefinition)) { return false; } return $moduleClassFilePath; }
public function testGetDbThrowsDatabaseNotConfiguredException() { /** @var ConfigFile $configFileBackup Backup of the configFile as stored in Registry. This object must be restored */ $configFileBackup = Registry::get('oxConfigFile'); $configFile = $this->getBlankConfigFile(); $configFile->setVar('dbHost', '<'); Registry::set('oxConfigFile', $configFile); $this->setProtectedClassProperty(oxDb::getInstance(), 'db', null); $this->setExpectedException('OxidEsales\\EshopCommunity\\Core\\Exception\\DatabaseNotConfiguredException'); try { oxDb::getDb(); } catch (DatabaseNotConfiguredException $exception) { /** Restore original configFile object */ Registry::set('oxConfigFile', $configFileBackup); throw $exception; } }
/** * Get a PDO instance representing a connection to the database. * Use this static method to access the database without using the shop adapters. * * @return \PDO PDO instance. */ protected static function getDatabaseHandler() { $configFile = Registry::get('oxConfigFile'); $dsn = 'mysql:host=' . $configFile->getVar('dbHost') . ';dbname=' . $configFile->getVar('dbName'); $username = $configFile->getVar('dbUser'); $password = $configFile->getVar('dbPwd'); $dbh = new \PDO($dsn, $username, $password); return $dbh; }
/** * Redirect to start page and display the error * * @param oxException $ex message to show on exit */ protected function _handleCookieException($ex) { $this->_processSeoCall(); //starting up the session $this->getSession()->start(); // redirect to start page and display the error Registry::get("oxUtilsView")->addErrorToDisplay($ex); Registry::getUtils()->redirect($this->getShopHomeUrl() . 'cl=start', true, 302); }
if (defined('E_DEPRECATED')) { //E_DEPRECATED is disabled particularly for PHP 5.3 as some 3rd party modules still uses deprecated functionality error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED); } else { error_reporting(E_ALL ^ E_NOTICE); } if (!defined('OX_BASE_PATH')) { define('OX_BASE_PATH', __DIR__ . DIRECTORY_SEPARATOR); } // custom functions file if (file_exists(OX_BASE_PATH . 'modules/functions.php')) { include_once OX_BASE_PATH . 'modules/functions.php'; } // Generic utility method file including autoloading definition require_once OX_BASE_PATH . 'oxfunctions.php'; // Make actions if there are eShop configuration problems showErrorIfConfigIsMissing(); redirectIfShopNotConfigured(); // Composer autoloader. registerComposerAutoload(); //init config.inc.php file reader $oConfigFile = new ConfigFile(OX_BASE_PATH . "config.inc.php"); Registry::set("oxConfigFile", $oConfigFile); registerVirtualNamespaceAutoLoad(); registerShopAutoLoad(); registerModuleAutoload(); //sets default PHP ini params ini_set('session.name', 'sid'); ini_set('session.use_cookies', 0); ini_set('session.use_trans_sid', 0); ini_set('url_rewriter.tags', '');
public function testCheckAccessRightsChecksSubshopAdminShop() { $session = Registry::getSession(); $backUpAuth = $session->getVariable("auth"); $exception = null; try { $utils = $this->getMock('OxidEsales\\EshopCommunity\\Core\\Utils', array('fetchRightsForUser', 'fetchShopAdminById')); $utils->expects($this->any())->method('fetchRightsForUser')->will($this->returnValue(1)); $utils->expects($this->any())->method('fetchShopAdminById')->will($this->returnValue(1)); $session->setVariable("auth", "blafooUser"); $this->assertEquals(true, $utils->checkAccessRights()); $this->setRequestParameter('fnc', 'chshp'); $this->assertEquals(false, $utils->checkAccessRights()); $this->setRequestParameter('fnc', null); $this->assertEquals(true, $utils->checkAccessRights()); $this->setRequestParameter('actshop', 1); $this->assertEquals(true, $utils->checkAccessRights()); $this->setRequestParameter('actshop', 2); $this->assertEquals(false, $utils->checkAccessRights()); $this->setRequestParameter('actshop', null); $this->assertEquals(true, $utils->checkAccessRights()); $this->setRequestParameter('shp', 1); $this->assertEquals(true, $utils->checkAccessRights()); $this->setRequestParameter('shp', 2); $this->assertEquals(false, $utils->checkAccessRights()); $this->setRequestParameter('shp', null); $this->assertEquals(true, $utils->checkAccessRights()); $this->setRequestParameter('currentadminshop', 1); $this->assertEquals(true, $utils->checkAccessRights()); $this->setRequestParameter('currentadminshop', 2); $this->assertEquals(false, $utils->checkAccessRights()); $this->setRequestParameter('currentadminshop', null); $this->assertEquals(true, $utils->checkAccessRights()); } catch (Exception $exception) { } $session->setVariable("auth", $backUpAuth); if ($exception) { throw $exception; } }
/** * Get an instance of the config file. * * @throws DatabaseNotConfiguredException * * @return ConfigFile */ protected function fetchConfigFile() { /** * Do the configuration of the database connection parameters */ /** @var ConfigFile $configFile */ $configFile = Registry::get('oxConfigFile'); return $configFile; }
/** * Returns alternative image url * * @param string $sFilePath path to file * @param string $sFile filename in pictures dir * @param bool $blSSL is ssl ? * * @return string */ public function getAltImageUrl($sFilePath, $sFile, $blSSL = null) { $oConfig = $this->getConfig(); $sAltUrl = $oConfig->getConfigParam('sAltImageUrl'); if (!$sAltUrl) { $sAltUrl = $oConfig->getConfigParam('sAltImageDir'); } if ($sAltUrl) { if (is_null($blSSL) && $oConfig->isSsl() || $blSSL) { $sSslAltUrl = $oConfig->getConfigParam('sSSLAltImageUrl'); if (!$sSslAltUrl) { $sSslAltUrl = $oConfig->getConfigParam('sSSLAltImageDir'); } if ($sSslAltUrl) { $sAltUrl = $sSslAltUrl; } } if (!is_null($sFile)) { $sAltUrl = Registry::getUtils()->checkUrlEndingSlash($sAltUrl) . $sFilePath . $sFile; } } return $sAltUrl; }
/** * Checks if main folder matches requested * * @param string $path image path name to check * * @return bool */ protected function _isValidPath($path) { $valid = false; list($width, $height, $quality) = $this->_getImageInfo(); if ($width && $height && $quality) { $config = Registry::getConfig(); $db = oxDb::getDb(oxDb::FETCH_MODE_ASSOC); // parameter names $names = []; foreach ($this->_aConfParamToPath as $paramName => $pathReg) { if (preg_match($pathReg, $path)) { $names[] = $db->quote($paramName); if ($paramName == "sManufacturerIconsize" || $paramName == "sCatIconsize") { $names[] = $db->quote("sIconsize"); } } } $names = implode(', ', $names); // any name matching path? if ($names) { $decodeField = $config->getDecodeValueQuery(); // selecting shop which image quality matches user given $q = "select oxshopid from oxconfig where oxvarname = 'sDefaultImageQuality' and\n {$decodeField} = " . $db->quote($quality); $shopIdsArray = $db->getAll($q); // building query: // shop id $shopIds = implode(', ', array_map(function ($shopId) use($db) { // probably here we can resolve and check shop id to shorten check? return $db->quote($shopId['oxshopid']); }, $shopIdsArray)); // any shop matching quality if ($shopIds) { // $checkSize = "{$width}*{$height}"; // selecting config variables to check $q = "select oxvartype, {$decodeField} as oxvarvalue from oxconfig\n where oxvarname in ( {$names} ) and oxshopid in ( {$shopIds} ) order by oxshopid"; $values = $db->getAll($q); foreach ($values as $value) { $confValues = (array) $config->decodeValue($value["oxvartype"], $value["oxvarvalue"]); foreach ($confValues as $confValue) { if (strcmp($checkSize, $confValue) == 0) { $valid = true; break; } } } } } } return $valid; }
/** * Check for forced edition in config file. If edition is not specified, * determine it by ClassMap existence. * * @return string */ protected function findEdition() { if (!class_exists('OxidEsales\\EshopCommunity\\Core\\Registry') || !Registry::instanceExists('oxConfigFile')) { $configFile = new ConfigFile(getShopBasePath() . "config.inc.php"); } $configFile = isset($configFile) ? $configFile : Registry::get('oxConfigFile'); $edition = $configFile->getVar('edition') ?: $this->findEditionByClassMap(); $configFile->setVar('edition', $edition); return strtoupper($edition); }
/** * Send an offline warning to the shop owner. * Currently an email is sent to the email address configured as 'sAdminEmail' in the eShop config file. * * This method forms part of the exception handling process. Any further exceptions must be caught. * * @param StandardException $exception * * @return bool Returns true, if the email was sent. */ protected function sendOfflineWarning(StandardException $exception) { $result = false; /** @var $emailAddress Email address to sent the message to */ $emailAddress = Registry::get("OxConfigFile")->getVar('sAdminEmail'); if ($emailAddress) { /** As we are inside the exception handling process, any further exceptions must be caught */ try { $failedShop = isset($_REQUEST['shp']) ? addslashes($_REQUEST['shp']) : 'Base shop'; $date = date(DATE_RFC822); // RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000) $script = $_SERVER['SCRIPT_NAME'] . '?' . $_SERVER['QUERY_STRING']; $referrer = $_SERVER['HTTP_REFERER']; //sending a message to admin $emailSubject = 'Offline warning!'; $emailBody = "\n Database connection error in OXID eShop:\n Date: {$date}\n Shop: {$failedShop}\n\n mysql error: " . $exception->getMessage() . "\n mysql error no: " . $exception->getCode() . "\n\n Script: {$script}\n Referrer: {$referrer}"; $mailer = new PHPMailer(); $mailer->isMail(); $mailer->setFrom($emailAddress); $mailer->addAddress($emailAddress); $mailer->Subject = $emailSubject; $mailer->Body = $emailBody; /** Set the priority of the message * For most clients expecting the Priority header: * 1 = High, 2 = Medium, 3 = Low * */ $mailer->Priority = 1; /** MS Outlook custom header */ $mailer->addCustomHeader("X-MSMail-Priority: Urgent"); /** Set the Importance header: */ $mailer->addCustomHeader("Importance: High"); $result = $mailer->send(); } catch (\Exception $exception) { $this->logException($exception); } } return $result; }
public function testCharsetIsUtf8() { $character_set = 'utf8'; $configFile = Registry::get('oxConfigFile'); $this->resetDbProperty(oxDb::getInstance()); $database = oxDb::getInstance(); $database->setConfigFile($configFile); $databaseConnection = $database::getDb(oxDb::FETCH_MODE_ASSOC); $actualResult = $databaseConnection->getRow('SHOW VARIABLES LIKE \'character_set_client\''); $this->assertEquals($character_set, $actualResult['Value'], 'As shop is in utf-8 mode, character_set_client is ' . $character_set); $actualResult = $databaseConnection->getRow('SHOW VARIABLES LIKE \'character_set_results\''); $this->assertEquals($character_set, $actualResult['Value'], 'As shop is in utf-8 mode, character_set_results is ' . $character_set); $actualResult = $databaseConnection->getRow('SHOW VARIABLES LIKE \'character_set_connection\''); $this->assertEquals($character_set, $actualResult['Value'], 'As shop is in utf-8 mode, character_set_client is ' . $character_set); }
/** * Returns request url, which was executed to render current page view * * @param string $sParams Parameters to object * @param bool $blReturnUrl If return url * * @deprecated since v6.0.0 (2016-05-16); Use OxidEsales\EshopCommunity\Core\Request::getRequestUrl(). * * @return string */ function getRequestUrl($sParams = '', $blReturnUrl = false) { return Registry::get(Request::class)->getRequestUrl($sParams, $blReturnUrl); }
public function testInstanceExists() { oxRegistry::set("testKey", "testVal"); $this->assertTrue(Registry::instanceExists('testKey')); oxRegistry::set("testKey", null); $this->assertFalse(Registry::instanceExists('testKey')); }