Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EmptyGroupCategoryTest.php
Go to the documentation of this file.
1 <?php
7 
9 use PHPUnit_Framework_MockObject_MockObject as MockObject;
14 
15 class EmptyGroupCategoryTest extends \PHPUnit\Framework\TestCase
16 {
20  private $objectManagerHelper;
21 
25  private $collectionMock;
26 
30  private $urlBuilderMock;
31 
35  private $model;
36 
40  public function setUp()
41  {
42  $this->objectManagerHelper = new ObjectManager($this);
43 
44  $this->collectionMock = $this->getMockBuilder(Collection::class)
45  ->disableOriginalConstructor()
46  ->getMock();
47  $this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
48  ->getMockForAbstractClass();
49 
50  $this->model = new EmptyGroupCategory(
51  $this->collectionMock,
52  $this->urlBuilderMock
53  );
54  }
55 
61  public function testIsDisplayed($expected, array $items)
62  {
63  $this->collectionMock->expects($this->once())
64  ->method('setWithoutAssignedCategoryFilter')
65  ->willReturnSelf();
66  $this->collectionMock->expects($this->once())
67  ->method('getItems')
68  ->willReturn($items);
69  $this->assertEquals($expected, $this->model->isDisplayed());
70  }
71 
72  public function testGetIdentity()
73  {
74  $this->assertEquals($this->model->getIdentity(), 'empty_assigned_group_category');
75  }
76 
77  public function testGetText()
78  {
79  $groupMock1 = $this->getGroupMock(1, 'groupName1');
80  $groupMock2 = $this->getGroupMock(2, 'groupName2');
81 
82  $this->collectionMock->expects($this->once())
83  ->method('setWithoutAssignedCategoryFilter')
84  ->willReturnSelf();
85  $this->collectionMock->expects($this->once())
86  ->method('getItems')
87  ->willReturn([$groupMock1, $groupMock2]);
88  $this->urlBuilderMock->expects($this->exactly(2))
89  ->method('getUrl')
90  ->withConsecutive(
91  ['adminhtml/system_store/editGroup', ['group_id' => 1]],
92  ['adminhtml/system_store/editGroup', ['group_id' => 2]]
93  )
94  ->willReturnOnConsecutiveCalls(
95  'http://url1.com',
96  'http://url2.com'
97  );
98 
99  $this->assertEquals(
100  'The following stores are not associated with a root category: <a href="http://url1.com">groupName1</a>, '
101  . '<a href="http://url2.com">groupName2</a>. For the store to be displayed in the storefront, '
102  . 'it must be associated with a root category.',
103  $this->model->getText()->getText()
104  );
105  }
106 
114  private function getGroupMock($id, $name)
115  {
116  $groupMock = $this->getMockBuilder(Group::class)
117  ->disableOriginalConstructor()
118  ->getMock();
119  $groupMock->expects($this->once())
120  ->method('getId')
121  ->willReturn($id);
122  $groupMock->expects($this->once())
123  ->method('getName')
124  ->willReturn($name);
125 
126  return $groupMock;
127  }
128 
129  public function testGetSeverity()
130  {
131  $this->assertEquals($this->model->getSeverity(), 2);
132  }
133 
137  public function isDisplayedDataProvider()
138  {
139  return [
140  [
141  false,
142  []
143  ],
144  [
145  true,
146  ['test']
147  ]
148  ];
149  }
150 }
$id
Definition: fieldset.phtml:14
$items
if(!isset($_GET['name'])) $name
Definition: log.php:14