1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Rss\Controller\Feed;
class IndexTest extends \Magento\TestFramework\TestCase\AbstractBackendController
{
/**
* @var \Magento\Rss\Model\UrlBuilder
*/
private $urlBuilder;
/**
* @var \Magento\Customer\Api\CustomerRepositoryInterface
*/
private $customerRepository;
/**
* @var \Magento\Wishlist\Model\Wishlist
*/
private $wishlist;
/**
* @var
*/
private $customerSession;
protected function setUp()
{
parent::setUp();
$this->urlBuilder = $this->_objectManager->get(\Magento\Rss\Model\UrlBuilder::class);
$this->customerRepository = $this->_objectManager->get(
\Magento\Customer\Api\CustomerRepositoryInterface::class
);
$this->wishlist = $this->_objectManager->get(\Magento\Wishlist\Model\Wishlist::class);
$this->customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
}
/**
* Check Rss response.
*
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Wishlist/_files/two_wishlists_for_two_diff_customers.php
* @magentoConfigFixture current_store rss/wishlist/active 1
* @magentoConfigFixture current_store rss/config/active 1
*/
public function testRssResponse()
{
$firstCustomerId = 1;
$this->customerSession->setCustomerId($firstCustomerId);
$customer = $this->customerRepository->getById($firstCustomerId);
$customerEmail = $customer->getEmail();
$wishlistId = $this->wishlist->loadByCustomerId($firstCustomerId)->getId();
$this->dispatch($this->getLink($firstCustomerId, $customerEmail, $wishlistId));
$body = $this->getResponse()->getBody();
$this->assertContains('<title>John Smith\'s Wishlist</title>', $body);
}
/**
* Check Rss with incorrect wishlist id.
*
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Wishlist/_files/two_wishlists_for_two_diff_customers.php
* @magentoConfigFixture current_store rss/wishlist/active 1
* @magentoConfigFixture current_store rss/config/active 1
*/
public function testRssResponseWithIncorrectWishlistId()
{
$firstCustomerId = 1;
$secondCustomerId = 2;
$this->customerSession->setCustomerId($firstCustomerId);
$customer = $this->customerRepository->getById($firstCustomerId);
$customerEmail = $customer->getEmail();
$wishlistId = $this->wishlist->loadByCustomerId($secondCustomerId, true)->getId();
$this->dispatch($this->getLink($firstCustomerId, $customerEmail, $wishlistId));
$body = $this->getResponse()->getBody();
$this->assertContains('<title>404 Not Found</title>', $body);
}
private function getLink($customerId, $customerEmail, $wishlistId)
{
return 'rss/feed/index/type/wishlist/data/'
. base64_encode($customerId . ',' . $customerEmail)
. '/wishlist_id/' . $wishlistId;
}
}