Skip to content

Commit 18ac426

Browse files
committed
Merge remote-tracking branch 'origin/MC-33388' into 2.4-develop-com-pr12
2 parents b045791 + ce246cb commit 18ac426

File tree

2 files changed

+229
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Customer

2 files changed

+229
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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\Customer\Block\Adminhtml\Edit\Tab\View;
9+
10+
use Magento\Customer\Controller\RegistryConstants;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\Registry;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Tests for customer wish list tab.
19+
*
20+
* @magentoAppArea adminhtml
21+
* @magentoDbIsolation enabled
22+
*/
23+
class WishlistTest extends TestCase
24+
{
25+
/** @var ObjectManagerInterface */
26+
private $objectManager;
27+
28+
/** @var Registry */
29+
private $registry;
30+
31+
/** @var Wishlist */
32+
private $block;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp(): void
38+
{
39+
parent::setUp();
40+
41+
$this->objectManager = Bootstrap::getObjectManager();
42+
$this->registry = $this->objectManager->get(Registry::class);
43+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Wishlist::class);
44+
}
45+
46+
/**
47+
* @inheritdoc
48+
*/
49+
protected function tearDown(): void
50+
{
51+
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
52+
53+
parent::tearDown();
54+
}
55+
56+
/**
57+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
58+
*
59+
* @return void
60+
*/
61+
public function testWishListGrid(): void
62+
{
63+
$this->registerCustomerId(1);
64+
$this->assertCount(1, $this->block->getPreparedCollection());
65+
}
66+
67+
/**
68+
* Add customer id to registry.
69+
*
70+
* @param int $customerId
71+
* @return void
72+
*/
73+
private function registerCustomerId(int $customerId): void
74+
{
75+
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
76+
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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\Customer\Controller\Adminhtml\Wishlist\Product\Composite\Wishlist;
9+
10+
use Magento\Backend\Model\Session;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Framework\App\Request\Http as HttpRequest;
13+
use Magento\Framework\Serialize\SerializerInterface;
14+
use Magento\TestFramework\TestCase\AbstractBackendController;
15+
use Magento\TestFramework\Wishlist\Model\GetWishlistByCustomerId;
16+
use Magento\Wishlist\Model\Item;
17+
18+
/**
19+
* Tests for update wish list items.
20+
*
21+
* @magentoAppArea adminhtml
22+
*/
23+
class UpdateTest extends AbstractBackendController
24+
{
25+
/** @var GetWishlistByCustomerId */
26+
private $getWishlistByCustomerId;
27+
28+
/** @var SerializerInterface */
29+
private $json;
30+
31+
/** @var Session */
32+
private $session;
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
protected function setUp(): void
38+
{
39+
parent::setUp();
40+
41+
$this->getWishlistByCustomerId = $this->_objectManager->get(GetWishlistByCustomerId::class);
42+
$this->json = $this->_objectManager->get(SerializerInterface::class);
43+
$this->session = $this->_objectManager->get(Session::class);
44+
}
45+
46+
/**
47+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_simple_product.php
48+
* @magentoDbIsolation disabled
49+
*
50+
* @return void
51+
*/
52+
public function testUpdateItem(): void
53+
{
54+
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'simple-1');
55+
$this->assertNotNull($item);
56+
$params = ['id' => $item->getId(), 'qty' => 5];
57+
$this->dispatchUpdateItemRequest($params);
58+
$this->assertEquals($params['qty'], $this->getWishlistByCustomerId->getItemBySku(1, 'simple-1')->getQty());
59+
}
60+
61+
/**
62+
* @magentoDataFixture Magento/Wishlist/_files/wishlist_with_configurable_product.php
63+
* @magentoDbIsolation disabled
64+
*
65+
* @return void
66+
*/
67+
public function testUpdateItemOption(): void
68+
{
69+
$item = $this->getWishlistByCustomerId->getItemBySku(1, 'Configurable product');
70+
$this->assertNotNull($item);
71+
$params = [
72+
'id' => $item->getId(),
73+
'super_attribute' => $this->performConfigurableOption($item->getProduct()),
74+
'qty' => 5,
75+
];
76+
$this->dispatchUpdateItemRequest($params);
77+
$this->assertUpdatedItem(
78+
$this->getWishlistByCustomerId->getItemBySku(1, 'Configurable product'),
79+
$params
80+
);
81+
}
82+
83+
/**
84+
* @return void
85+
*/
86+
public function testUpdateNotExistingItem(): void
87+
{
88+
$this->dispatchUpdateItemRequest(['id' => 989]);
89+
$this->assertTrue($this->session->getCompositeProductResult()->getError());
90+
$this->assertEquals(
91+
(string)__('Please load Wish List item.'),
92+
$this->session->getCompositeProductResult()->getMessage()
93+
);
94+
}
95+
96+
/**
97+
* @return void
98+
*/
99+
public function testUpdateWithoutParams(): void
100+
{
101+
$this->dispatchUpdateItemRequest([]);
102+
$this->assertTrue($this->session->getCompositeProductResult()->getError());
103+
$this->assertEquals(
104+
(string)__('Please define Wish List item ID.'),
105+
$this->session->getCompositeProductResult()->getMessage()
106+
);
107+
}
108+
/**
109+
* Assert updated item in wish list.
110+
*
111+
* @param Item $item
112+
* @param array $expectedData
113+
* @return void
114+
*/
115+
private function assertUpdatedItem(Item $item, array $expectedData): void
116+
{
117+
$this->assertEquals($expectedData['qty'], $item->getQty());
118+
$buyRequestOption = $this->json->unserialize($item->getOptionByCode('info_buyRequest')->getValue());
119+
foreach ($expectedData as $key => $value) {
120+
$this->assertEquals($value, $buyRequestOption[$key]);
121+
}
122+
}
123+
124+
/**
125+
* Perform configurable option to select.
126+
*
127+
* @param ProductInterface $product
128+
* @return array
129+
*/
130+
private function performConfigurableOption(ProductInterface $product): array
131+
{
132+
$configurableOptions = $product->getTypeInstance()->getConfigurableOptions($product);
133+
$attributeId = key($configurableOptions);
134+
$option = reset($configurableOptions[$attributeId]);
135+
136+
return [$attributeId => $option['value_index']];
137+
}
138+
139+
/**
140+
* Dispatch update wish list item request.
141+
*
142+
* @param array $params
143+
* @return void
144+
*/
145+
private function dispatchUpdateItemRequest(array $params): void
146+
{
147+
$this->getRequest()->setParams($params)->setMethod(HttpRequest::METHOD_POST);
148+
$this->dispatch('backend/customer/wishlist_product_composite_wishlist/update');
149+
$this->assertRedirect($this->stringContains('backend/catalog/product/showUpdateResult/'));
150+
}
151+
}

0 commit comments

Comments
 (0)