Skip to content

Commit 21cb52b

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-96690' into 2.2.8-develop-pr71
2 parents 09e6a79 + e152f2e commit 21cb52b

File tree

6 files changed

+248
-18
lines changed

6 files changed

+248
-18
lines changed

app/code/Magento/Wishlist/Model/Rss/Wishlist.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Wishlist\Model\Rss;
88

99
use Magento\Framework\App\Rss\DataProviderInterface;
10+
use Magento\Store\Model\ScopeInterface;
1011

1112
/**
1213
* Wishlist RSS model
@@ -114,10 +115,8 @@ public function __construct(
114115
*/
115116
public function isAllowed()
116117
{
117-
return (bool)$this->scopeConfig->getValue(
118-
'rss/wishlist/active',
119-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
120-
);
118+
return $this->scopeConfig->isSetFlag('rss/wishlist/active', ScopeInterface::SCOPE_STORE)
119+
&& $this->getWishlist()->getCustomerId() == $this->wishlistHelper->getCustomer()->getId();
121120
}
122121

123122
/**
@@ -180,8 +179,8 @@ public function getRssData()
180179
}
181180
} else {
182181
$data = [
183-
'title' => __('We cannot retrieve the Wish List.'),
184-
'description' => __('We cannot retrieve the Wish List.'),
182+
'title' => __('We cannot retrieve the Wish List.')->render(),
183+
'description' => __('We cannot retrieve the Wish List.')->render(),
185184
'link' => $this->urlBuilder->getUrl(),
186185
'charset' => 'UTF-8',
187186
];
@@ -195,7 +194,7 @@ public function getRssData()
195194
*/
196195
public function getCacheKey()
197196
{
198-
return 'rss_wishlist_data';
197+
return 'rss_wishlist_data_' . $this->getWishlist()->getId();
199198
}
200199

201200
/**
@@ -215,7 +214,7 @@ public function getHeader()
215214
{
216215
$customerId = $this->getWishlist()->getCustomerId();
217216
$customer = $this->customerFactory->create()->load($customerId);
218-
$title = __('%1\'s Wishlist', $customer->getName());
217+
$title = __('%1\'s Wishlist', $customer->getName())->render();
219218
$newUrl = $this->urlBuilder->getUrl(
220219
'wishlist/shared/index',
221220
['code' => $this->getWishlist()->getSharingCode()]

app/code/Magento/Wishlist/Test/Unit/Model/Rss/WishlistTest.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,37 @@ class WishlistTest extends \PHPUnit\Framework\TestCase
1919
protected $model;
2020

2121
/**
22-
* @var \Magento\Wishlist\Block\Customer\Wishlist
22+
* @var \Magento\Wishlist\Block\Customer\Wishlist|\PHPUnit_Framework_MockObject_MockObject
2323
*/
2424
protected $wishlistBlock;
2525

2626
/**
27-
* @var \Magento\Rss\Model\RssFactory
27+
* @var \Magento\Rss\Model\RssFactory|\PHPUnit_Framework_MockObject_MockObject
2828
*/
2929
protected $rssFactoryMock;
3030

3131
/**
32-
* @var \Magento\Framework\UrlInterface
32+
* @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
3333
*/
3434
protected $urlBuilderMock;
3535

3636
/**
37-
* @var \Magento\Wishlist\Helper\Rss
37+
* @var \Magento\Wishlist\Helper\Rss|\PHPUnit_Framework_MockObject_MockObject
3838
*/
3939
protected $wishlistHelperMock;
4040

4141
/**
42-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
42+
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
4343
*/
4444
protected $scopeConfig;
4545

4646
/**
47-
* @var \Magento\Catalog\Helper\Image
47+
* @var \Magento\Catalog\Helper\Image|\PHPUnit_Framework_MockObject_MockObject
4848
*/
4949
protected $imageHelperMock;
5050

5151
/**
52-
* @var \Magento\Catalog\Helper\Output
52+
* @var \Magento\Catalog\Helper\Output|\PHPUnit_Framework_MockObject_MockObject
5353
*/
5454
protected $catalogOutputMock;
5555

@@ -59,7 +59,7 @@ class WishlistTest extends \PHPUnit\Framework\TestCase
5959
protected $layoutMock;
6060

6161
/**
62-
* @var \Magento\Customer\Model\CustomerFactory
62+
* @var \Magento\Customer\Model\CustomerFactory|\PHPUnit_Framework_MockObject_MockObject
6363
*/
6464
protected $customerFactory;
6565

@@ -276,17 +276,46 @@ protected function processWishlistItemDescription($wishlistModelMock, $staticArg
276276
return $description;
277277
}
278278

