Skip to content

Commit 57cf3d8

Browse files
committed
Merge remote-tracking branch 'nord/MAGETWO-37045' into MAGETWO-37718
2 parents c54445e + ce6d3a7 commit 57cf3d8

File tree

2 files changed

+103
-0
lines changed
  • app/code/Magento/Catalog

2 files changed

+103
-0
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Advanced.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ protected function _prepareForm()
194194
);
195195

196196
$this->_eventManager->dispatch('product_attribute_form_build', ['form' => $form]);
197+
if ($attributeObject->getId() && !$attributeObject->getIsUserDefined()) {
198+
$form->getElement('is_global')->setDisabled(1);
199+
}
197200
$this->setForm($form);
198201
return $this;
199202
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Block\Adminhtml\Product\Attribute\Edit\Tab;
7+
8+
class AdvancedTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Catalog\Block\Adminhtml\Product\Attribute\Grid
12+
*/
13+
protected $block;
14+
15+
/**
16+
* @var \Magento\Framework\Data\FormFactory|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $formFactory;
19+
20+
/**
21+
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $registry;
24+
25+
/**
26+
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $localeDate;
29+
30+
/**
31+
* @var \Magento\Config\Model\Config\Source\Yesno|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $yesNo;
34+
35+
/**
36+
* @var \Magento\Eav\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $eavData;
39+
40+
/**
41+
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
protected $filesystem;
44+
45+
protected function setUp()
46+
{
47+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
48+
$this->registry = $this->getMock('\Magento\Framework\Registry');
49+
$this->formFactory = $this->getMock('Magento\Framework\Data\FormFactory', [], [], '', false);
50+
$this->yesNo = $this->getMock('Magento\Config\Model\Config\Source\Yesno');
51+
$this->localeDate = $this->getMock('Magento\Framework\Stdlib\DateTime\TimezoneInterface');
52+
$this->eavData = $this->getMock('Magento\Eav\Helper\Data', [], [], '', false);
53+
$this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
54+
55+
$this->block = $objectManager->getObject(
56+
'Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab\Advanced',
57+
[
58+
'registry' => $this->registry,
59+
'formFactory' => $this->formFactory,
60+
'localeDate' => $this->localeDate,
61+
'yesNo' => $this->yesNo,
62+
'eavData' => $this->eavData,
63+
'filesystem' => $this->filesystem
64+
]
65+
);
66+
}
67+
68+
public function testToHtml()
69+
{
70+
$fieldSet = $this->getMock('Magento\Framework\Data\Form\Element\Fieldset', [], [], '', false);
71+
$form = $this->getMock('Magento\Framework\Data\Form', [], [], '', false);
72+
$attributeModel = $this->getMock('\Magento\Catalog\Model\Resource\Eav\Attribute', [], [], '', false);
73+
$entityType = $this->getMock('Magento\Eav\Model\Entity\Type', [], [], '', false);
74+
$formElement = $this->getMock('Magento\Framework\Data\Form\Element\Text', ['setDisabled'], [], '', false);
75+
$directoryReadInterface = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface');
76+
77+
$this->registry->expects($this->any())->method('registry')->with('entity_attribute')
78+
->willReturn($attributeModel);
79+
$this->formFactory->expects($this->any())->method('create')->willReturn($form);
80+
$form->expects($this->any())->method('addFieldset')->willReturn($fieldSet);
81+
$form->expects($this->any())->method('getElement')->willReturn($formElement);
82+
$fieldSet->expects($this->any())->method('addField')->willReturnSelf();
83+
$attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
84+
$attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf();
85+
$attributeModel->expects($this->any())->method('getId')->willReturn(1);
86+
$attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType);
87+
$attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false);
88+
$attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code');
89+
$this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy');
90+
$entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code');
91+
$this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]);
92+
$formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf();
93+
$this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']);
94+
$this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface);
95+
$directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path');
96+
97+
$this->block->setData(['action' => 'save']);
98+
$this->block->toHtml();
99+
}
100+
}

0 commit comments

Comments
 (0)