PagerTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Review\Test\Unit\Helper\Action;
  7. class PagerTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Review\Helper\Action\Pager */
  10. protected $_helper = null;
  11. /**
  12. * Prepare helper object
  13. */
  14. protected function setUp()
  15. {
  16. $sessionMock = $this->getMockBuilder(
  17. \Magento\Backend\Model\Session::class
  18. )->disableOriginalConstructor()->setMethods(
  19. ['setData', 'getData']
  20. )->getMock();
  21. $sessionMock->expects(
  22. $this->any()
  23. )->method(
  24. 'setData'
  25. )->with(
  26. $this->equalTo('search_result_idsreviews'),
  27. $this->anything()
  28. );
  29. $sessionMock->expects(
  30. $this->any()
  31. )->method(
  32. 'getData'
  33. )->with(
  34. $this->equalTo('search_result_idsreviews')
  35. )->will(
  36. $this->returnValue([3, 2, 6, 5])
  37. );
  38. $contextMock = $this->createPartialMock(
  39. \Magento\Framework\App\Helper\Context::class,
  40. ['getModuleManager', 'getRequest']
  41. );
  42. $this->_helper = new \Magento\Review\Helper\Action\Pager($contextMock, $sessionMock);
  43. $this->_helper->setStorageId('reviews');
  44. }
  45. /**
  46. * Test storage set with proper parameters
  47. */
  48. public function testStorageSet()
  49. {
  50. $result = $this->_helper->setItems([1]);
  51. $this->assertEquals($result, $this->_helper);
  52. }
  53. /**
  54. * Test getNextItem
  55. */
  56. public function testGetNextItem()
  57. {
  58. $this->assertEquals(2, $this->_helper->getNextItemId(3));
  59. }
  60. /**
  61. * Test getNextItem when item not found or no next item
  62. */
  63. public function testGetNextItemNotFound()
  64. {
  65. $this->assertFalse($this->_helper->getNextItemId(30));
  66. $this->assertFalse($this->_helper->getNextItemId(5));
  67. }
  68. /**
  69. * Test getPreviousItemId
  70. */
  71. public function testGetPreviousItem()
  72. {
  73. $this->assertEquals(2, $this->_helper->getPreviousItemId(6));
  74. }
  75. /**
  76. * Test getPreviousItemId when item not found or no next item
  77. */
  78. public function testGetPreviousItemNotFound()
  79. {
  80. $this->assertFalse($this->_helper->getPreviousItemId(30));
  81. $this->assertFalse($this->_helper->getPreviousItemId(3));
  82. }
  83. }