279+
/**
280+
* @return void
281+
*/
279282
public function testIsAllowed()
280283
{
281-
$this->scopeConfig->expects($this->once())->method('getValue')
284+
$customerId = 1;
285+
$customerServiceMock = $this->createMock(\Magento\Customer\Api\Data\CustomerInterface::class);
286+
$wishlist = $this->getMockBuilder(\Magento\Wishlist\Model\Wishlist::class)
287+
->setMethods(['getCustomerId'])
288+
->disableOriginalConstructor()
289+
->getMock();
290+
$wishlist->expects($this->once())->method('getCustomerId')->willReturn($customerId);
291+
$this->wishlistHelperMock->expects($this->once())->method('getWishlist')
292+
->willReturn($wishlist);
293+
$this->wishlistHelperMock->expects($this->once())
294+
->method('getCustomer')
295+
->willReturn($customerServiceMock);
296+
$customerServiceMock->expects($this->once())->method('getId')->willReturn($customerId);
297+
298+
$this->scopeConfig->expects($this->once())->method('isSetFlag')
282299
->with('rss/wishlist/active', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)
283300
->will($this->returnValue(true));
301+
284302
$this->assertTrue($this->model->isAllowed());
285303
}
286304

305+
/**
306+
* @return void
307+
*/
287308
public function testGetCacheKey()
288309
{
289-
$this->assertEquals('rss_wishlist_data', $this->model->getCacheKey());
310+
$wishlistId = 1;
311+
$wishlist = $this->getMockBuilder(\Magento\Wishlist\Model\Wishlist::class)
312+
->setMethods(['getId'])
313+
->disableOriginalConstructor()
314+
->getMock();
315+
$wishlist->expects($this->once())->method('getId')->willReturn($wishlistId);
316+
$this->wishlistHelperMock->expects($this->once())->method('getWishlist')->willReturn($wishlist);
317+
318+
$this->assertEquals('rss_wishlist_data_1', $this->model->getCacheKey());
290319
}
291320

