Skip to content

Commit 940a78e

Browse files
committed
Add Unit Test for fix getRssUrl() when customer not login
1 parent e56640c commit 940a78e

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

app/code/Magento/Wishlist/Helper/Data.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Wishlist\Helper;
710

811
use Magento\Framework\App\ActionInterface;
@@ -117,6 +120,9 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
117120
* @param \Magento\Customer\Helper\View $customerViewHelper
118121
* @param WishlistProviderInterface $wishlistProvider
119122
* @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
123+
* @param Escaper $escaper
124+
*
125+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
120126
*/
121127
public function __construct(
122128
\Magento\Framework\App\Helper\Context $context,
@@ -127,7 +133,8 @@ public function __construct(
127133
\Magento\Framework\Data\Helper\PostHelper $postDataHelper,
128134
\Magento\Customer\Helper\View $customerViewHelper,
129135
WishlistProviderInterface $wishlistProvider,
130-
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
136+
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
137+
Escaper $escaper = null
131138
) {
132139
$this->_coreRegistry = $coreRegistry;
133140
$this->_customerSession = $customerSession;
@@ -137,7 +144,7 @@ public function __construct(
137144
$this->_customerViewHelper = $customerViewHelper;
138145
$this->wishlistProvider = $wishlistProvider;
139146
$this->productRepository = $productRepository;
140-
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
147+
$this->escaper = $escaper ?? ObjectManager::getInstance()->get(Escaper::class);
141148
parent::__construct($context);
142149
}
143150

@@ -352,7 +359,6 @@ public function getAddParams($item, array $params = [])
352359
* Retrieve params for adding product to wishlist
353360
*
354361
* @param int $itemId
355-
*
356362
* @return string
357363
*/
358364
public function getMoveFromCartParams($itemId)
@@ -366,7 +372,6 @@ public function getMoveFromCartParams($itemId)
366372
* Retrieve params for updating product in wishlist
367373
*
368374
* @param \Magento\Catalog\Model\Product|\Magento\Wishlist\Model\Item $item
369-
*
370375
* @return string|false
371376
*/
372377
public function getUpdateParams($item)
@@ -541,6 +546,7 @@ public function getCustomerName()
541546
*/
542547
public function getRssUrl($wishlistId = null)
543548
{
549+
$params = [];
544550
$customer = $this->_getCurrentCustomer();
545551
if ($customer) {
546552
$key = $customer->getId() . ',' . $customer->getEmail();
@@ -574,6 +580,7 @@ public function getDefaultWishlistName()
574580

575581
/**
576582
* Calculate count of wishlist items and put value to customer session.
583+
*
577584
* Method called after wishlist modifications and trigger 'wishlist_items_renewed' event.
578585
* Depends from configuration.
579586
*

app/code/Magento/Wishlist/Test/Unit/Helper/DataTest.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Wishlist\Controller\WishlistProviderInterface;
1919
use Magento\Wishlist\Model\Item as WishlistItem;
2020
use Magento\Wishlist\Model\Wishlist;
21+
use Magento\Customer\Model\Session;
2122

2223
/**
2324
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -63,6 +64,9 @@ class DataTest extends \PHPUnit\Framework\TestCase
6364
/** @var Context |\PHPUnit_Framework_MockObject_MockObject */
6465
protected $context;
6566

67+
/** @var Session |\PHPUnit_Framework_MockObject_MockObject */
68+
protected $customerSession;
69+
6670
/**
6771
* Set up mock objects for tested class
6872
*
@@ -121,12 +125,13 @@ protected function setUp()
121125

122126
$this->wishlistItem = $this->getMockBuilder(\Magento\Wishlist\Model\Item::class)
123127
->disableOriginalConstructor()
124-
->setMethods([
125-
'getProduct',
126-
'getWishlistItemId',
127-
'getQty',
128-
])
129-
->getMock();
128+
->setMethods(
129+
[
130+
'getProduct',
131+
'getWishlistItemId',
132+
'getQty',
133+
]
134+
)->getMock();
130135

131136
$this->wishlist = $this->getMockBuilder(\Magento\Wishlist\Model\Wishlist::class)
132137
->disableOriginalConstructor()
@@ -136,11 +141,16 @@ protected function setUp()
136141
->disableOriginalConstructor()
137142
->getMock();
138143

144+
$this->customerSession = $this->getMockBuilder(\Magento\Customer\Model\Session::class)
145+
->disableOriginalConstructor()
146+
->getMock();
147+
139148
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
140149
$this->model = $objectManager->getObject(
141150
\Magento\Wishlist\Helper\Data::class,
142151
[
143152
'context' => $this->context,
153+
'customerSession' => $this->customerSession,
144154
'storeManager' => $this->storeManager,
145155
'wishlistProvider' => $this->wishlistProvider,
146156
'coreRegistry' => $this->coreRegistry,
@@ -431,4 +441,20 @@ public function testGetSharedAddAllToCartUrl()
431441

432442
$this->assertEquals($url, $this->model->getSharedAddAllToCartUrl());
433443
}
444+
445+
public function testGetRssUrlWithCustomerNotLogin()
446+
{
447+
$url = 'result url';
448+
449+
$this->customerSession->expects($this->once())
450+
->method('isLoggedIn')
451+
->willReturn(false);
452+
453+
$this->urlBuilder->expects($this->once())
454+
->method('getUrl')
455+
->with('wishlist/index/rss', [])
456+
->willReturn($url);
457+
458+
$this->assertEquals($url, $this->model->getRssUrl());
459+
}
434460
}

0 commit comments

Comments
 (0)