RssTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Test\Unit\Block\Adminhtml;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class RssTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Review\Block\Adminhtml\Rss
  12. */
  13. protected $block;
  14. /**
  15. * @var ObjectManagerHelper
  16. */
  17. protected $objectManagerHelper;
  18. /**
  19. * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $storeManagerInterface;
  22. /**
  23. * @var \Magento\Review\Model\Rss|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $rss;
  26. /**
  27. * @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. protected $urlBuilder;
  30. protected function setUp()
  31. {
  32. $this->storeManagerInterface = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  33. $this->rss = $this->createPartialMock(\Magento\Review\Model\Rss::class, ['__wakeUp', 'getProductCollection']);
  34. $this->urlBuilder = $this->createMock(\Magento\Framework\UrlInterface::class);
  35. $this->objectManagerHelper = new ObjectManagerHelper($this);
  36. $this->block = $this->objectManagerHelper->getObject(
  37. \Magento\Review\Block\Adminhtml\Rss::class,
  38. [
  39. 'storeManager' => $this->storeManagerInterface,
  40. 'rssModel' => $this->rss,
  41. 'urlBuilder' => $this->urlBuilder,
  42. ]
  43. );
  44. }
  45. public function testGetRssData()
  46. {
  47. $rssData = [
  48. 'title' => 'Pending product review(s)',
  49. 'description' => 'Pending product review(s)',
  50. 'link' => 'http://rss.magento.com',
  51. 'charset' => 'UTF-8',
  52. 'entries' => [
  53. 'title' => 'Product: "Product Name" reviewed by: Product Nick',
  54. 'link' => 'http://product.magento.com',
  55. 'description' => [
  56. 'rss_url' => 'http://rss.magento.com',
  57. 'name' => 'Product Name',
  58. 'summary' => 'Product Title',
  59. 'review' => 'Product Detail',
  60. 'store' => 'Store Name',
  61. ],
  62. ],
  63. ];
  64. $rssUrl = 'http://rss.magento.com';
  65. $productModel = $this->createPartialMock(\Magento\Catalog\Model\ResourceModel\Product::class, [
  66. 'getStoreId',
  67. 'getId',
  68. 'getReviewId',
  69. 'getName',
  70. 'getDetail',
  71. 'getTitle',
  72. 'getNickname',
  73. 'getProductUrl'
  74. ]);
  75. $storeModel = $this->createMock(\Magento\Store\Model\Store::class);
  76. $this->storeManagerInterface->expects($this->once())->method('getStore')->will($this->returnValue($storeModel));
  77. $storeModel->expects($this->once())->method('getName')
  78. ->will($this->returnValue($rssData['entries']['description']['store']));
  79. $this->urlBuilder->expects($this->any())->method('getUrl')->will($this->returnValue($rssUrl));
  80. $this->urlBuilder->expects($this->once())->method('setScope')->will($this->returnSelf());
  81. $productModel->expects($this->any())->method('getStoreId')->will($this->returnValue(1));
  82. $productModel->expects($this->any())->method('getId')->will($this->returnValue(1));
  83. $productModel->expects($this->once())->method('getReviewId')->will($this->returnValue(1));
  84. $productModel->expects($this->any())->method('getNickName')->will($this->returnValue('Product Nick'));
  85. $productModel->expects($this->any())->method('getName')
  86. ->will($this->returnValue($rssData['entries']['description']['name']));
  87. $productModel->expects($this->once())->method('getDetail')
  88. ->will($this->returnValue($rssData['entries']['description']['review']));
  89. $productModel->expects($this->once())->method('getTitle')
  90. ->will($this->returnValue($rssData['entries']['description']['summary']));
  91. $productModel->expects($this->any())->method('getProductUrl')
  92. ->will($this->returnValue('http://product.magento.com'));
  93. $this->rss->expects($this->once())->method('getProductCollection')
  94. ->will($this->returnValue([$productModel]));
  95. $data = $this->block->getRssData();
  96. $this->assertEquals($rssData['title'], $data['title']);
  97. $this->assertEquals($rssData['description'], $data['description']);
  98. $this->assertEquals($rssData['link'], $data['link']);
  99. $this->assertEquals($rssData['charset'], $data['charset']);
  100. $this->assertEquals($rssData['entries']['title'], $data['entries'][0]['title']);
  101. $this->assertEquals($rssData['entries']['link'], $data['entries'][0]['link']);
  102. $this->assertContains($rssData['entries']['description']['rss_url'], $data['entries'][0]['description']);
  103. $this->assertContains($rssData['entries']['description']['name'], $data['entries'][0]['description']);
  104. $this->assertContains($rssData['entries']['description']['summary'], $data['entries'][0]['description']);
  105. $this->assertContains($rssData['entries']['description']['review'], $data['entries'][0]['description']);
  106. $this->assertContains($rssData['entries']['description']['store'], $data['entries'][0]['description']);
  107. }
  108. public function testGetCacheLifetime()
  109. {
  110. $this->assertEquals(0, $this->block->getCacheLifetime());
  111. }
  112. public function testIsAllowed()
  113. {
  114. $this->assertEquals(true, $this->block->isAllowed());
  115. }
  116. public function testGetFeeds()
  117. {
  118. $this->assertEquals([], $this->block->getFeeds());
  119. }
  120. }