Skip to content

Commit 402d4fe

Browse files
author
stasiukaitis-saulius
committed
ESDEV-4774 Makes activateTheme, changeBasket and addToBasket subshop compatible
Add shop ID to request URL in order to make changes in needed subshop.
1 parent be7175b commit 402d4fe

1 file changed

Lines changed: 41 additions & 24 deletions

File tree

library/AcceptanceTestCase.php

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,9 @@ public function addToBasket(
436436
$additionalParams = array(),
437437
$shopId = null
438438
) {
439-
$oInput = $this->getElement('stoken', false);
440-
if ($oInput) {
441-
$aParams['stoken'] = $oInput->getValue();
442-
}
443-
$aParams['cl'] = $controller;
444-
$aParams['fnc'] = 'tobasket';
445-
$aParams['aid'] = $articleId;
446-
$aParams['am'] = $amount;
447-
$aParams['anid'] = $articleId;
448-
449-
$aParams = array_merge($aParams, $additionalParams);
439+
$actionName = 'tobasket';
450440

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

454444

@@ -468,19 +458,9 @@ public function changeBasket(
468458
$additionalParams = array(),
469459
$shopId = null
470460
) {
471-
$input = $this->getElement('stoken', false);
472-
if ($input) {
473-
$params['stoken'] = $input->getValue();
474-
}
475-
$params['cl'] = $controller;
476-
$params['fnc'] = 'changebasket';
477-
$params['aid'] = $articleId;
478-
$params['am'] = $amount;
479-
$params['anid'] = $articleId;
461+
$actionName = 'changebasket';
480462

481-
$params = array_merge($params, $additionalParams);
482-
483-
$this->openNewWindow($this->_getShopUrl($params, $shopId), false);
463+
$this->callBasketAction($actionName, $articleId, $amount, $controller, $additionalParams, $shopId);
484464
}
485465

486466
/**
@@ -1779,6 +1759,11 @@ public function activateTheme($themeName)
17791759
{
17801760
$theme = oxNew(Theme::class);
17811761
$theme->load($themeName);
1762+
1763+
$testConfig = new TestConfig();
1764+
$shopId = $testConfig->getShopId();
1765+
\OxidEsales\Eshop\Core\Registry::getConfig()->setShopId($shopId);
1766+
17821767
$theme->activate();
17831768
}
17841769

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

2128+
/**
2129+
* addToBasket and changeBasket has same logic which is extracted.
2130+
*
2131+
* @param string $actionName addToBasket or changeBasket
2132+
* @param string $articleId Article id
2133+
* @param int $amount Amount of items to add
2134+
* @param string $controller Controller name which should be opened after article is added
2135+
* @param array $additionalParams Additional parameters (like persparam[details] for label)
2136+
* @param int $shopId Shop id
2137+
*/
2138+
private function callBasketAction($actionName, $articleId, $amount, $controller, $additionalParams, $shopId = null)
2139+
{
2140+
if (is_null($shopId)) {
2141+
$testConfig = new TestConfig();
2142+
$shopId = $testConfig->getShopId();
2143+
}
2144+
2145+
$input = $this->getElement('stoken', false);
2146+
if ($input) {
2147+
$params['stoken'] = $input->getValue();
2148+
}
2149+
2150+
$params['cl'] = $controller;
2151+
$params['fnc'] = $actionName;
2152+
$params['aid'] = $articleId;
2153+
$params['am'] = $amount;
2154+
$params['anid'] = $articleId;
2155+
2156+
$params = array_merge($params, $additionalParams);
2157+
2158+
$this->openNewWindow($this->_getShopUrl($params, $shopId), true);
2159+
}
21432160
}
21442161

0 commit comments

Comments
 (0)