IndexTest.php 3.1 KB

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