Skip to content

Commit 0bb57a6

Browse files
author
Oleksandr Dubovyk
committed
Merge remote-tracking branch 'troll/MAGETWO-61274' into troll-bugfix-pr
2 parents 60be232 + 3c582ce commit 0bb57a6

File tree

5 files changed

+155
-27
lines changed

5 files changed

+155
-27
lines changed

app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/SelectAttributes.php

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(
2828
\Magento\Framework\Registry $registry
2929
) {
3030
parent::__construct($context);
31-
$this->registry = $registry;
31+
$this->coreRegistry = $registry;
3232
}
3333

3434
/**
@@ -43,31 +43,35 @@ public function getAddNewAttributeButton($dataProvider = '')
4343
$attributeCreate = $this->getLayout()->createBlock(
4444
\Magento\Backend\Block\Widget\Button::class
4545
);
46-
$attributeCreate->setDataAttribute(
47-
[
48-
'mage-init' => [
49-
'productAttributes' => [
50-
'dataProvider' => $dataProvider,
51-
'url' => $this->getUrl('catalog/product_attribute/new', [
52-
'store' => $this->registry->registry('current_product')->getStoreId(),
53-
'product_tab' => 'variations',
54-
'popup' => 1,
55-
'_query' => [
56-
'attribute' => [
57-
'is_global' => 1,
58-
'frontend_input' => 'select',
46+
if ($attributeCreate->getAuthorization()->isAllowed('Magento_Catalog::attributes_attributes')) {
47+
$attributeCreate->setDataAttribute(
48+
[
49+
'mage-init' => [
50+
'productAttributes' => [
51+
'dataProvider' => $dataProvider,
52+
'url' => $this->getUrl('catalog/product_attribute/new', [
53+
'store' => $this->coreRegistry->registry('current_product')->getStoreId(),
54+
'product_tab' => 'variations',
55+
'popup' => 1,
56+
'_query' => [
57+
'attribute' => [
58+
'is_global' => 1,
59+
'frontend_input' => 'select',
60+
],
5961
],
60-
],
61-
]),
62+
]),
63+
],
6264
],
63-
],
64-
]
65-
)->setType(
66-
'button'
67-
)->setLabel(
68-
__('Create New Attribute')
69-
);
70-
return $attributeCreate->toHtml();
65+
]
66+
)->setType(
67+
'button'
68+
)->setLabel(
69+
__('Create New Attribute')
70+
);
71+
return $attributeCreate->toHtml();
72+
} else {
73+
return '';
74+
}
7175
}
7276

7377
/**

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/CreateOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CreateOptions extends Action
1616
*
1717
* @see _isAllowed()
1818
*/
19-
const ADMIN_RESOURCE = 'Magento_Catalog::attributes_attributes';
19+
const ADMIN_RESOURCE = 'Magento_Catalog::products';
2020

2121
/**
2222
* @var \Magento\Framework\Json\Helper\Data

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/GetAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GetAttributes extends Action
1616
*
1717
* @see _isAllowed()
1818
*/
19-
const ADMIN_RESOURCE = 'Magento_Catalog::attributes_attributes';
19+
const ADMIN_RESOURCE = 'Magento_Catalog::products';
2020

2121
/**
2222
* Store manager

app/code/Magento/ConfigurableProduct/Controller/Adminhtml/Product/Attribute/SuggestConfigurableAttributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SuggestConfigurableAttributes extends Action
1616
*
1717
* @see _isAllowed()
1818
*/
19-
const ADMIN_RESOURCE = 'Magento_Catalog::attributes_attributes';
19+
const ADMIN_RESOURCE = 'Magento_Catalog::products';
2020

2121
/**
2222
* @var \Magento\ConfigurableProduct\Model\SuggestedAttributeList
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\ConfigurableProduct\Test\Unit\Block\Adminhtml\Product\Steps;
7+
8+
use Magento\ConfigurableProduct\Block\Adminhtml\Product\Steps\SelectAttributes;
9+
use Magento\Framework\View\Element\Template\Context;
10+
use Magento\Framework\Registry;
11+
use Magento\Backend\Block\Widget\Button;
12+
use Magento\Framework\View\LayoutInterface;
13+
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Framework\UrlInterface;
15+
16+
class SelectAttributesTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var SelectAttributes
20+
*/
21+
private $selectAttributes;
22+
23+
/**
24+
* @var Context|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $contextMock;
27+
28+
/**
29+
* @var Registry|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $registryMock;
32+
33+
/**
34+
* @var Button|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
private $buttonMock;
37+
38+
/**
39+
* @var LayoutInterface|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
private $layoutMock;
42+
43+
/**
44+
* @var UrlInterface|\PHPUnit_Framework_MockObject_MockObject
45+
*/
46+
private $urlBuilderMock;
47+
48+
/**
49+
* {@inheritDoc}
50+
*/
51+
protected function setUp()
52+
{
53+
$this->contextMock = $this->getMockBuilder(Context::class)
54+
->disableOriginalConstructor()
55+
->getMock();
56+
$this->registryMock = $this->getMockBuilder(Registry::class)
57+
->getMock();
58+
$this->buttonMock = $this->getMockBuilder(Button::class)
59+
->disableOriginalConstructor()
60+
->setMethods(['isAllowed', 'getAuthorization', 'toHtml'])
61+
->getMock();
62+
$this->layoutMock = $this->getMockBuilder(LayoutInterface::class)
63+
->disableOriginalConstructor()
64+
->getMock();
65+
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
66+
->disableOriginalConstructor()
67+
->getMock();
68+
69+
$this->contextMock->expects($this->any())
70+
->method('getLayout')
71+
->willReturn($this->layoutMock);
72+
$this->contextMock->expects($this->any())
73+
->method('getUrlBuilder')
74+
->willReturn($this->urlBuilderMock);
75+
76+
$this->selectAttributes = new SelectAttributes(
77+
$this->contextMock,
78+
$this->registryMock
79+
);
80+
}
81+
82+
/**
83+
* @param bool $isAllowed
84+
* @param string $result
85+
*
86+
* @dataProvider attributesDataProvider
87+
*
88+
* @return void
89+
*/
90+
public function testGetAddNewAttributeButton($isAllowed, $result)
91+
{
92+
$productMock = $this->getMockBuilder(ProductInterface::class)
93+
->setMethods(['getStoreId'])
94+
->getMockForAbstractClass();
95+
$this->registryMock->expects($this->any())
96+
->method('registry')
97+
->with('current_product')
98+
->willReturn($productMock);
99+
$this->buttonMock->expects($this->any())
100+
->method('toHtml')
101+
->willReturn($result);
102+
103+
$this->layoutMock->expects($this->once())
104+
->method('createBlock')
105+
->willReturn($this->buttonMock);
106+
$this->buttonMock->expects($this->once())
107+
->method('getAuthorization')
108+
->willReturnSelf();
109+
$this->buttonMock->expects($this->once())
110+
->method('isAllowed')
111+
->with('Magento_Catalog::attributes_attributes')
112+
->willReturn($isAllowed);
113+
114+
$this->assertEquals($result, $this->selectAttributes->getAddNewAttributeButton());
115+
}
116+
117+
public function attributesDataProvider()
118+
{
119+
return [
120+
[false, ''],
121+
[true, 'attribute html']
122+
];
123+
}
124+
}

0 commit comments

Comments
 (0)