Skip to content

Commit

Permalink
ESDEV-4774 Makes activateTheme, changeBasket and addToBasket subshop …
Browse files Browse the repository at this point in the history
…compatible

Add shop ID to request URL in order to make changes in needed subshop.
  • Loading branch information
stasiukaitis-saulius committed Aug 28, 2017
1 parent be7175b commit 402d4fe
Showing 1 changed file with 41 additions and 24 deletions.
65 changes: 41 additions & 24 deletions library/AcceptanceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,19 +436,9 @@ public function addToBasket(
$additionalParams = array(),
$shopId = null
) {
$oInput = $this->getElement('stoken', false);
if ($oInput) {
$aParams['stoken'] = $oInput->getValue();
}
$aParams['cl'] = $controller;
$aParams['fnc'] = 'tobasket';
$aParams['aid'] = $articleId;
$aParams['am'] = $amount;
$aParams['anid'] = $articleId;

$aParams = array_merge($aParams, $additionalParams);
$actionName = 'tobasket';

$this->openNewWindow($this->_getShopUrl($aParams, $shopId), false);
$this->callBasketAction($actionName, $articleId, $amount, $controller, $additionalParams, $shopId);
}


Expand All @@ -468,19 +458,9 @@ public function changeBasket(
$additionalParams = array(),
$shopId = null
) {
$input = $this->getElement('stoken', false);
if ($input) {
$params['stoken'] = $input->getValue();
}
$params['cl'] = $controller;
$params['fnc'] = 'changebasket';
$params['aid'] = $articleId;
$params['am'] = $amount;
$params['anid'] = $articleId;
$actionName = 'changebasket';

$params = array_merge($params, $additionalParams);

$this->openNewWindow($this->_getShopUrl($params, $shopId), false);
$this->callBasketAction($actionName, $articleId, $amount, $controller, $additionalParams, $shopId);
}

/**
Expand Down Expand Up @@ -1779,6 +1759,11 @@ public function activateTheme($themeName)
{
$theme = oxNew(Theme::class);
$theme->load($themeName);

$testConfig = new TestConfig();
$shopId = $testConfig->getShopId();
\OxidEsales\Eshop\Core\Registry::getConfig()->setShopId($shopId);

$theme->activate();
}

Expand Down Expand Up @@ -2140,5 +2125,37 @@ private function resetCachedObjects()
\OxidEsales\Eshop\Core\Registry::set(\OxidEsales\Eshop\Core\Language::class, oxNew(\OxidEsales\Eshop\Core\Language::class));
}

/**
* addToBasket and changeBasket has same logic which is extracted.
*
* @param string $actionName addToBasket or changeBasket
* @param string $articleId Article id
* @param int $amount Amount of items to add
* @param string $controller Controller name which should be opened after article is added
* @param array $additionalParams Additional parameters (like persparam[details] for label)
* @param int $shopId Shop id
*/
private function callBasketAction($actionName, $articleId, $amount, $controller, $additionalParams, $shopId = null)
{
if (is_null($shopId)) {
$testConfig = new TestConfig();
$shopId = $testConfig->getShopId();
}

$input = $this->getElement('stoken', false);
if ($input) {
$params['stoken'] = $input->getValue();
}

$params['cl'] = $controller;
$params['fnc'] = $actionName;
$params['aid'] = $articleId;
$params['am'] = $amount;
$params['anid'] = $articleId;

$params = array_merge($params, $additionalParams);

$this->openNewWindow($this->_getShopUrl($params, $shopId), true);
}
}

0 comments on commit 402d4fe

Please sign in to comment.