ToolbarEntryTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Test class for \Magento\AdminNotification\Block\ToolbarEntry
  8. */
  9. namespace Magento\AdminNotification\Test\Unit\Block;
  10. class ToolbarEntryTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Retrieve toolbar entry block instance
  14. *
  15. * @param int $unreadNotifications number of unread notifications
  16. * @return \Magento\AdminNotification\Block\ToolbarEntry
  17. */
  18. protected function _getBlockInstance($unreadNotifications)
  19. {
  20. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  21. // mock collection of unread notifications
  22. $notificationList = $this->createPartialMock(
  23. \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class,
  24. ['getSize', 'setCurPage', 'setPageSize']
  25. );
  26. $notificationList->expects($this->any())->method('getSize')->will($this->returnValue($unreadNotifications));
  27. $block = $objectManagerHelper->getObject(
  28. \Magento\AdminNotification\Block\ToolbarEntry::class,
  29. ['notificationList' => $notificationList]
  30. );
  31. return $block;
  32. }
  33. public function testGetUnreadNotificationCount()
  34. {
  35. $notificationsCount = 100;
  36. $block = $this->_getBlockInstance($notificationsCount);
  37. $this->assertEquals($notificationsCount, $block->getUnreadNotificationCount());
  38. }
  39. public function testGetLatestUnreadNotifications()
  40. {
  41. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  42. // 1. Create mocks
  43. $notificationList = $this->getMockBuilder(
  44. \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class
  45. )
  46. ->disableOriginalConstructor()
  47. ->getMock();
  48. /** @var \Magento\AdminNotification\Block\ToolbarEntry $model */
  49. $model = $helper->getObject(
  50. \Magento\AdminNotification\Block\ToolbarEntry::class,
  51. ['notificationList' => $notificationList]
  52. );
  53. // 2. Set expectations
  54. $notificationList->expects($this->atLeastOnce())
  55. ->method('setPageSize')
  56. ->with(\Magento\AdminNotification\Block\ToolbarEntry::NOTIFICATIONS_NUMBER)
  57. ->will($this->returnSelf());
  58. // 3. Run tested method
  59. $result = $model->getLatestUnreadNotifications();
  60. // 4. Compare actual result with expected result
  61. $this->assertEquals($notificationList, $result);
  62. }
  63. }