Skip to content

Commit f4ec5a3

Browse files
committed
MAGETWO-45133: Get json instead of normal page when trying to delete category after reset
1 parent c38de7c commit f4ec5a3

File tree

2 files changed

+48
-9
lines changed
  • app/code/Magento/Catalog

2 files changed

+48
-9
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Category/Edit/Form.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ protected function _prepareLayout()
9898
[
9999
'id' => 'delete',
100100
'label' => __('Delete Category'),
101-
'onclick' => "categoryDelete('" . $this->getUrl(
102-
'catalog/*/delete',
103-
['_current' => true]
104-
) . "')",
101+
'onclick' => "categoryDelete('" . $this->getDeleteUrl() . "')",
105102
'class' => 'delete'
106103
]
107104
);
@@ -115,7 +112,7 @@ protected function _prepareLayout()
115112
[
116113
'id' => 'reset',
117114
'label' => __('Reset'),
118-
'onclick' => "categoryReset('" . $this->getUrl($resetPath, ['_current' => true]) . "',true)",
115+
'onclick' => "categoryReset('" . $this->getUrl($resetPath, $this->getDefaultUrlParams()) . "',true)",
119116
'class' => 'reset'
120117
]
121118
);
@@ -259,8 +256,7 @@ public function getHeader()
259256
*/
260257
public function getDeleteUrl(array $args = [])
261258
{
262-
$params = ['_current' => true];
263-
$params = array_merge($params, $args);
259+
$params = array_merge($this->getDefaultUrlParams(), $args);
264260
return $this->getUrl('catalog/*/delete', $params);
265261
}
266262

@@ -272,8 +268,7 @@ public function getDeleteUrl(array $args = [])
272268
*/
273269
public function getRefreshPathUrl(array $args = [])
274270
{
275-
$params = ['_current' => true];
276-
$params = array_merge($params, $args);
271+
$params = array_merge($this->getDefaultUrlParams(), $args);
277272
return $this->getUrl('catalog/*/refreshPath', $params);
278273
}
279274

@@ -359,4 +354,12 @@ protected function getButtonChildBlock($childId, $blockClassName = null)
359354
}
360355
return $this->getLayout()->createBlock($blockClassName, $this->getNameInLayout() . '-' . $childId);
361356
}
357+
358+
/**
359+
* @return array
360+
*/
361+
protected function getDefaultUrlParams()
362+
{
363+
return ['_current' => true, '_query' => ['isAjax' => null]];
364+
}
362365
}

app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Category/Edit/FormTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class FormTest extends \PHPUnit_Framework_TestCase
5050
*/
5151
protected $requestMock;
5252

53+
/**
54+
* @var \Magento\Framework\UrlInterface|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $urlBuilderMock;
57+
5358
/**
5459
* Set up
5560
*
@@ -103,9 +108,16 @@ protected function setUp()
103108
['getParam']
104109
);
105110

111+
$this->urlBuilderMock = $this->getMockBuilder('Magento\Framework\UrlInterface')
112+
->disableOriginalConstructor()
113+
->getMockForAbstractClass();
114+
106115
$this->contextMock->expects($this->any())
107116
->method('getRequest')
108117
->will($this->returnValue($this->requestMock));
118+
$this->contextMock->expects($this->any())
119+
->method('getUrlBuilder')
120+
->will($this->returnValue($this->urlBuilderMock));
109121

110122
$this->form = $this->objectManager->getObject(
111123
'Magento\Catalog\Block\Adminhtml\Category\Edit\Form',
@@ -148,4 +160,28 @@ public function testGetCategoryId()
148160

149161
$this->assertEquals(789, $this->form->getCategoryId());
150162
}
163+
164+
public function testGetDeleteUrl()
165+
{
166+
$url = 'some/magento/delete/url';
167+
$params = ['property' => 'value'];
168+
$this->urlBuilderMock->expects($this->once())
169+
->method('getUrl')
170+
->with('catalog/*/delete', ['_current' => true, '_query' => ['isAjax' => null], 'property' => 'value'])
171+
->willReturn($url);
172+
173+
$this->assertEquals($url, $this->form->getDeleteUrl($params));
174+
}
175+
176+
public function testGetRefreshPathUrl()
177+
{
178+
$url = 'some/magento/refresh/path/url';
179+
$params = ['argument' => 'value'];
180+
$this->urlBuilderMock->expects($this->once())
181+
->method('getUrl')
182+
->with('catalog/*/refreshPath', ['_current' => true, '_query' => ['isAjax' => null], 'argument' => 'value'])
183+
->willReturn($url);
184+
185+
$this->assertEquals($url, $this->form->getRefreshPathUrl($params));
186+
}
151187
}

0 commit comments

Comments
 (0)