Skip to content

Commit da7da66

Browse files
committed
MC-19255: API functional tests to cover cart promotions
- fixed fixture to remove entities properly
1 parent be238ea commit da7da66

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/CartPromotionsTest.php

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Catalog\Api\CategoryLinkManagementInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Model\Product;
13-
use Magento\Catalog\Model\Product\Visibility;
1413
use Magento\SalesRule\Model\ResourceModel\Rule\Collection;
1514
use Magento\SalesRule\Model\Rule;
1615
use Magento\TestFramework\Helper\Bootstrap;
@@ -31,16 +30,13 @@ class CartPromotionsTest extends GraphQlAbstract
3130
*/
3231
public function testCartPromotionSingleCartRule()
3332
{
33+
$skus =['simple1', 'simple2'];
3434
$objectManager = Bootstrap::getObjectManager();
3535
/** @var ProductRepositoryInterface $productRepository */
3636
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
3737
/** @var Product $prod2 */
3838
$prod1 = $productRepository->get('simple1');
3939
$prod2 = $productRepository->get('simple2');
40-
$productsInCart = [$prod1, $prod2];
41-
$prod2->setVisibility(Visibility::VISIBILITY_BOTH);
42-
$productRepository->save($prod2);
43-
$skus =['simple1', 'simple2'];
4440
$categoryId = 66;
4541
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
4642
$categoryLinkManagement = $objectManager->create(CategoryLinkManagementInterface::class);
@@ -63,6 +59,7 @@ public function testCartPromotionSingleCartRule()
6359
$query = $this->getCartItemPricesQuery($cartId);
6460
$response = $this->graphQlMutation($query);
6561
$this->assertCount(2, $response['cart']['items']);
62+
$productsInCart = [$prod1, $prod2];
6663
//validating the line item prices, quantity and discount
6764
$this->assertLineItemDiscountPrices($response, $productsInCart, $qty, $ruleLabels);
6865
//total discount on the cart which is the sum of the individual row discounts
@@ -105,7 +102,7 @@ private function assertLineItemDiscountPrices($response, $productsInCart, $qty,
105102
}
106103

107104
/**
108-
* Test applying multiple cart rules to multiple products in a cart
105+
* Apply multiple cart rules to multiple products in a cart
109106
*
110107
* @magentoApiDataFixture Magento/Catalog/_files/multiple_products.php
111108
* @magentoApiDataFixture Magento/SalesRule/_files/rules_category.php
@@ -120,8 +117,6 @@ public function testCartPromotionsMultipleCartRules()
120117
$prod1 = $productRepository->get('simple1');
121118
$prod2 = $productRepository->get('simple2');
122119
$productsInCart = [$prod1, $prod2];
123-
$prod2->setVisibility(Visibility::VISIBILITY_BOTH);
124-
$productRepository->save($prod2);
125120
$skus =['simple1', 'simple2'];
126121
$categoryId = 66;
127122
/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */
@@ -188,8 +183,8 @@ public function testCartPromotionsMultipleCartRules()
188183
}
189184

190185
/**
191-
* Test applying single cart rules to multiple products in a cart with tax settings
192-
* Tax settings are : Including and Excluding tax for Price Display and Shopping cart display settings
186+
* Apply cart rules to multiple products in a cart with taxes
187+
* Tax settings : Including and Excluding tax for Price Display and Shopping cart display
193188
* Discount on Prices Includes Tax
194189
* Tax rate = 7.5%
195190
* Cart rule to apply 50% for products assigned to a specific category
@@ -287,8 +282,7 @@ public function testCartPromotionsWithCoupons()
287282
$prod1 = $productRepository->get('simple1');
288283
$prod2 = $productRepository->get('simple2');
289284
$productsInCart = [$prod1, $prod2];
290-
$prod2->setVisibility(Visibility::VISIBILITY_BOTH);
291-
$productRepository->save($prod2);
285+
292286
$skus =['simple1', 'simple2'];
293287

294288
/** @var Collection $ruleCollection */
@@ -343,14 +337,6 @@ public function testCartPromotionsWithCoupons()
343337
*/
344338
public function testCartPromotionsWhenNoDiscountIsAvailable()
345339
{
346-
$objectManager = Bootstrap::getObjectManager();
347-
/** @var ProductRepositoryInterface $productRepository */
348-
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
349-
/** @var Product $prod2 */
350-
$prod1 = $productRepository->get('simple1');
351-
$prod2 = $productRepository->get('simple2');
352-
$prod2->setVisibility(Visibility::VISIBILITY_BOTH);
353-
$productRepository->save($prod2);
354340
$skus =['simple1', 'simple2'];
355341
$qty = 2;
356342
$cartId = $this->createEmptyCart();

dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_category.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
)->setParentId(
7676
2
7777
)->setPath(
78-
'1/2/333'
78+
'1/2/66'
7979
)->setLevel(
8080
2
8181
)->setAvailableSortBy(

dev/tests/integration/testsuite/Magento/SalesRule/_files/rules_category_rollback.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,16 @@
1111
$rule = $registry->registry('_fixture/Magento_SalesRule_Category');
1212

1313
$rule->delete();
14+
15+
$registry->unregister('isSecureArea');
16+
$registry->register('isSecureArea', true);
17+
18+
/** @var $category \Magento\Catalog\Model\Category */
19+
$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
20+
$category->load(66);
21+
if ($category->getId()) {
22+
$category->delete();
23+
}
24+
25+
$registry->unregister('isSecureArea');
26+
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)