|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2016 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | declare(strict_types=1);
|
7 | 7 |
|
|
11 | 11 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
12 | 12 | use Magento\Catalog\Model\ProductCategoryList;
|
13 | 13 | use Magento\Catalog\Model\ProductFactory;
|
| 14 | +use Magento\Catalog\Model\ResourceModel\Eav\Attribute; |
14 | 15 | use Magento\Catalog\Model\ResourceModel\Product;
|
15 | 16 | use Magento\Directory\Model\CurrencyFactory;
|
16 | 17 | use Magento\Eav\Model\Config;
|
@@ -322,6 +323,73 @@ public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator
|
322 | 323 | $this->assertEquals($isValid, $this->model->setValue($conditionValue)->validate($item));
|
323 | 324 | }
|
324 | 325 |
|
| 326 | + /** |
| 327 | + * Test for loadAttributeOptions |
| 328 | + * |
| 329 | + * @return void |
| 330 | + */ |
| 331 | + public function testLoadAttributeOptions(): void |
| 332 | + { |
| 333 | + $secondAttributeCode = 'second_attribute'; |
| 334 | + |
| 335 | + $attribute = $this->getMockBuilder(Attribute::class) |
| 336 | + ->onlyMethods(['getDataUsingMethod']) |
| 337 | + ->disableOriginalConstructor() |
| 338 | + ->getMock(); |
| 339 | + $attribute->expects($this->atLeastOnce()) |
| 340 | + ->method('getDataUsingMethod') |
| 341 | + ->with('is_used_for_promo_rules') |
| 342 | + ->willReturn(false); |
| 343 | + |
| 344 | + $attributeSecond = $this->getMockBuilder(Attribute::class) |
| 345 | + ->onlyMethods(['getDataUsingMethod', 'isAllowedForRuleCondition', 'getAttributeCode']) |
| 346 | + ->addMethods(['getFrontendLabel']) |
| 347 | + ->disableOriginalConstructor() |
| 348 | + ->getMock(); |
| 349 | + $attributeSecond->expects($this->atLeastOnce()) |
| 350 | + ->method('getDataUsingMethod') |
| 351 | + ->with('is_used_for_promo_rules') |
| 352 | + ->willReturn(true); |
| 353 | + $attributeSecond->expects($this->atLeastOnce()) |
| 354 | + ->method('isAllowedForRuleCondition') |
| 355 | + ->willReturn(true); |
| 356 | + $attributeSecond->expects($this->atLeastOnce()) |
| 357 | + ->method('getFrontendLabel') |
| 358 | + ->willReturn('Second Attribute'); |
| 359 | + $attributeSecond->expects($this->atLeastOnce()) |
| 360 | + ->method('getAttributeCode') |
| 361 | + ->willReturn($secondAttributeCode); |
| 362 | + |
| 363 | + $attributeLoaderInterfaceMock = $this->createMock(AbstractEntity::class); |
| 364 | + $attributeLoaderInterfaceMock->expects($this->atLeastOnce()) |
| 365 | + ->method('getAttributesByCode') |
| 366 | + ->willReturn([$attribute, $attributeSecond]); |
| 367 | + |
| 368 | + $productResourceMock = $this->createMock(Product::class); |
| 369 | + $productResourceMock->expects($this->atLeastOnce()) |
| 370 | + ->method('loadAllAttributes') |
| 371 | + ->willReturn($attributeLoaderInterfaceMock); |
| 372 | + |
| 373 | + $model = new SalesRuleProduct( |
| 374 | + $this->contextMock, |
| 375 | + $this->backendHelperMock, |
| 376 | + $this->configMock, |
| 377 | + $this->productFactoryMock, |
| 378 | + $this->productRepositoryMock, |
| 379 | + $productResourceMock, |
| 380 | + $this->collectionMock, |
| 381 | + $this->format, |
| 382 | + [], |
| 383 | + $this->productCategoryListMock |
| 384 | + ); |
| 385 | + |
| 386 | + $model->loadAttributeOptions(); |
| 387 | + |
| 388 | + $this->assertArrayHasKey($secondAttributeCode, $model->getAttributeOption()); |
| 389 | + $this->assertArrayHasKey('children::' . $secondAttributeCode, $model->getAttributeOption()); |
| 390 | + $this->assertArrayHasKey('parent::' . $secondAttributeCode, $model->getAttributeOption()); |
| 391 | + } |
| 392 | + |
325 | 393 | /**
|
326 | 394 | * DataProvider for testQuoteLocaleFormatPrice
|
327 | 395 | *
|
|
0 commit comments