From be7175b8ccc2842933fae08ce312d208d32f376c Mon Sep 17 00:00:00 2001 From: stasiukaitis-saulius Date: Wed, 23 Aug 2017 14:28:04 +0200 Subject: [PATCH] ESDEV-4774 Change updateProductAmountInBasket to changeBasket Rewrite method that it would be driver and theme agnostic. Rename method to match already existing logic etc. addToBasket --- README.rst | 9 ++++-- library/AcceptanceTestCase.php | 56 ++++++++++++++++------------------ 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/README.rst b/README.rst index e9e31742..d4bb842f 100755 --- a/README.rst +++ b/README.rst @@ -353,12 +353,17 @@ Add article to basket: // This will add article with ID 1001 to basket. $this->addToBasket("1001"); -Update items amount in basket: +Update items amount in basket: *(Note that item must be in basket in order to change it)* .. code:: php // This will update article with ID 1001 in basket to have 2 items. - $this->updateProductAmountInBasket("1001", 2); + $this->changeBasket("1001", 2); + +.. code:: php + + // This will remove an item from basket. + $this->changeBasket("1001", 0); Login user in front end side: diff --git a/library/AcceptanceTestCase.php b/library/AcceptanceTestCase.php index 8692bfe4..55af731d 100644 --- a/library/AcceptanceTestCase.php +++ b/library/AcceptanceTestCase.php @@ -421,7 +421,7 @@ public function openArticle($articleId, $clearCache = false, $shopId = null) } /** - * Adds article to basket + * Adds article to basket. * * @param string $articleId Article id * @param int $amount Amount of items to add @@ -451,40 +451,36 @@ public function addToBasket( $this->openNewWindow($this->_getShopUrl($aParams, $shopId), false); } + /** - * Update basket with new amount for the product. - * Add needed amount or 0 to delete item from the basket. + * Change product in basket. * - * @param string $productId oxid of the product. - * @param int $itemsAmount amount of the product. + * @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 */ - public function updateProductAmountInBasket($productId, $itemsAmount) - { - $this->openBasket(); - $this->getHtmlSource(); - - $basket = new \OxidEsales\Eshop\Application\Model\Basket(); - $itemId = $basket->getItemKey($productId); - - // There is a bug in goutte while clicking on button in a form with more than one button: - // only first button is available. In this case the third button is needed. - // Bug is in BrowserKitDriver->click($xpath) where $this->getCrawler()->filterXPath($xpath) is called. - // It returns a form which later on throws an exception. - // This code gets a form and push it without need to click a button. - if ($this->currentMinkDriver === "goutte") { - $updateButton = $this->getElement("//button[@id='basketRemove']"); - $client = $updateButton->getSession()->getDriver()->getClient(); - $updateItemsForm = $client->getCrawler()->filterXPath("//form[@name='basket']")->form(); - $client->submit($updateItemsForm, ['aproducts[' . $itemId . '][am]' => $itemsAmount]); - } else { - $amountInput = $this->getElement("//input[@name='aproducts[$itemId][am]']"); - $amountInput->setValue($itemsAmount); + public function changeBasket( + $articleId, + $amount = 1, + $controller = 'basket', + $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; - $productSelector = $this->getElement("//input[@name='aproducts[$itemId][remove]']"); - $productSelector->check(); + $params = array_merge($params, $additionalParams); - $this->clickAndWait("//button[@id='basketUpdate']"); - } + $this->openNewWindow($this->_getShopUrl($params, $shopId), false); } /**