292321
public function testGetCacheLifetime()
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
require 'customer_rollback.php';
9+
10+
use Magento\Customer\Api\CustomerRepositoryInterface;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/** @var \Magento\Framework\Registry $registry */
15+
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
/** @var CustomerRepositoryInterface $customerRepository */
20+
$customerRepository = Bootstrap::getObjectManager()->get(CustomerRepositoryInterface::class);
21+
try {
22+
$customer = $customerRepository->get('customer_two@example.com');
23+
$customerRepository->delete($customer);
24+
} catch (NoSuchEntityException $e) {
25+
/** Tests which are wrapped with MySQL transaction clear all data by transaction rollback. */
26+
}
27+
28+
$registry->unregister('isSecureArea');
29+
$registry->register('isSecureArea', false);
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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\Rss\Controller\Feed;
9+
10+
/**
11+
* Test for \Magento\Rss\Controller\Feed\Index
12+
*/
13+
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
14+
{
15+
/**
16+
* @var \Magento\Rss\Model\UrlBuilder
17+
*/
18+
private $urlBuilder;
19+
20+
/**
21+
* @var \Magento\Customer\Api\CustomerRepositoryInterface
22+
*/
23+
private $customerRepository;
24+
25+
/**
26+
* @var \Magento\Wishlist\Model\Wishlist
27+
*/
28+
private $wishlist;
29+
30+
/**
31+
* @var \Magento\Customer\Model\Session
32+
*/
33+
private $customerSession;
34+
35+
/**
36+
* @inheritdoc
37+
*/
38+
protected function setUp()
39+
{
40+
parent::setUp();
41+
$this->urlBuilder = $this->_objectManager->get(\Magento\Rss\Model\UrlBuilder::class);
42+
$this->customerRepository = $this->_objectManager->get(
43+
\Magento\Customer\Api\CustomerRepositoryInterface::class
44+
);
45+
$this->wishlist = $this->_objectManager->get(\Magento\Wishlist\Model\Wishlist::class);
46+
$this->customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
47+
}
48+
49+
/**
50+
* Check Rss response.
51+
*
52+
* @magentoAppIsolation enabled
53+
* @magentoDataFixture Magento/Wishlist/_files/two_wishlists_for_two_diff_customers.php
54+
* @magentoConfigFixture current_store rss/wishlist/active 1
55+
* @magentoConfigFixture current_store rss/config/active 1
56+
* @return void
57+
*/
58+
public function testRssResponse()
59+
{
60+
$customerEmail = 'customer@example.com';
61+
$customer = $this->customerRepository->get($customerEmail);
62+
$customerId = $customer->getId();
63+
$this->customerSession->setCustomerId($customerId);
64+
$wishlistId = $this->wishlist->loadByCustomerId($customerId)->getId();
65+
$this->dispatch($this->getLink($customerId, $customerEmail, $wishlistId));
66+
$body = $this->getResponse()->getBody();
67+
68+
$this->assertContains('John Smith\'s Wishlist', $body);
69+
}
70+
71+
/**
72+
* Check Rss with incorrect wishlist id.
73+
*
74+
* @magentoAppIsolation enabled
75+
* @magentoDataFixture Magento/Wishlist/_files/two_wishlists_for_two_diff_customers.php
76+
* @magentoConfigFixture current_store rss/wishlist/active 1
77+
* @magentoConfigFixture current_store rss/config/active 1
78+
* @return void
79+
*/
80+
public function testRssResponseWithIncorrectWishlistId()
81+
{
82+
$firstCustomerEmail = 'customer@example.com';
83+
$secondCustomerEmail = 'customer_two@example.com';
84+
$firstCustomer = $this->customerRepository->get($firstCustomerEmail);
85+
$secondCustomer = $this->customerRepository->get($secondCustomerEmail);
86+
87+
$firstCustomerId = $firstCustomer->getId();
88+
$secondCustomerId = $secondCustomer->getId();
89+
$this->customerSession->setCustomerId($firstCustomerId);
90+
$wishlistId = $this->wishlist->loadByCustomerId($secondCustomerId, true)->getId();
91+
$this->dispatch($this->getLink($firstCustomerId, $firstCustomerEmail, $wishlistId));
92+
$body = $this->getResponse()->getBody();
93+
94+
$this->assertContains('<title>404 Not Found</title>', $body);
95+
}
96+
97+
/**
98+
* @param mixed $customerId
99+
* @param string $customerEmail
100+
* @param mixed $wishlistId
101+
* @return string
102+
*/
103+
private function getLink($customerId, string $customerEmail, $wishlistId): string
104+
{
105+
return 'rss/feed/index/type/wishlist/data/'
106+
. base64_encode($customerId . ',' . $customerEmail)
107+
. '/wishlist_id/' . $wishlistId;
108+
}
109+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
require __DIR__ . '/../../../Magento/Customer/_files/two_customers.php';
9+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple.php';
10+
11+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
12+
13+
$customerRepository = $objectManager->create(\Magento\Customer\Api\CustomerRepositoryInterface::class);
14+
$firstCustomer = $customerRepository->get('customer@example.com');
15+
16+
$wishlistForFirstCustomer = $objectManager->create(\Magento\Wishlist\Model\Wishlist::class);
17+
$wishlistForFirstCustomer->loadByCustomerId($firstCustomer->getId(), true);
18+
$item = $wishlistForFirstCustomer->addNewItem($product, new \Magento\Framework\DataObject([]));
19+
$wishlistForFirstCustomer->save();
20+
21+
$secondCustomer = $customerRepository->get('customer_two@example.com');
22+
$wishlistForSecondCustomer = $objectManager->create(\Magento\Wishlist\Model\Wishlist::class);
23+
$wishlistForSecondCustomer->loadByCustomerId($secondCustomer->getId(), true);
24+
$item = $wishlistForSecondCustomer->addNewItem($product, new \Magento\Framework\DataObject([]));
25+
$wishlistForSecondCustomer->save();
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\Customer\Api\CustomerRepositoryInterface;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
11+
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
12+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
13+
14+
/** @var \Magento\Framework\Registry $registry */
15+
$registry = $objectManager->get(\Magento\Framework\Registry::class);
16+
$registry->unregister('isSecureArea');
17+
$registry->register('isSecureArea', true);
18+
19+
/** @var \Magento\Wishlist\Model\Wishlist $wishlist */
20+
$wishlist = $objectManager->create(\Magento\Wishlist\Model\Wishlist::class);
21+
22+
/** @var CustomerRepositoryInterface $customerRepository */
23+
$customerRepository = $objectManager->get(CustomerRepositoryInterface::class);
24+
try {
25+
$firstCustomer = $customerRepository->get('customer@example.com');
26+
$wishlist->loadByCustomerId($firstCustomer->getId());
27+
$wishlist->delete();
28+
$secondCustomer = $customerRepository->get('customer_two@example.com');
29+
$wishlist->loadByCustomerId($secondCustomer->getId());
30+
$wishlist->delete();
31+
} catch (NoSuchEntityException $e) {
32+
/** Tests which are wrapped with MySQL transaction clear all data by transaction rollback. */
33+
}
34+
35+
$registry->unregister('isSecureArea');
36+
$registry->register('isSecureArea', false);
37+
38+
require __DIR__ . '/../../../Magento/Customer/_files/two_customers_rollback.php';
39+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_rollback.php';

0 commit comments

Comments
 (0)