RssTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Test\Unit\Model;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class RssTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \Magento\Review\Model\Rss
  12. */
  13. protected $rss;
  14. /**
  15. * @var ObjectManagerHelper
  16. */
  17. protected $objectManagerHelper;
  18. /**
  19. * @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. protected $managerInterface;
  22. /**
  23. * @var \PHPUnit_Framework_MockObject_MockObject
  24. */
  25. protected $reviewFactory;
  26. protected function setUp()
  27. {
  28. $this->managerInterface = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
  29. $this->reviewFactory = $this->createPartialMock(\Magento\Review\Model\ReviewFactory::class, ['create']);
  30. $this->objectManagerHelper = new ObjectManagerHelper($this);
  31. $this->rss = $this->objectManagerHelper->getObject(
  32. \Magento\Review\Model\Rss::class,
  33. [
  34. 'eventManager' => $this->managerInterface,
  35. 'reviewFactory' => $this->reviewFactory
  36. ]
  37. );
  38. }
  39. public function testGetProductCollection()
  40. {
  41. $reviewModel = $this->createPartialMock(\Magento\Review\Model\Review::class, [
  42. '__wakeUp',
  43. 'getProductCollection'
  44. ]);
  45. $productCollection = $this->createPartialMock(
  46. \Magento\Review\Model\ResourceModel\Review\Product\Collection::class,
  47. [
  48. 'addStatusFilter',
  49. 'addAttributeToSelect',
  50. 'setDateOrder'
  51. ]
  52. );
  53. $reviewModel->expects($this->once())->method('getProductCollection')
  54. ->will($this->returnValue($productCollection));
  55. $this->reviewFactory->expects($this->once())->method('create')->will($this->returnValue($reviewModel));
  56. $productCollection->expects($this->once())->method('addStatusFilter')->will($this->returnSelf());
  57. $productCollection->expects($this->once())->method('addAttributeToSelect')->will($this->returnSelf());
  58. $productCollection->expects($this->once())->method('setDateOrder')->will($this->returnSelf());
  59. $this->managerInterface->expects($this->once())->method('dispatch')->will($this->returnSelf());
  60. $this->assertEquals($productCollection, $this->rss->getProductCollection());
  61. }
  62. }