Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReviewDataProviderTest.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Review\Model\ResourceModel\Review\Product\CollectionFactory;
13 
17 class ReviewDataProviderTest extends \PHPUnit\Framework\TestCase
18 {
22  protected $model;
23 
27  protected $objectManager;
28 
33 
37  protected $collectionMock;
38 
42  protected $requestMock;
43 
44  protected function setUp()
45  {
46  $this->objectManager = new ObjectManager($this);
47  $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
48  ->setMethods(['create'])
49  ->disableOriginalConstructor()
50  ->getMock();
51  $this->collectionMock = $this->objectManager->getCollectionMock(Collection::class, []);
52  $this->requestMock = $this->getMockBuilder(RequestInterface::class)
53  ->getMockForAbstractClass();
54 
55  $this->collectionFactoryMock->expects($this->any())
56  ->method('create')
57  ->willReturn($this->collectionMock);
58 
59  $this->model = $this->objectManager->getObject(ReviewDataProvider::class, [
60  'name' => 'testName',
61  'primaryFieldName' => 'testPrimaryFieldName',
62  'requestFieldName' => 'testRequestFieldName',
63  'meta' => [],
64  'data' => [],
65  'collectionFactory' => $this->collectionFactoryMock,
66  'request' => $this->requestMock,
67  ]);
68  }
69 
70  public function testGetData()
71  {
72  $expected = [
73  'totalRecords' => null,
74  'items' => [],
75  ];
76 
77  $this->collectionMock->expects($this->once())
78  ->method('addEntityFilter')
79  ->willReturnSelf();
80  $this->collectionMock->expects($this->once())
81  ->method('addStoreData')
82  ->willReturnSelf();
83  $this->requestMock->expects($this->once())
84  ->method('getParam')
85  ->with('current_product_id', 0)
86  ->willReturn(1);
87 
88  $this->assertSame($expected, $this->model->getData());
89  }
90 }