8 use Magento\Customer\Api\Data\OptionInterfaceFactory;
9 use Magento\Customer\Api\Data\ValidationRuleInterfaceFactory;
10 use Magento\Customer\Api\Data\AttributeMetadataInterfaceFactory;
23 private $optionFactory;
28 private $validationRuleFactory;
33 private $attributeMetadataFactory;
38 private $dataObjectHelper;
48 $this->optionFactory = $this->getMockBuilder(OptionInterfaceFactory::class)
49 ->setMethods([
'create'])
50 ->disableOriginalConstructor()
52 $this->validationRuleFactory = $this->getMockBuilder(ValidationRuleInterfaceFactory::class)
53 ->setMethods([
'create'])
54 ->disableOriginalConstructor()
56 $this->attributeMetadataFactory = $this->getMockBuilder(AttributeMetadataInterfaceFactory::class)
57 ->setMethods([
'create'])
58 ->disableOriginalConstructor()
60 $this->dataObjectHelper = $this->getMockBuilder(\
Magento\Framework\Api\DataObjectHelper::class)
61 ->disableOriginalConstructor()
63 $this->attribute = $this->getMockBuilder(\
Magento\
Customer\Model\Attribute::class)
64 ->disableOriginalConstructor()
69 $this->validationRuleFactory,
70 $this->attributeMetadataFactory,
71 $this->dataObjectHelper
78 private function prepareValidateRules()
82 'two' =>
'alphanumeric' 89 private function prepareOptions()
93 'label' =>
'few_values',
99 'label' =>
'one_value',
107 $validatedRules = $this->prepareValidateRules();
109 $optionDataObjectForSimpleValue1 = $this->getMockBuilder(\
Magento\
Customer\Model\Data\Option::class)
110 ->disableOriginalConstructor()
112 $optionDataObjectForSimpleValue2 = $this->getMockBuilder(\
Magento\
Customer\Model\Data\Option::class)
113 ->disableOriginalConstructor()
115 $optionObject1 = $this->createMock(\
Magento\
Customer\Api\Data\OptionInterface::class);
116 $optionObject2 = $this->createMock(\
Magento\
Customer\Api\Data\OptionInterface::class);
117 $this->optionFactory->expects($this->exactly(4))
120 $this->onConsecutiveCalls(
121 $optionDataObjectForSimpleValue2,
124 $optionDataObjectForSimpleValue1
128 ->disableOriginalConstructor()
130 $source->expects($this->once())
131 ->method(
'getAllOptions')
133 $this->attribute->expects($this->once())
134 ->method(
'usesSource')
136 $this->attribute->expects($this->once())
137 ->method(
'getSource')
139 $optionDataObjectForSimpleValue1->expects($this->once())
142 $optionDataObjectForSimpleValue2->expects($this->once())
144 ->with(
'few_values');
145 $optionDataObjectForSimpleValue1->expects($this->once())
148 $this->dataObjectHelper->expects($this->exactly(2))
149 ->method(
'populateWithArray')
151 [$optionObject1, [
'1'], \
Magento\
Customer\Api\Data\OptionInterface::class],
152 [$optionObject2, [
'2'], \
Magento\
Customer\Api\Data\OptionInterface::class]
154 $validationRule1 = $this->createMock(\
Magento\
Customer\Api\Data\ValidationRuleInterface::class);
155 $validationRule2 = $this->createMock(\
Magento\
Customer\Api\Data\ValidationRuleInterface::class);
156 $this->validationRuleFactory->expects($this->exactly(2))
158 ->will($this->onConsecutiveCalls($validationRule1, $validationRule2));
159 $validationRule1->expects($this->once())
162 $validationRule1->expects($this->once())
166 $validationRule2->expects($this->once())
168 ->with(
'alphanumeric');
169 $validationRule2->expects($this->once())
174 $mockMethods = [
'setAttributeCode',
'setFrontendInput'];
175 $attributeMetaData = $this->getMockBuilder(\
Magento\
Customer\Model\Data\AttributeMetadata::class)
176 ->setMethods($mockMethods)
177 ->disableOriginalConstructor()
179 foreach ($mockMethods as
$method) {
180 $attributeMetaData->expects($this->once())->method(
$method)->willReturnSelf();
183 $this->attribute->expects($this->once())
184 ->method(
'getValidateRules')
185 ->willReturn($validatedRules);
186 $this->attributeMetadataFactory->expects($this->once())
188 ->willReturn($attributeMetaData);
189 $frontend = $this->getMockBuilder(\
Magento\Eav\Model\Entity\
Attribute\Frontend\AbstractFrontend::class)
190 ->disableOriginalConstructor()
192 $this->attribute->expects($this->once())
193 ->method(
'getFrontend')
194 ->willReturn($frontend);
195 $optionDataObjectForSimpleValue2->expects($this->once())
196 ->method(
'setOptions')
197 ->with([$optionObject1, $optionObject2]);
198 $this->model->createMetadataAttribute($this->attribute);