-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from magento-south/MAGETWO-24139
Stories: * MAGETWO-24139: Resolve TODO's related to Customer Service or create stories to resolve them * MAGETWO-56007: Initialize default values in customer custom attributes metadata * MAGETWO-56008: Moving getStoreByWebsite to Store Module
- Loading branch information
Showing
14 changed files
with
437 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
app/code/Magento/Customer/Test/Unit/Model/AttributeMetadatConverterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Test\Unit\Model; | ||
|
||
use Magento\Customer\Api\Data\OptionInterfaceFactory; | ||
use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory; | ||
use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory; | ||
use Magento\Customer\Model\AttributeMetadataConverter; | ||
|
||
/** | ||
* Class AttributeMetadataConverterTest | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
* @package Magento\Customer\Test\Unit\Model | ||
*/ | ||
class AttributeMetadatConverterTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var OptionInterfaceFactory | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $optionFactory; | ||
|
||
/** | ||
* @var ValidationRuleInterfaceFactory | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $validationRuleFactory; | ||
|
||
/** | ||
* @var AttributeMetadataInterfaceFactory | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $attributeMetadataFactory; | ||
|
||
/** | ||
* @var \Magento\Framework\Api\DataObjectHelper | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $dataObjectHelper; | ||
|
||
/** @var AttributeMetadataConverter */ | ||
private $model; | ||
|
||
/** @var \Magento\Customer\Model\Attribute | \PHPUnit_Framework_MockObject_MockObject */ | ||
private $attribute; | ||
|
||
public function setUp() | ||
{ | ||
$this->optionFactory = $this->getMockBuilder(OptionInterfaceFactory::class) | ||
->setMethods(['create']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->validationRuleFactory = $this->getMockBuilder(ValidationRuleInterfaceFactory::class) | ||
->setMethods(['create']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->attributeMetadataFactory = $this->getMockBuilder(AttributeMetadataInterfaceFactory::class) | ||
->setMethods(['create']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->dataObjectHelper = $this->getMockBuilder(\Magento\Framework\Api\DataObjectHelper::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->attribute = $this->getMockBuilder(\Magento\Customer\Model\Attribute::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->model = new AttributeMetadataConverter( | ||
$this->optionFactory, | ||
$this->validationRuleFactory, | ||
$this->attributeMetadataFactory, | ||
$this->dataObjectHelper | ||
); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function prepareValidateRules() | ||
{ | ||
return [ | ||
'one' => 'numeric', | ||
'two' => 'alphanumeric' | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function prepareOptions() | ||
{ | ||
return [ | ||
[ | ||
'label' => 'few_values', | ||
'value' => [ | ||
[1], [2] | ||
] | ||
], | ||
[ | ||
'label' => 'one_value', | ||
'value' => 1 | ||
] | ||
]; | ||
} | ||
|
||
public function testCreateAttributeMetadataTestWithSource() | ||
{ | ||
$validatedRules = $this->prepareValidateRules(); | ||
$options = $this->prepareOptions(); | ||
$optionDataObjectForSimpleValue1 = $this->getMockBuilder(\Magento\Customer\Model\Data\Option::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$optionDataObjectForSimpleValue2 = $this->getMockBuilder(\Magento\Customer\Model\Data\Option::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$optionObject1 = $this->getMock(\Magento\Customer\Api\Data\OptionInterface::class); | ||
$optionObject2 = $this->getMock(\Magento\Customer\Api\Data\OptionInterface::class); | ||
$this->optionFactory->expects($this->exactly(4)) | ||
->method('create') | ||
->will( | ||
$this->onConsecutiveCalls( | ||
$optionDataObjectForSimpleValue2, | ||
$optionObject1, | ||
$optionObject2, | ||
$optionDataObjectForSimpleValue1 | ||
) | ||
); | ||
$source = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Source\AbstractSource::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$source->expects($this->once()) | ||
->method('getAllOptions') | ||
->willReturn($options); | ||
$this->attribute->expects($this->once()) | ||
->method('usesSource') | ||
->willReturn(true); | ||
$this->attribute->expects($this->once()) | ||
->method('getSource') | ||
->willReturn($source); | ||
$optionDataObjectForSimpleValue1->expects($this->once()) | ||
->method('setValue') | ||
->with(1); | ||
$optionDataObjectForSimpleValue2->expects($this->once()) | ||
->method('setLabel') | ||
->with('few_values'); | ||
$optionDataObjectForSimpleValue1->expects($this->once()) | ||
->method('setLabel') | ||
->with('one_value'); | ||
$this->dataObjectHelper->expects($this->exactly(2)) | ||
->method('populateWithArray') | ||
->withConsecutive( | ||
[$optionObject1, ['1'], \Magento\Customer\Api\Data\OptionInterface::class], | ||
[$optionObject2, ['2'], \Magento\Customer\Api\Data\OptionInterface::class] | ||
); | ||
$validationRule1 = $this->getMock(\Magento\Customer\Api\Data\ValidationRuleInterface::class); | ||
$validationRule2 = $this->getMock(\Magento\Customer\Api\Data\ValidationRuleInterface::class); | ||
$this->validationRuleFactory->expects($this->exactly(2)) | ||
->method('create') | ||
->will($this->onConsecutiveCalls($validationRule1, $validationRule2)); | ||
$validationRule1->expects($this->once()) | ||
->method('setValue') | ||
->with('numeric'); | ||
$validationRule1->expects($this->once()) | ||
->method('setName') | ||
->with('one') | ||
->willReturnSelf(); | ||
$validationRule2->expects($this->once()) | ||
->method('setValue') | ||
->with('alphanumeric'); | ||
$validationRule2->expects($this->once()) | ||
->method('setName') | ||
->with('two') | ||
->willReturnSelf(); | ||
$attributeMetaData = $this->getMockBuilder(\Magento\Customer\Model\Data\AttributeMetadata::class) | ||
->disableOriginalConstructor() | ||
->enableProxyingToOriginalMethods() | ||
->getMock(); | ||
$this->attribute->expects($this->once()) | ||
->method('getValidateRules') | ||
->willReturn($validatedRules); | ||
$this->attributeMetadataFactory->expects($this->once()) | ||
->method('create') | ||
->willReturn($attributeMetaData); | ||
$frontend = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->attribute->expects($this->once()) | ||
->method('getFrontend') | ||
->willReturn($frontend); | ||
$optionDataObjectForSimpleValue2->expects($this->once()) | ||
->method('setOptions') | ||
->with([$optionObject1, $optionObject2]); | ||
$this->model->createMetadataAttribute($this->attribute); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/code/Magento/Eav/Api/Data/AttributeDefaultValueInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Eav\Api\Data; | ||
|
||
/** | ||
* Interface AttributeDefaultValueInterface | ||
* Allows to manage attribute default value through interface | ||
* @api | ||
* @package Magento\Eav\Api\Data | ||
*/ | ||
interface AttributeDefaultValueInterface | ||
{ | ||
const DEFAULT_VALUE = "default_value"; | ||
|
||
/** | ||
* @param string $defaultValue | ||
* @return \Magento\Framework\Api\MetadataObjectInterface | ||
*/ | ||
public function setDefaultValue($defaultValue); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDefaultValue(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.