Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ToolbarEntryTest.php
Go to the documentation of this file.
1 <?php
11 
12 class ToolbarEntryTest extends \PHPUnit\Framework\TestCase
13 {
20  protected function _getBlockInstance($unreadNotifications)
21  {
22  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23  // mock collection of unread notifications
24  $notificationList = $this->createPartialMock(
25  \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class,
26  ['getSize', 'setCurPage', 'setPageSize']
27  );
28  $notificationList->expects($this->any())->method('getSize')->will($this->returnValue($unreadNotifications));
29 
30  $block = $objectManagerHelper->getObject(
31  \Magento\AdminNotification\Block\ToolbarEntry::class,
32  ['notificationList' => $notificationList]
33  );
34 
35  return $block;
36  }
37 
39  {
40  $notificationsCount = 100;
41  $block = $this->_getBlockInstance($notificationsCount);
42  $this->assertEquals($notificationsCount, $block->getUnreadNotificationCount());
43  }
44 
45  public function testGetLatestUnreadNotifications()
46  {
47  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
48 
49  // 1. Create mocks
50  $notificationList = $this->getMockBuilder(
51  \Magento\AdminNotification\Model\ResourceModel\Inbox\Collection\Unread::class
52  )
53  ->disableOriginalConstructor()
54  ->getMock();
55 
57  $model = $helper->getObject(
58  \Magento\AdminNotification\Block\ToolbarEntry::class,
59  ['notificationList' => $notificationList]
60  );
61 
62  // 2. Set expectations
63  $notificationList->expects($this->atLeastOnce())
64  ->method('setPageSize')
65  ->with(\Magento\AdminNotification\Block\ToolbarEntry::NOTIFICATIONS_NUMBER)
66  ->will($this->returnSelf());
67 
68  // 3. Run tested method
69  $result = $model->getLatestUnreadNotifications();
70 
71  // 4. Compare actual result with expected result
72  $this->assertEquals($notificationList, $result);
73  }
74 }
$helper
Definition: iframe.phtml:13
$block
Definition: block.php:8
testGetUnreadNotificationCount()
_getBlockInstance($unreadNotifications)