|
7 | 7 |
|
8 | 8 | namespace Magento\Eav\Test\Unit\Model\Entity\Attribute;
|
9 | 9 |
|
| 10 | +use Magento\Catalog\Model\Product; |
10 | 11 | use Magento\Eav\Api\Data\AttributeOptionInterface as EavAttributeOptionInterface;
|
11 | 12 | use Magento\Eav\Api\Data\AttributeOptionLabelInterface as EavAttributeOptionLabelInterface;
|
12 | 13 | use Magento\Eav\Model\AttributeRepository;
|
|
18 | 19 | use Magento\Framework\Exception\InputException;
|
19 | 20 | use Magento\Framework\Exception\NoSuchEntityException;
|
20 | 21 | use Magento\Framework\Exception\StateException;
|
21 |
| -use PHPUnit\Framework\MockObject\MockObject as MockObject; |
| 22 | +use PHPUnit\Framework\MockObject\MockObject; |
22 | 23 | use PHPUnit\Framework\TestCase;
|
23 | 24 |
|
24 | 25 | /**
|
@@ -228,6 +229,74 @@ public function testAddWithCannotSaveException()
|
228 | 229 | $this->model->add($entityType, $attributeCode, $optionMock);
|
229 | 230 | }
|
230 | 231 |
|
| 232 | + /** |
| 233 | + * Test to update attribute option |
| 234 | + * |
| 235 | + * @dataProvider optionLabelDataProvider |
| 236 | + */ |
| 237 | + public function testUpdate($label) |
| 238 | + { |
| 239 | + $entityType = Product::ENTITY; |
| 240 | + $storeId = 4; |
| 241 | + $attributeCode = 'atrCde'; |
| 242 | + $storeLabel = 'labelLabel'; |
| 243 | + $sortOder = 'optionSortOrder'; |
| 244 | + $optionId = 10; |
| 245 | + $option = [ |
| 246 | + 'value' => [ |
| 247 | + $optionId => [ |
| 248 | + 0 => $label, |
| 249 | + $storeId => $storeLabel, |
| 250 | + ], |
| 251 | + ], |
| 252 | + 'order' => [ |
| 253 | + $optionId => $sortOder, |
| 254 | + ] |
| 255 | + ]; |
| 256 | + |
| 257 | + $optionMock = $this->getAttributeOption(); |
| 258 | + $labelMock = $this->getAttributeOptionLabel(); |
| 259 | + /** @var SourceInterface|MockObject $sourceMock */ |
| 260 | + $sourceMock = $this->createMock(EavAttributeSource::class); |
| 261 | + |
| 262 | + $sourceMock->expects($this->once()) |
| 263 | + ->method('getOptionText') |
| 264 | + ->with($optionId) |
| 265 | + ->willReturn($label); |
| 266 | + |
| 267 | + $sourceMock->expects($this->once()) |
| 268 | + ->method('getOptionId') |
| 269 | + ->with($label) |
| 270 | + ->willReturn($optionId); |
| 271 | + |
| 272 | + /** @var EavAbstractAttribute|MockObject $attributeMock */ |
| 273 | + $attributeMock = $this->getMockBuilder(EavAbstractAttribute::class) |
| 274 | + ->disableOriginalConstructor() |
| 275 | + ->addMethods(['setOption']) |
| 276 | + ->onlyMethods(['usesSource', 'getSource']) |
| 277 | + ->getMock(); |
| 278 | + $attributeMock->method('usesSource')->willReturn(true); |
| 279 | + $attributeMock->expects($this->once())->method('setOption')->with($option); |
| 280 | + $attributeMock->method('getSource')->willReturn($sourceMock); |
| 281 | + |
| 282 | + $this->attributeRepositoryMock->expects($this->once()) |
| 283 | + ->method('get') |
| 284 | + ->with($entityType, $attributeCode) |
| 285 | + ->willReturn($attributeMock); |
| 286 | + $optionMock->method('getLabel')->willReturn($label); |
| 287 | + $optionMock->method('getSortOrder')->willReturn($sortOder); |
| 288 | + $optionMock->method('getIsDefault')->willReturn(true); |
| 289 | + $optionMock->method('getStoreLabels')->willReturn([$labelMock]); |
| 290 | + $labelMock->method('getStoreId')->willReturn($storeId); |
| 291 | + $labelMock->method('getLabel')->willReturn($storeLabel); |
| 292 | + $this->resourceModelMock->expects($this->once())->method('save')->with($attributeMock); |
| 293 | + |
| 294 | + $this->assertEquals( |
| 295 | + true, |
| 296 | + $this->model->update($entityType, $attributeCode, $optionId, $optionMock) |
| 297 | + ); |
| 298 | + } |
| 299 | + |
231 | 300 | /**
|
232 | 301 | * Test to delete attribute option
|
233 | 302 | */
|
|
0 commit comments