|
16 | 16 | use Magento\Customer\Model\FileUploader; |
17 | 17 | use Magento\Customer\Model\Metadata\ElementFactory; |
18 | 18 | use Magento\Customer\Model\Metadata\Form\Image; |
| 19 | +use Magento\Customer\Model\Metadata\Form\Select; |
19 | 20 | use PHPUnit\Framework\MockObject\MockObject; |
20 | 21 | use PHPUnit\Framework\TestCase; |
21 | 22 |
|
@@ -118,10 +119,39 @@ public function testValidate() |
118 | 119 | ->with($this->attributeMetadata, null, CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER) |
119 | 120 | ->willReturn($formElement); |
120 | 121 |
|
| 122 | + $this->attributeMetadata->expects($this->once()) |
| 123 | + ->method('getFrontendInput') |
| 124 | + ->willReturn('image'); |
| 125 | + |
121 | 126 | $model = $this->getModel(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'customer'); |
122 | 127 | $this->assertTrue($model->validate()); |
123 | 128 | } |
124 | 129 |
|
| 130 | + public function testValidateInvalidAttributeType() |
| 131 | + { |
| 132 | + $attributeType = 'select'; |
| 133 | + $attributeCode = 'attribute_code'; |
| 134 | + $filename = 'filename.ext1'; |
| 135 | + |
| 136 | + $_FILES = [ |
| 137 | + 'customer' => [ |
| 138 | + 'name' => [ |
| 139 | + $attributeCode => $filename, |
| 140 | + ], |
| 141 | + ], |
| 142 | + ]; |
| 143 | + |
| 144 | + $this->attributeMetadata->expects($this->exactly(2)) |
| 145 | + ->method('getFrontendInput') |
| 146 | + ->willReturn($attributeType); |
| 147 | + |
| 148 | + $model = $this->getModel(CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'customer'); |
| 149 | + $expectedErrors = [ |
| 150 | + __('"%1" is not a valid input to accept file uploads.', $attributeType) |
| 151 | + ]; |
| 152 | + $this->assertEquals($expectedErrors, $model->validate()); |
| 153 | + } |
| 154 | + |
125 | 155 | public function testUpload() |
126 | 156 | { |
127 | 157 | $attributeCode = 'attribute_code'; |
|
0 commit comments