17 private $customerMetadataService;
22 private $addressMetadataService;
27 private $elementFactory;
32 private $fileProcessorFactory;
37 private $attributeMetadata;
41 $this->customerMetadataService = $this->getMockBuilder(\
Magento\
Customer\Api\CustomerMetadataInterface::class)
42 ->getMockForAbstractClass();
44 $this->addressMetadataService = $this->getMockBuilder(\
Magento\
Customer\Api\AddressMetadataInterface::class)
45 ->getMockForAbstractClass();
47 $this->elementFactory = $this->getMockBuilder(\
Magento\
Customer\Model\Metadata\ElementFactory::class)
48 ->disableOriginalConstructor()
51 $this->fileProcessorFactory = $this->getMockBuilder(\
Magento\
Customer\Model\FileProcessorFactory::class)
52 ->disableOriginalConstructor()
53 ->setMethods([
'create'])
56 $this->attributeMetadata = $this->getMockBuilder(\
Magento\
Customer\Api\Data\AttributeMetadataInterface::class)
57 ->getMockForAbstractClass();
73 $this->customerMetadataService,
74 $this->addressMetadataService,
75 $this->elementFactory,
76 $this->fileProcessorFactory,
77 $this->attributeMetadata,
88 $filename =
'filename.ext1';
99 ->disableOriginalConstructor()
101 $formElement->expects($this->once())
102 ->method(
'validateValue')
103 ->with([
'name' => $filename])
106 $this->elementFactory->expects($this->once())
109 ->willReturn($formElement);
112 $this->assertTrue(
$model->validate());
118 $attributeFrontendInput =
'image';
120 $resultFileName =
'/filename.ext1';
121 $resultFilePath =
'filepath';
122 $resultFileUrl =
'viewFileUrl';
125 $expectedAllowedExtensions = [
140 'name' => $resultFileName,
141 'file' => $resultFileName,
142 'path' => $resultFilePath,
143 'tmp_name' => ltrim($resultFileName,
'/'),
144 'url' => $resultFileUrl,
147 $fileProcessor = $this->getMockBuilder(\
Magento\
Customer\Model\FileProcessor::class)
148 ->disableOriginalConstructor()
150 $fileProcessor->expects($this->once())
151 ->method(
'saveTemporaryFile')
154 'name' => $resultFileName,
155 'path' => $resultFilePath,
156 'file' => $resultFileName,
158 $fileProcessor->expects($this->once())
159 ->method(
'getViewUrl')
161 ->willReturn($resultFileUrl);
163 $this->fileProcessorFactory->expects($this->once())
167 'allowedExtensions' => $expectedAllowedExtensions,
169 ->willReturn($fileProcessor);
171 $validationRuleMock = $this->getMockBuilder(\
Magento\
Customer\Api\Data\ValidationRuleInterface::class)
172 ->getMockForAbstractClass();
173 $validationRuleMock->expects($this->once())
175 ->willReturn(
'file_extensions');
176 $validationRuleMock->expects($this->once())
180 $this->attributeMetadata->expects($this->once())
181 ->method(
'getFrontendInput')
182 ->willReturn($attributeFrontendInput);
183 $this->attributeMetadata->expects($this->once())
184 ->method(
'getValidationRules')
185 ->willReturn([$validationRuleMock]);
188 $this->assertEquals($expectedResult,
$model->upload());