Skip to content

Commit 981cd29

Browse files
add unit test
1 parent e130be7 commit 981cd29

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

app/code/Magento/SalesRule/Test/Unit/Model/Rule/Condition/ProductTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
1212
use Magento\Catalog\Model\ProductCategoryList;
1313
use Magento\Catalog\Model\ProductFactory;
14+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
1415
use Magento\Catalog\Model\ResourceModel\Product;
1516
use Magento\Directory\Model\CurrencyFactory;
1617
use Magento\Eav\Model\Config;
@@ -319,6 +320,73 @@ public function testQuoteLocaleFormatPrice($isValid, $conditionValue, $operator
319320
$this->assertEquals($isValid, $this->model->setValue($conditionValue)->validate($item));
320321
}
321322

323+
/**
324+
* Test for loadAttributeOptions
325+
*
326+
* @return void
327+
*/
328+
public function testLoadAttributeOptions(): void
329+
{
330+
$secondAttributeCode = 'second_attribute';
331+
332+
$attribute = $this->getMockBuilder(Attribute::class)
333+
->onlyMethods(['getDataUsingMethod'])
334+
->disableOriginalConstructor()
335+
->getMock();
336+
$attribute->expects($this->atLeastOnce())
337+
->method('getDataUsingMethod')
338+
->with('is_used_for_promo_rules')
339+
->willReturn(false);
340+
341+
$attributeSecond = $this->getMockBuilder(Attribute::class)
342+
->onlyMethods(['getDataUsingMethod', 'isAllowedForRuleCondition', 'getAttributeCode'])
343+
->addMethods(['getFrontendLabel'])
344+
->disableOriginalConstructor()
345+
->getMock();
346+
$attributeSecond->expects($this->atLeastOnce())
347+
->method('getDataUsingMethod')
348+
->with('is_used_for_promo_rules')
349+
->willReturn(true);
350+
$attributeSecond->expects($this->atLeastOnce())
351+
->method('isAllowedForRuleCondition')
352+
->willReturn(true);
353+
$attributeSecond->expects($this->atLeastOnce())
354+
->method('getFrontendLabel')
355+
->willReturn('Second Attribute');
356+
$attributeSecond->expects($this->atLeastOnce())
357+
->method('getAttributeCode')
358+
->willReturn($secondAttributeCode);
359+
360+
$attributeLoaderInterfaceMock = $this->createMock(AbstractEntity::class);
361+
$attributeLoaderInterfaceMock->expects($this->atLeastOnce())
362+
->method('getAttributesByCode')
363+
->willReturn([$attribute, $attributeSecond]);
364+
365+
$productResourceMock = $this->createMock(Product::class);
366+
$productResourceMock->expects($this->atLeastOnce())
367+
->method('loadAllAttributes')
368+
->willReturn($attributeLoaderInterfaceMock);
369+
370+
$model = new SalesRuleProduct(
371+
$this->contextMock,
372+
$this->backendHelperMock,
373+
$this->configMock,
374+
$this->productFactoryMock,
375+
$this->productRepositoryMock,
376+
$productResourceMock,
377+
$this->collectionMock,
378+
$this->format,
379+
[],
380+
$this->productCategoryListMock
381+
);
382+
383+
$model->loadAttributeOptions();
384+
385+
$this->assertArrayHasKey($secondAttributeCode, $model->getAttributeOption());
386+
$this->assertArrayHasKey('children::' . $secondAttributeCode, $model->getAttributeOption());
387+
$this->assertArrayHasKey('parent::' . $secondAttributeCode, $model->getAttributeOption());
388+
}
389+
322390
/**
323391
* DataProvider for testQuoteLocaleFormatPrice
324392
*

0 commit comments

Comments
 (0)