RecentTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\Customer;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class RecentTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Review\Block\Customer\Recent */
  11. protected $object;
  12. /** @var ObjectManagerHelper */
  13. protected $objectManagerHelper;
  14. /** @var \Magento\Framework\View\Element\Template\Context|\PHPUnit_Framework_MockObject_MockObject */
  15. protected $context;
  16. /** @var \Magento\Review\Model\ResourceModel\Review\Product\Collection|\PHPUnit_Framework_MockObject_MockObject */
  17. protected $collection;
  18. /** @var \PHPUnit_Framework_MockObject_MockObject */
  19. protected $collectionFactory;
  20. /** @var \Magento\Customer\Helper\Session\CurrentCustomer|\PHPUnit_Framework_MockObject_MockObject */
  21. protected $currentCustomer;
  22. /** @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
  23. protected $storeManager;
  24. protected function setUp()
  25. {
  26. $this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
  27. $this->context = $this->createMock(\Magento\Framework\View\Element\Template\Context::class);
  28. $this->context->expects(
  29. $this->any()
  30. )->method(
  31. 'getStoreManager'
  32. )->will(
  33. $this->returnValue($this->storeManager)
  34. );
  35. $this->collection = $this->createMock(\Magento\Review\Model\ResourceModel\Review\Product\Collection::class);
  36. $this->collectionFactory = $this->createPartialMock(
  37. \Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory::class,
  38. ['create']
  39. );
  40. $this->collectionFactory->expects(
  41. $this->once()
  42. )->method(
  43. 'create'
  44. )->will(
  45. $this->returnValue($this->collection)
  46. );
  47. $this->currentCustomer = $this->createMock(\Magento\Customer\Helper\Session\CurrentCustomer::class);
  48. $this->objectManagerHelper = new ObjectManagerHelper($this);
  49. $this->object = $this->objectManagerHelper->getObject(
  50. \Magento\Review\Block\Customer\Recent::class,
  51. [
  52. 'context' => $this->context,
  53. 'collectionFactory' => $this->collectionFactory,
  54. 'currentCustomer' => $this->currentCustomer
  55. ]
  56. );
  57. }
  58. public function testGetCollection()
  59. {
  60. $this->storeManager->expects(
  61. $this->any()
  62. )->method(
  63. 'getStore'
  64. )->will(
  65. $this->returnValue(new \Magento\Framework\DataObject(['id' => 42]))
  66. );
  67. $this->currentCustomer->expects($this->any())->method('getCustomerId')->will($this->returnValue(4242));
  68. $this->collection->expects(
  69. $this->any()
  70. )->method(
  71. 'addStoreFilter'
  72. )->with(
  73. 42
  74. )->will(
  75. $this->returnValue($this->collection)
  76. );
  77. $this->collection->expects(
  78. $this->any()
  79. )->method(
  80. 'addCustomerFilter'
  81. )->with(
  82. 4242
  83. )->will(
  84. $this->returnValue($this->collection)
  85. );
  86. $this->collection->expects(
  87. $this->any()
  88. )->method(
  89. 'setDateOrder'
  90. )->with()->will(
  91. $this->returnValue($this->collection)
  92. );
  93. $this->collection->expects(
  94. $this->any()
  95. )->method(
  96. 'setPageSize'
  97. )->with(
  98. 5
  99. )->will(
  100. $this->returnValue($this->collection)
  101. );
  102. $this->collection->expects($this->any())->method('load')->with()->will($this->returnValue($this->collection));
  103. $this->collection->expects(
  104. $this->any()
  105. )->method(
  106. 'addReviewSummary'
  107. )->with()->will(
  108. $this->returnValue($this->collection)
  109. );
  110. $this->assertSame($this->collection, $this->object->getReviews());
  111. }
  112. }