|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\SalesRule\Test\Unit\Model\Rule\Condition\Product; |
| 9 | + |
| 10 | +use Magento\Rule\Model\Condition\Context; |
| 11 | +use Magento\SalesRule\Model\Rule\Condition\Product as SalesRuleProduct; |
| 12 | +use Magento\SalesRule\Model\Rule\Condition\Product\Combine; |
| 13 | +use PHPUnit\Framework\MockObject\MockObject; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +class CombineTest extends TestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @var Combine |
| 20 | + */ |
| 21 | + private $model; |
| 22 | + |
| 23 | + /** |
| 24 | + * @var SalesRuleProduct|MockObject |
| 25 | + */ |
| 26 | + private $ruleConditionMock; |
| 27 | + |
| 28 | + /** |
| 29 | + * @inheritDoc |
| 30 | + */ |
| 31 | + protected function setUp(): void |
| 32 | + { |
| 33 | + $contextMock = $this->getMockBuilder(Context::class) |
| 34 | + ->disableOriginalConstructor() |
| 35 | + ->getMock(); |
| 36 | + $this->ruleConditionMock = $this->getMockBuilder(SalesRuleProduct::class) |
| 37 | + ->setMethods(['loadAttributeOptions', 'getAttributeOption']) |
| 38 | + ->disableOriginalConstructor() |
| 39 | + ->getMock(); |
| 40 | + $this->model = new Combine( |
| 41 | + $contextMock, |
| 42 | + $this->ruleConditionMock, |
| 43 | + [] |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @return void |
| 49 | + */ |
| 50 | + public function testGetNewChildSelectOptions() |
| 51 | + { |
| 52 | + $this->ruleConditionMock->expects($this->any()) |
| 53 | + ->method('loadAttributeOptions') |
| 54 | + ->willReturn($this->ruleConditionMock); |
| 55 | + $this->ruleConditionMock->expects($this->any()) |
| 56 | + ->method('getAttributeOption') |
| 57 | + ->willReturn([ |
| 58 | + 'parent::quote_item_qty' => __('Quantity in cart'), |
| 59 | + 'name' => __('Name') |
| 60 | + ]); |
| 61 | + $this->assertEquals([ |
| 62 | + [ |
| 63 | + 'value' => '', |
| 64 | + 'label' => __('Please choose a condition to add.')], |
| 65 | + [ |
| 66 | + 'value' => Combine::class, |
| 67 | + 'label' => __('Conditions Combination'), |
| 68 | + ], |
| 69 | + [ |
| 70 | + 'label' => __('Cart Item Attribute'), |
| 71 | + 'value' => [ |
| 72 | + [ |
| 73 | + 'value' => SalesRuleProduct::class . '|' . 'parent::quote_item_qty', |
| 74 | + 'label' => __('Quantity in cart'), |
| 75 | + ] |
| 76 | + ] |
| 77 | + ], |
| 78 | + [ |
| 79 | + 'label' => __('Product Attribute'), |
| 80 | + 'value' => [ |
| 81 | + [ |
| 82 | + 'value' => SalesRuleProduct::class . '|' . 'name', |
| 83 | + 'label' => __('Name'), |
| 84 | + ] |
| 85 | + ] |
| 86 | + ] |
| 87 | + ], $this->model->getNewChildSelectOptions()); |
| 88 | + } |
| 89 | +} |
0 commit comments