35 $this->markTestSkipped(
'Due to MAGETWO-48956');
36 $this->_objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
37 $this->_scopeConfig = $this->createMock(\
Magento\Framework\
App\
Config\ScopeConfigInterface::class);
38 $this->_model = $this->_objectHelper->getObject(
40 [
'scopeConfig' => $this->_scopeConfig]
42 $this->_attribute = $this->createPartialMock(
56 $this->_model->setAttribute($this->_attribute);
67 $this->_attribute->expects($this->any())->method(
'getName')->will($this->returnValue(
$attributeCode));
68 $object = new \Magento\Framework\DataObject(
$data);
69 $this->_model->beforeSave($object);
80 'attribute with specified value' => [
82 [self::DEFAULT_ATTRIBUTE_CODE =>
'test_value'],
85 'attribute with default value' => [
87 [self::DEFAULT_ATTRIBUTE_CODE =>
null],
90 'attribute does not exist' => [
95 'attribute sort by empty' => [
97 [
'available_sort_by' =>
null],
100 'attribute sort by' => [
102 [
'available_sort_by' => [
'test',
'value']],
116 $this->_attribute->expects($this->any())->method(
'getName')->will($this->returnValue(
$attributeCode));
117 $object = new \Magento\Framework\DataObject(
$data);
118 $this->_model->afterLoad($object);
129 'attribute with specified value' => [
131 [self::DEFAULT_ATTRIBUTE_CODE =>
'test_value'],
134 'attribute sort by empty' => [
136 [
'available_sort_by' =>
null],
139 'attribute sort by' => [
141 [
'available_sort_by' =>
'test,value'],
155 $this->_attribute->expects($this->any())->method(
'getName')->will($this->returnValue(
$attributeData[
'code']));
157 ->expects($this->at(1))
158 ->method(
'getIsRequired')
161 ->expects($this->any())
162 ->method(
'isValueEmpty')
164 $object = new \Magento\Framework\DataObject(
$data);
165 $this->assertSame($expected, $this->_model->validate($object));
174 'is not required' => [
179 'required, empty, not use config case 1' => [
181 [self::DEFAULT_ATTRIBUTE_CODE => [],
'use_post_data_config' => []],
184 'required, empty, not use config case 2' => [
186 [self::DEFAULT_ATTRIBUTE_CODE => [],
'use_post_data_config' => [
'config']],
189 'required, empty, use config' => [
199 $this->_attribute->expects($this->any())->method(
'getName')->will($this->returnValue(
'attribute_name'));
200 $this->_attribute->expects($this->at(1))->method(
'getIsRequired');
201 $this->_attribute->expects($this->at(2))->method(
'getIsUnique')->will($this->returnValue(
true));
203 $entityMock = $this->getMockForAbstractClass(
204 \
Magento\Eav\Model\Entity\AbstractEntity::class,
210 [
'checkAttributeUniqueValue']
212 $this->_attribute->expects($this->any())->method(
'getEntity')->will($this->returnValue($entityMock));
213 $entityMock->expects($this->at(0))->method(
'checkAttributeUniqueValue')->will($this->returnValue(
true));
222 $this->_attribute->expects($this->any())->method(
'getName')->will($this->returnValue(
'attribute_name'));
223 $this->_attribute->expects($this->at(1))->method(
'getIsRequired');
224 $this->_attribute->expects($this->at(2))->method(
'getIsUnique')->will($this->returnValue(
true));
226 $entityMock = $this->getMockForAbstractClass(
227 \
Magento\Eav\Model\Entity\AbstractEntity::class,
233 [
'checkAttributeUniqueValue']
235 $frontMock = $this->getMockForAbstractClass(
244 $this->_attribute->expects($this->any())->method(
'getEntity')->will($this->returnValue($entityMock));
245 $this->_attribute->expects($this->any())->method(
'getFrontend')->will($this->returnValue($frontMock));
246 $entityMock->expects($this->at(0))->method(
'checkAttributeUniqueValue')->will($this->returnValue(
false));
257 $this->_attribute->expects($this->any())->method(
'getName')->will($this->returnValue(
$attributeCode));
258 $this->_scopeConfig->expects($this->any())->method(
'getValue')->will($this->returnValue(
'value2'));
259 $object = new \Magento\Framework\DataObject(
$data);
260 $this->assertTrue($this->_model->validate($object));
272 'available_sort_by' => [
'value1',
'value2'],
273 'default_sort_by' =>
'value2',
274 'use_post_data_config' => []
280 'available_sort_by' =>
'value1,value2',
281 'use_post_data_config' => [
'default_sort_by']
287 'available_sort_by' =>
null,
288 'default_sort_by' =>
null,
289 'use_post_data_config' => [
'available_sort_by',
'default_sort_by',
'filter_price_range']
303 $this->_attribute->expects($this->any())->method(
'getName')->will($this->returnValue(
$attributeCode));
304 $this->_scopeConfig->expects($this->any())->method(
'getValue')->will($this->returnValue(
'another value'));
305 $object = new \Magento\Framework\DataObject(
$data);
306 $this->_model->validate($object);
318 'available_sort_by' =>
null,
319 'use_post_data_config' => [
'default_sort_by']
325 'available_sort_by' =>
null,
326 'use_post_data_config' => []
332 'available_sort_by' => [
'value1',
'value2'],
333 'default_sort_by' =>
'another value',
334 'use_post_data_config' => []
340 'available_sort_by' =>
'value1',
341 'use_post_data_config' => []
testValidateDefaultSortException($attributeCode, $data)
testValidateDefaultSort($attributeCode, $data)
validateDefaultSortException()
testBeforeSave($attributeCode, $data, $expected)
const DEFAULT_ATTRIBUTE_CODE
testAfterLoad($attributeCode, $data, $expected)
validateDefaultSortDataProvider()
testValidateUniqueException()
testValidate($attributeData, $data, $expected)