Skip to content

Commit 41815bd

Browse files
committed
Merge branch 'MC-37263' into 2.4-develop-com-pr16
2 parents 740737a + 05d185d commit 41815bd

File tree

7 files changed

+530
-58
lines changed

7 files changed

+530
-58
lines changed

dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQlAbstract.php

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -184,61 +184,4 @@ protected function assertResponseFields($actualResponse, $assertionMap)
184184
);
185185
}
186186
}
187-
188-
/**
189-
* Compare arrays recursively regardless of nesting.
190-
*
191-
* Can compare arrays that have both one level and n-level nesting.
192-
* ```
193-
* [
194-
* 'products' => [
195-
* 'items' => [
196-
* [
197-
* 'sku' => 'bundle-product',
198-
* 'type_id' => 'bundle',
199-
* 'items' => [
200-
* [
201-
* 'title' => 'Bundle Product Items',
202-
* 'sku' => 'bundle-product',
203-
* 'options' => [
204-
* [
205-
* 'price' => 2.75,
206-
* 'label' => 'Simple Product',
207-
* 'product' => [
208-
* 'name' => 'Simple Product',
209-
* 'sku' => 'simple',
210-
* ]
211-
* ]
212-
* ]
213-
* ]
214-
* ];
215-
* ```
216-
*
217-
* @param array $expected
218-
* @param array $actual
219-
* @return array
220-
*/
221-
public function compareArraysRecursively(array $expected, array $actual): array
222-
{
223-
$diffResult = [];
224-
225-
foreach ($expected as $key => $value) {
226-
if (array_key_exists($key, $actual)) {
227-
if (is_array($value)) {
228-
$recursiveDiff = $this->compareArraysRecursively($value, $actual[$key]);
229-
if (!empty($recursiveDiff)) {
230-
$diffResult[$key] = $recursiveDiff;
231-
}
232-
} else {
233-
if (!in_array($value, $actual, true)) {
234-
$diffResult[$key] = $value;
235-
}
236-
}
237-
} else {
238-
$diffResult[$key] = $value;
239-
}
240-
}
241-
242-
return $diffResult;
243-
}
244187
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/BundleProductMultipleOptionsTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@
77

88
namespace Magento\GraphQl\Bundle;
99

10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use Magento\TestFramework\Helper\CompareArraysRecursively;
1012
use Magento\TestFramework\TestCase\GraphQlAbstract;
1113

