Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PagerTest.php
Go to the documentation of this file.
1 <?php
7 
8 class PagerTest extends \PHPUnit\Framework\TestCase
9 {
11  protected $_helper = null;
12 
16  protected function setUp()
17  {
18  $sessionMock = $this->getMockBuilder(
19  \Magento\Backend\Model\Session::class
20  )->disableOriginalConstructor()->setMethods(
21  ['setData', 'getData']
22  )->getMock();
23  $sessionMock->expects(
24  $this->any()
25  )->method(
26  'setData'
27  )->with(
28  $this->equalTo('search_result_idsreviews'),
29  $this->anything()
30  );
31  $sessionMock->expects(
32  $this->any()
33  )->method(
34  'getData'
35  )->with(
36  $this->equalTo('search_result_idsreviews')
37  )->will(
38  $this->returnValue([3, 2, 6, 5])
39  );
40 
41  $contextMock = $this->createPartialMock(
42  \Magento\Framework\App\Helper\Context::class,
43  ['getModuleManager', 'getRequest']
44  );
45  $this->_helper = new \Magento\Review\Helper\Action\Pager($contextMock, $sessionMock);
46  $this->_helper->setStorageId('reviews');
47  }
48 
52  public function testStorageSet()
53  {
54  $result = $this->_helper->setItems([1]);
55  $this->assertEquals($result, $this->_helper);
56  }
57 
61  public function testGetNextItem()
62  {
63  $this->assertEquals(2, $this->_helper->getNextItemId(3));
64  }
65 
69  public function testGetNextItemNotFound()
70  {
71  $this->assertFalse($this->_helper->getNextItemId(30));
72  $this->assertFalse($this->_helper->getNextItemId(5));
73  }
74 
78  public function testGetPreviousItem()
79  {
80  $this->assertEquals(2, $this->_helper->getPreviousItemId(6));
81  }
82 
86  public function testGetPreviousItemNotFound()
87  {
88  $this->assertFalse($this->_helper->getPreviousItemId(30));
89  $this->assertFalse($this->_helper->getPreviousItemId(3));
90  }
91 }