Skip to content

Commit 212c93a

Browse files
committed
MAGETWO-62253: Refactor code to remove unserialize
- fixed tests
1 parent 7b76e12 commit 212c93a

File tree

2 files changed

+63
-11
lines changed

2 files changed

+63
-11
lines changed

app/code/Magento/Backend/Test/Unit/Model/MenuTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,14 +368,9 @@ public function testUnserialize()
368368
->method('unserialize')
369369
->willReturn([['unserializedData']]);
370370
$menuItemFactoryMock = $this->getMock(Factory::class, [], [], '', false);
371-
$menuItemMock = $this->getMock(Item::class, [], [], '', false);
372371
$menuItemFactoryMock->expects($this->once())
373372
->method('create')
374-
->willReturn($menuItemMock);
375-
$menuItemMock->expects($this->once())
376-
->method('populateFromArray')
377-
->with(['unserializedData'])
378-
->willReturn($this);
373+
->with(['unserializedData']);
379374
$menu = $this->objectManagerHelper->getObject(
380375
\Magento\Backend\Model\Menu::class,
381376
[

dev/tests/integration/testsuite/Magento/Backend/Model/MenuTest.php

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ public function testMenuItemManipulation()
7878
$menu->move('Magento_Catalog::catalog_products', 'Magento_Backend::system2');
7979
}
8080

81-
public function testSerializeUnserialize()
81+
/**
82+
* @magentoAppIsolation enabled
83+
*/
84+
public function testSerialize()
8285
{
8386
/** @var Menu $menu */
8487
$menu = $this->objectManager->get(\Magento\Backend\Model\MenuFactory::class)->create();
@@ -111,9 +114,63 @@ public function testSerializeUnserialize()
111114
'Magento_Backend::system3'
112115
);
113116
$serializedString = $menu->serialize();
114-
/** @var Menu $unserializedMenu */
115-
$unserializedMenu = $this->objectManager->get(\Magento\Backend\Model\MenuFactory::class)->create();
116-
$unserializedMenu->unserialize($serializedString);
117-
$this->assertEquals($menu, $unserializedMenu);
117+
$expected = '[{"parent_id":null,"module_name":"Magento_Backend","sort_index":null,"depends_on_config":null,'
118+
. '"id":"Magento_Backend::system3","resource":"Magento_Backend::system3","path":"","action":null,'
119+
. '"depends_on_module":null,"tooltip":"","title":"Extended System",'
120+
. '"sub_menu":[{"parent_id":null,"module_name":"Magento_Backend","sort_index":null,'
121+
. '"depends_on_config":null,"id":"Magento_Backend::system3_acl","resource":"Magento_Backend::system3_acl",'
122+
. '"path":"","action":"admin\/backend\/acl\/index","depends_on_module":null,"tooltip":"","title":"Acl",'
123+
. '"sub_menu":null}]}]';
124+
$this->assertEquals($expected, $serializedString);
125+
}
126+
127+
/**
128+
* @magentoAppIsolation enabled
129+
*/
130+
public function testUnserialize()
131+
{
132+
$serializedMenu = '[{"parent_id":null,"module_name":"Magento_Backend","sort_index":null,'
133+
. '"depends_on_config":null,"id":"Magento_Backend::system3","resource":"Magento_Backend::system3",'
134+
. '"path":"","action":null,"depends_on_module":null,"tooltip":"","title":"Extended System",'
135+
. '"sub_menu":[{"parent_id":null,"module_name":"Magento_Backend","sort_index":null,'
136+
. '"depends_on_config":null,"id":"Magento_Backend::system3_acl","resource":"Magento_Backend::system3_acl",'
137+
. '"path":"","action":"admin\/backend\/acl\/index","depends_on_module":null,"tooltip":"","title":"Acl",'
138+
. '"sub_menu":null}]}]';
139+
/** @var Menu $menu */
140+
$menu = $this->objectManager->get(\Magento\Backend\Model\MenuFactory::class)->create();
141+
$menu->unserialize($serializedMenu);
142+
$expected = [
143+
[
144+
'parent_id' => null,
145+
'module_name' => 'Magento_Backend',
146+
'sort_index' => null,
147+
'depends_on_config' => null,
148+
'id' => 'Magento_Backend::system3',
149+
'resource' => 'Magento_Backend::system3',
150+
'path' => '',
151+
'action' => null,
152+
'depends_on_module' => null,
153+
'tooltip' => '',
154+
'title' => 'Extended System',
155+
'sub_menu' =>
156+
[
157+
[
158+
'parent_id' => null,
159+
'module_name' => 'Magento_Backend',
160+
'sort_index' => null,
161+
'depends_on_config' => null,
162+
'id' => 'Magento_Backend::system3_acl',
163+
'resource' => 'Magento_Backend::system3_acl',
164+
'path' => '',
165+
'action' => 'admin/backend/acl/index',
166+
'depends_on_module' => null,
167+
'tooltip' => '',
168+
'title' => 'Acl',
169+
'sub_menu' => null,
170+
],
171+
],
172+
],
173+
];
174+
$this->assertEquals($expected, $menu->toArray());
118175
}
119176
}

0 commit comments

Comments
 (0)