1214
/**
1315
* Bundle product with multiple options test.
1416
*/
1517
class BundleProductMultipleOptionsTest extends GraphQlAbstract
1618
{
19+
/**
20+
* @var CompareArraysRecursively
21+
*/
22+
private $compareArraysRecursively;
23+
24+
/**
25+
* @inheritDoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$objectManager = Bootstrap::getObjectManager();
30+
$this->compareArraysRecursively = $objectManager->create(CompareArraysRecursively::class);
31+
}
32+
1733
/**
1834
* @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options.php
1935
* @param array $bundleProductDataProvider
@@ -85,7 +101,7 @@ private function assertBundleProduct(array $response, array $bundleProductDataPr
85101
$productItems = $response['products']['items'];
86102

87103
foreach ($bundleProductDataProvider as $key => $data) {
88-
$diff = $this->compareArraysRecursively($data, $productItems[$key]);
104+
$diff = $this->compareArraysRecursively->execute($data, $productItems[$key]);
89105
self::assertEquals([], $diff, "Actual response doesn't equal to expected data");
90106
}
91107
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\ProductRepositoryInterface;
9+
use Magento\Checkout\Model\Type\Onepage;
10+
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
use Magento\Quote\Api\Data\CartInterface;
13+
use Magento\Quote\Api\Data\CartInterfaceFactory;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
16+
17+
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer.php');
18+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/taxable_simple_product.php');
19+
20+
$objectManager = Bootstrap::getObjectManager();
21+
/** @var ProductRepositoryInterface $productRepository */
22+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
23+
$productRepository->cleanCache();
24+
/** @var CartRepositoryInterface $quoteRepository */
25+
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
26+
/** @var CustomerRepositoryInterface $customerRepository */
27+
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
28+
$customer = $customerRepository->get('customer@example.com');
29+
30+
/** @var CartInterface $quote */
31+
$quote = $objectManager->get(CartInterfaceFactory::class)->create();
32+
$quote->setStoreId(1)
33+
->setIsActive(false)
34+
->setIsMultiShipping(0)
35+
->setCustomer($customer)
36+
->setCheckoutMethod(Onepage::METHOD_CUSTOMER)
37+
->setReservedOrderId('test_order_with_customer_inactive_quote')
38+
->addProduct($productRepository->get('taxable_product'), 1);
39+
$quoteRepository->save($quote);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Quote\Api\CartRepositoryInterface;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
11+
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
12+
13+
$objectManager = Bootstrap::getObjectManager();
14+
/** @var CartRepositoryInterface $quoteRepository */
15+
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
16+
/** @var GetQuoteByReservedOrderId $getQuoteByReservedOrderId */
17+
$getQuoteByReservedOrderId = $objectManager->get(GetQuoteByReservedOrderId::class);
18+
$quote = $getQuoteByReservedOrderId->execute('test_order_with_customer_inactive_quote');
19+
if ($quote !== null) {
20+
$quoteRepository->delete($quote);
21+
}
22+
23+
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/taxable_simple_product_rollback.php');
24+
Resolver::getInstance()->requireDataFixture('Magento/Customer/_files/customer_rollback.php');
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Block\Adminhtml\Order\Create\Items;
9+
10+
use Magento\Backend\Model\Session\Quote;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\Sales\Block\Adminhtml\Order\Create\Items;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
16+
use PHPUnit\Framework\TestCase;
17+
18+
/**
19+
* Checks order items grid
20+
*
21+
* @magentoAppArea adminhtml
22+
* @magentoDbIsolation enabled
23+
*/
24+
class GridTest extends TestCase
25+
{
26+
/** @var ObjectManagerInterface */
27+
private $objectManager;
28+
29+
/** @var LayoutInterface */
30+
private $layout;
31+
32+
/** @var Grid */
33+
private $block;
34+
35+
/** @var Quote */
36+
private $session;
37+
38+
/** @var GetQuoteByReservedOrderId */
39+
private $getQuoteByReservedOrderId;
40+
41+
/**
42+
* @inheritdoc
43+
*/
44+
protected function setUp(): void
45+
{
46+
parent::setUp();
47+
48+
$this->objectManager = Bootstrap::getObjectManager();
49+
$this->getQuoteByReservedOrderId = $this->objectManager->get(GetQuoteByReservedOrderId::class);
50+
$this->session = $this->objectManager->get(Quote::class);
51+
$this->layout = $this->objectManager->get(LayoutInterface::class);
52+
$this->block = $this->layout->createBlock(Grid::class);
53+
$this->layout->createBlock(Items::class)->setChild('items_grid', $this->block);
54+
}
55+
56+
/**
57+
* @magentoDataFixture Magento/Checkout/_files/quote_with_customer_without_address.php
58+
*
59+
* @return void
60+
*/
61+
public function testGetItems(): void
62+
{
63+
$quote = $this->getQuoteByReservedOrderId->execute('test_order_with_customer_without_address');
64+
$this->session->setQuoteId($quote->getId());
65+
$items = $this->block->getItems();
66+
$this->assertCount(1, $items);
67+
$this->assertEquals('simple2', reset($items)->getSku());
68+
}
69+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Block\Adminhtml\Order\Create\Sidebar;
9+
10+
use Magento\Backend\Model\Session\Quote;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Check sidebar shopping cart section block
18+
*
19+
* @see \Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\Cart
20+
*
21+
* @magentoAppArea adminhtml
22+
* @magentoDbIsolation enabled
23+
*/
24+
class CartTest extends TestCase
25+
{
26+
/** @var ObjectManagerInterface */
27+
private $objectManager;
28+
29+
/** @var Cart */
30+
private $block;
31+
32+
/** @var Quote */
33+
private $session;
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
protected function setUp(): void
39+
{
40+
parent::setUp();
41+
42+
$this->objectManager = Bootstrap::getObjectManager();
43+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Cart::class);
44+
$this->session = $this->objectManager->get(Quote::class);
45+
}
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function tearDown(): void
51+
{
52+
$this->session->clearStorage();
53+
54+
parent::tearDown();
55+
}
56+
57+
/**
58+
* @magentoDataFixture Magento/Checkout/_files/quote_with_customer_without_address.php
59+
*
60+
* @return void
61+
*/
62+
public function testGetItemCollection(): void
63+
{
64+
$this->session->setCustomerId(1);
65+
$items = $this->block->getItemCollection();
66+
$this->assertCount(1, $items);
67+
$this->assertEquals('simple2', reset($items)->getSku());
68+
}
69+
70+
/**
71+
* @return void
72+
*/
73+
public function testClearShoppingCartButton(): void
74+
{
75+
$confirmation = __('Are you sure you want to delete all items from shopping cart?');
76+
$button = $this->block->getChildBlock('empty_customer_cart_button');
77+
$this->assertEquals(sprintf("order.clearShoppingCart('%s')", $confirmation), $button->getOnclick());
78+
$this->assertEquals(__('Clear Shopping Cart'), $button->getLabel());
79+
}
80+
}

0 commit comments

Comments
 (0)