Skip to content

Commit 5932b59

Browse files
committed
MC-32134: Storefront: Customer wish list on customer profile
1 parent 81bb39b commit 5932b59

21 files changed

+1735
-316
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\TestFramework\Wishlist\Model;
9+
10+
use Magento\Wishlist\Model\Item;
11+
use Magento\Wishlist\Model\Wishlist;
12+
use Magento\Wishlist\Model\WishlistFactory;
13+
14+
/**
15+
* Load wish list by customer id.
16+
*/
17+
class GetWishlistByCustomerId
18+
{
19+
/** @var WishlistFactory */
20+
private $wishlistFactory;
21+
22+
/**
23+
* @param WishlistFactory $wishlistFactory
24+
*/
25+
public function __construct(WishlistFactory $wishlistFactory)
26+
{
27+
$this->wishlistFactory = $wishlistFactory;
28+
}
29+
30+
/**
31+
* Load wish list by customer id.
32+
*
33+
* @param int $customerId
34+
* @return Wishlist
35+
*/
36+
public function execute(int $customerId): Wishlist
37+
{
38+
return $this->wishlistFactory->create()->loadByCustomerId($customerId, true);
39+
}
40+
41+
/**
42+
* Get wish list item by sku.
43+
*
44+
* @param int $customerId
45+
* @param string $sku
46+
* @return null|Item
47+
*/
48+
public function getItemBySku(int $customerId, string $sku): ?Item
49+
{
50+
$result = null;
51+
$items = $this->execute($customerId)->getItemCollection()->getItems();
52+
foreach ($items as $item) {
53+
if ($item->getProduct()->getData('sku') === $sku) {
54+
$result = $item;
55+
break;
56+
}
57+
}
58+
59+
return $result;
60+
}
61+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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\Wishlist\Block\Customer;
9+
10+
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Framework\View\LayoutInterface;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
use Magento\TestFramework\Helper\Xpath;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Class test share wish list block.
18+
*
19+
* @magentoDbIsolation enabled
20+
* @magentoAppArea frontend
21+
*/
22+
class SharingTest extends TestCase
23+
{
24+
/** @var ObjectManagerInterface */
25+
private $objectManager;
26+
27+
/** @var Sharing */
28+
private $block;
29+
30+
/**
31+
* @inheritdoc
32+
*/
33+
protected function setUp()
34+
{
35+
parent::setUp();
36+
37+
$this->objectManager = Bootstrap::getObjectManager();
38+
$this->block = $this->objectManager->get(LayoutInterface::class)->createBlock(Sharing::class);
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function testDisplayWishListSharingForm(): void
45+
{
46+
$elementsXpath = [
47+
'Emails input' => "//form[contains(@class, 'share')]//textarea[@name='emails' and @id='email_address']",
48+
'Message input' => "//form[contains(@class, 'share')]//textarea[@name='message' and @id='message']",
49+
'Share button' => "//form[contains(@class, 'share')]//button[contains(@class, 'submit')]"
50+
. "/span[contains(text(), 'Share Wish List')]",
51+
];
52+
$blockHtml = $this->block->setTemplate('Magento_Wishlist::sharing.phtml')->toHtml();
53+
foreach ($elementsXpath as $element => $xpath) {
54+
$this->assertEquals(
55+
1,
56+
Xpath::getElementsCountForXpath($xpath, $blockHtml),
57+
sprintf("%s was not found.", $element)
58+
);
59+
}
60+
}
61+
}

dev/tests/integration/testsuite/Magento/Wishlist/Block/Customer/Wishlist/Item/ColumnTest.php

Lines changed: 105 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,130 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Wishlist\Block\Customer\Wishlist\Item;
79

8-
class ColumnTest extends \PHPUnit\Framework\TestCase
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\View\Element\Text;
13+
use Magento\Framework\View\LayoutInterface;
14+
use Magento\Framework\View\Result\PageFactory;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use Magento\TestFramework\Helper\Xpath;
17+
use Magento\TestFramework\Wishlist\Model\GetWishlistByCustomerId;
18+
use Magento\Wishlist\Block\Customer\Wishlist\Items;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Test wish list item column.
23+
*
24+
* @magentoDbIsolation enabled
25+
* @magentoAppArea frontend
26+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
27+
*/
28+
class ColumnTest extends TestCase
929
{
30+
/** @var ObjectManagerInterface */
31+
private $objectManager;
32+
33+
/** @var Session */
34+
private $customerSession;
35+
36+
/** @var LayoutInterface */
37+
private $layout;
38+
39+
/** @var Column */
40+
private $block;
41+
42+
/** @var GetWishlistByCustomerId */
43+
private $getWishlistItemsByCustomerId;
44+
1045
/**
11-
* @var \Magento\Framework\View\LayoutInterface
46+
* @inheritdoc
1247
*/
13-
protected $_layout = null;
48+
protected function setUp()
49+
{
50+
$this->objectManager = Bootstrap::getObjectManager();
51+
$this->customerSession = $this->objectManager->get(Session::class);
52+
$this->layout = $this->objectManager->get(LayoutInterface::class);
53+
$this->block = $this->layout->addBlock(Column::class, 'test');
54+
$this->layout->addBlock(Text::class, 'child', 'test');
55+
$this->getWishlistItemsByCustomerId = $this->objectManager->get(GetWishlistByCustomerId::class);
56+
}
1457

1558
/**
16-
* @var \Magento\Wishlist\Block\Customer\Wishlist\Item\Column
59+
* @inheritdoc
1760
*/
18-
protected $_block = null;
19-
20-
protected function setUp()
61+
protected function tearDown()
2162
{
22-
$this->_layout = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
23-
\Magento\Framework\View\LayoutInterface::class
24-
);
25-
$this->_block = $this->_layout->addBlock(\Magento\Wishlist\Block\Customer\Wishlist\Item\Column::class, 'test');
26-
$this->_layout->addBlock(\Magento\Framework\View\Element\Text::class, 'child', 'test');
63+
$this->customerSession->setCustomerId(null);
64+
65+
parent::tearDown();
2766
}
2867

2968
/**
3069
* @magentoAppIsolation enabled
70+
*
71+
* @return void
3172
*/
32-
public function testToHtml()
73+
public function testToHtml(): void
3374
{
3475
$item = new \StdClass();
35-
$this->_block->setItem($item);
36-
$this->_block->toHtml();
37-
$this->assertSame($item, $this->_layout->getBlock('child')->getItem());
76+
$this->block->setItem($item);
77+
$this->block->toHtml();
78+
$this->assertSame($item, $this->layout->getBlock('child')->getItem());
3879
}
3980

40-
public function testGetJs()
81+
/**
82+
* @return void
83+
*/
84+
public function testGetJs(): void
4185
{
4286
$expected = uniqid();
43-
$this->_layout->getBlock('child')->setJs($expected);
44-
$this->assertEquals($expected, $this->_block->getJs());
87+
$this->layout->getBlock('child')->setJs($expected);
88+
$this->assertEquals($expected, $this->block->getJs());
89+
}
90+
91+
/**
92+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
93+
*
94+
* @return void
95+
*/
96+
public function testWishListItemButtons(): void
97+
{
98+
$buttons = [
99+
"Add to Cart button" => "//button[contains(@class, 'tocart')]/span[contains(text(), 'Add to Cart')]",
100+
"Edit button" => "//a[contains(@class, 'edit')]/span[contains(text(), 'Edit')]",
101+
"Remove item button" => "//a[contains(@class, 'delete')]/span[contains(text(), 'Remove item')]",
102+
];
103+
$item = $this->getWishlistItemsByCustomerId->getItemBySku(1, 'simple');
104+
$this->assertNotNull($item);
105+
$block = $this->getWishListItemsBlock()->getChildBlock('customer.wishlist.item.inner');
106+
$blockHtml = $block->setItem($item)->toHtml();
107+
foreach ($buttons as $buttonName => $xpath) {
108+
$this->assertEquals(
109+
1,
110+
Xpath::getElementsCountForXpath($xpath, $blockHtml),
111+
sprintf("%s wasn't found.", $buttonName)
112+
);
113+
}
114+
}
115+
116+
/**
117+
* Get wish list items block.
118+
*
119+
* @return Items
120+
*/
121+
private function getWishListItemsBlock(): Items
122+
{
123+
$page = $this->objectManager->create(PageFactory::class)->create();
124+
$page->addHandle([
125+
'default',
126+
'wishlist_index_index',
127+
]);
128+
$page->getLayout()->generateXml();
129+
130+
return $page->getLayout()->getBlock('customer.wishlist.items');
45131
}
46132
}

dev/tests/integration/testsuite/Magento/Wishlist/Block/Customer/WishlistTest.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616

1717
/**
18-
* Class test my wish list on customer account page.
18+
* Class test block wish list on customer account page.
1919
*
2020
* @magentoAppArea frontend
2121
* @magentoDbIsolation enabled
@@ -66,9 +66,11 @@ protected function tearDown()
6666
public function testDisplayNumberOfItemsInWishList(): void
6767
{
6868
$this->customerSession->setCustomerId(1);
69+
$pagerBlockHtml = $this->getWishListBlock()->getChildBlock('wishlist_item_pager')->toHtml();
6970
$this->assertEquals(
7071
1,
71-
Xpath::getElementsCountForXpath(sprintf(self::ITEMS_COUNT_XPATH, 1), $this->getWishListPagerBlockHtml())
72+
Xpath::getElementsCountForXpath(sprintf(self::ITEMS_COUNT_XPATH, 1), $pagerBlockHtml),
73+
"Element items count wasn't found."
7274
);
7375
}
7476

@@ -82,27 +84,46 @@ public function testDisplayItemQuantitiesInWishList(): void
8284
{
8385
$this->markTestSkipped('Test is blocked by issue MC-31595');
8486
$this->customerSession->setCustomerId(1);
87+
$pagerBlockHtml = $this->getWishListBlock()->getChildBlock('wishlist_item_pager')->toHtml();
8588
$this->assertEquals(
8689
1,
87-
Xpath::getElementsCountForXpath(sprintf(self::ITEMS_COUNT_XPATH, 3), $this->getWishListPagerBlockHtml())
90+
Xpath::getElementsCountForXpath(sprintf(self::ITEMS_COUNT_XPATH, 3), $pagerBlockHtml),
91+
"Element items count wasn't found."
8892
);
8993
}
9094

9195
/**
92-
* Get wish list pager block html.
96+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
9397
*
94-
* @return string
98+
* @return void
99+
*/
100+
public function testDisplayActionButtonsInWishList(): void
101+
{
102+
$buttonsXpath = [
103+
"//button[contains(@class, 'update') and @type='submit']/span[contains(text(), 'Update Wish List')]",
104+
"//button[contains(@class, 'share') and @type='submit']/span[contains(text(), 'Share Wish List')]",
105+
"//button[contains(@class, 'tocart') and @type='button']/span[contains(text(), 'Add All to Cart')]",
106+
];
107+
$this->customerSession->setCustomerId(1);
108+
$blockHtml = $this->getWishListBlock()->toHtml();
109+
foreach ($buttonsXpath as $xpath) {
110+
$this->assertEquals(1, Xpath::getElementsCountForXpath($xpath, $blockHtml));
111+
}
112+
}
113+
114+
/**
115+
* Get wish list block.
116+
*
117+
* @return Wishlist
95118
*/
96-
private function getWishListPagerBlockHtml(): string
119+
private function getWishListBlock(): Wishlist
97120
{
98121
$this->page->addHandle([
99122
'default',
100123
'wishlist_index_index',
101124
]);
102125
$this->page->getLayout()->generateXml();
103-
/** @var Wishlist $customerWishlistBlock */
104-
$customerWishlistBlock = $this->page->getLayout()->getBlock('customer.wishlist');
105126

106-
return $customerWishlistBlock->getChildBlock('wishlist_item_pager')->toHtml();
127+
return $this->page->getLayout()->getBlock('customer.wishlist');
107128
}
108129
}

0 commit comments

Comments
 (0)