mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
Update configuration keys in tests to use excluded channels
This commit is contained in:
parent
702ebe31bd
commit
e87f870860
6 changed files with 538 additions and 29 deletions
|
|
@ -0,0 +1,235 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Sylius\Bundle\AdminBundle\Form\Extension\Promotion;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Sylius\Bundle\AdminBundle\Form\Extension\Promotion\PromotionActionTypeExtension;
|
||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||
use Sylius\Component\Core\Promotion\ChannelAwareConfigurationInterface;
|
||||
use Sylius\Component\Promotion\Model\PromotionActionInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
#[CoversClass(PromotionActionTypeExtension::class)]
|
||||
final class PromotionActionTypeExtensionTest extends TestCase
|
||||
{
|
||||
private const KEY = ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY;
|
||||
|
||||
private ChannelRepositoryInterface&MockObject $channelRepository;
|
||||
|
||||
private PromotionActionTypeExtension $extension;
|
||||
|
||||
/** @var array<string, callable> */
|
||||
private array $listeners = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->channelRepository = $this->createMock(ChannelRepositoryInterface::class);
|
||||
|
||||
$webChannel = $this->createMock(ChannelInterface::class);
|
||||
$webChannel->method('getName')->willReturn('Web');
|
||||
$webChannel->method('getCode')->willReturn('WEB');
|
||||
|
||||
$mobileChannel = $this->createMock(ChannelInterface::class);
|
||||
$mobileChannel->method('getName')->willReturn('Mobile');
|
||||
$mobileChannel->method('getCode')->willReturn('MOBILE');
|
||||
|
||||
$this->channelRepository->method('findAll')->willReturn([$webChannel, $mobileChannel]);
|
||||
|
||||
$this->extension = new PromotionActionTypeExtension($this->channelRepository);
|
||||
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$builder->method('add')->willReturnSelf();
|
||||
$builder->method('addEventListener')->willReturnCallback(
|
||||
function (string $event, callable $listener): FormBuilderInterface {
|
||||
$this->listeners[$event] = $listener;
|
||||
|
||||
return $this->createMock(FormBuilderInterface::class);
|
||||
},
|
||||
);
|
||||
|
||||
$this->extension->buildForm($builder, []);
|
||||
}
|
||||
|
||||
public function testPreSubmitInjectsDefaultChannelsForNewAction(): void
|
||||
{
|
||||
$innerForm = $this->createMock(FormInterface::class);
|
||||
$innerForm->method('getData')->willReturn(null);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(['type' => 'order_percentage_discount']);
|
||||
$event->method('getForm')->willReturn($innerForm);
|
||||
$event->expects($this->once())->method('setData')->with([
|
||||
'type' => 'order_percentage_discount',
|
||||
self::KEY => ['WEB', 'MOBILE'],
|
||||
]);
|
||||
|
||||
($this->listeners[FormEvents::PRE_SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testPreSubmitDoesNotInjectForExistingActionWithNoKeyPresent(): void
|
||||
{
|
||||
$action = $this->createMock(PromotionActionInterface::class);
|
||||
$innerForm = $this->createMock(FormInterface::class);
|
||||
$innerForm->method('getData')->willReturn($action);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(['type' => 'order_percentage_discount']);
|
||||
$event->method('getForm')->willReturn($innerForm);
|
||||
$event->expects($this->never())->method('setData');
|
||||
|
||||
($this->listeners[FormEvents::PRE_SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testPreSubmitDoesNotInjectWhenKeyAlreadyPresent(): void
|
||||
{
|
||||
$innerForm = $this->createMock(FormInterface::class);
|
||||
$innerForm->method('getData')->willReturn(null);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(['type' => 'order_percentage_discount', self::KEY => ['WEB']]);
|
||||
$event->method('getForm')->willReturn($innerForm);
|
||||
$event->expects($this->never())->method('setData');
|
||||
|
||||
($this->listeners[FormEvents::PRE_SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testPostSetDataSetsAllChannelsCheckedForNewAction(): void
|
||||
{
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->expects($this->once())->method('setData')->with(['WEB', 'MOBILE']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(null);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::POST_SET_DATA])($event);
|
||||
}
|
||||
|
||||
public function testPostSetDataSetsAllChannelsCheckedWhenNoExclusions(): void
|
||||
{
|
||||
$action = $this->createMock(PromotionActionInterface::class);
|
||||
$action->method('getConfiguration')->willReturn([self::KEY => []]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->expects($this->once())->method('setData')->with(['WEB', 'MOBILE']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($action);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::POST_SET_DATA])($event);
|
||||
}
|
||||
|
||||
public function testPostSetDataSetsOnlyNonExcludedChannelsChecked(): void
|
||||
{
|
||||
$action = $this->createMock(PromotionActionInterface::class);
|
||||
$action->method('getConfiguration')->willReturn([self::KEY => ['MOBILE']]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->expects($this->once())->method('setData')->with(['WEB']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($action);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::POST_SET_DATA])($event);
|
||||
}
|
||||
|
||||
public function testSubmitComputesExcludedChannelsFromSelectedChannels(): void
|
||||
{
|
||||
$action = $this->createMock(PromotionActionInterface::class);
|
||||
$action->method('getConfiguration')->willReturn([]);
|
||||
$action->expects($this->once())->method('setConfiguration')->with([
|
||||
self::KEY => ['MOBILE'],
|
||||
]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->method('getData')->willReturn(['WEB']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($action);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testSubmitStoresEmptyExclusionsWhenAllChannelsSelected(): void
|
||||
{
|
||||
$action = $this->createMock(PromotionActionInterface::class);
|
||||
$action->method('getConfiguration')->willReturn([]);
|
||||
$action->expects($this->once())->method('setConfiguration')->with([
|
||||
self::KEY => [],
|
||||
]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->method('getData')->willReturn(['WEB', 'MOBILE']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($action);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testSubmitStoresAllChannelsExcludedWhenNoneSelected(): void
|
||||
{
|
||||
$action = $this->createMock(PromotionActionInterface::class);
|
||||
$action->method('getConfiguration')->willReturn([]);
|
||||
$action->expects($this->once())->method('setConfiguration')->with([
|
||||
self::KEY => ['WEB', 'MOBILE'],
|
||||
]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->method('getData')->willReturn([]);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($action);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testSubmitDoesNothingForNonActionData(): void
|
||||
{
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(null);
|
||||
$event->expects($this->never())->method('getForm');
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,248 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Sylius Sp. z o.o.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Sylius\Bundle\AdminBundle\Form\Extension\Promotion;
|
||||
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Sylius\Bundle\AdminBundle\Form\Extension\Promotion\PromotionRuleTypeExtension;
|
||||
use Sylius\Component\Channel\Model\ChannelInterface;
|
||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||
use Sylius\Component\Core\Promotion\ChannelAwareConfigurationInterface;
|
||||
use Sylius\Component\Promotion\Model\PromotionRuleInterface;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
|
||||
#[CoversClass(PromotionRuleTypeExtension::class)]
|
||||
final class PromotionRuleTypeExtensionTest extends TestCase
|
||||
{
|
||||
private const KEY = ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY;
|
||||
|
||||
private ChannelRepositoryInterface&MockObject $channelRepository;
|
||||
|
||||
private PromotionRuleTypeExtension $extension;
|
||||
|
||||
/** @var array<string, callable> */
|
||||
private array $listeners = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->channelRepository = $this->createMock(ChannelRepositoryInterface::class);
|
||||
|
||||
$webChannel = $this->createMock(ChannelInterface::class);
|
||||
$webChannel->method('getName')->willReturn('Web');
|
||||
$webChannel->method('getCode')->willReturn('WEB');
|
||||
|
||||
$mobileChannel = $this->createMock(ChannelInterface::class);
|
||||
$mobileChannel->method('getName')->willReturn('Mobile');
|
||||
$mobileChannel->method('getCode')->willReturn('MOBILE');
|
||||
|
||||
$this->channelRepository->method('findAll')->willReturn([$webChannel, $mobileChannel]);
|
||||
|
||||
$this->extension = new PromotionRuleTypeExtension($this->channelRepository);
|
||||
|
||||
$builder = $this->createMock(FormBuilderInterface::class);
|
||||
$builder->method('add')->willReturnSelf();
|
||||
$builder->method('addEventListener')->willReturnCallback(
|
||||
function (string $event, callable $listener): FormBuilderInterface {
|
||||
$this->listeners[$event] = $listener;
|
||||
|
||||
return $this->createMock(FormBuilderInterface::class);
|
||||
},
|
||||
);
|
||||
|
||||
$this->extension->buildForm($builder, []);
|
||||
}
|
||||
|
||||
public function testPreSubmitInjectsDefaultChannelsForNewItem(): void
|
||||
{
|
||||
$innerForm = $this->createMock(FormInterface::class);
|
||||
$innerForm->method('getData')->willReturn(null);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(['type' => 'item_total']);
|
||||
$event->method('getForm')->willReturn($innerForm);
|
||||
$event->expects($this->once())->method('setData')->with([
|
||||
'type' => 'item_total',
|
||||
self::KEY => ['WEB', 'MOBILE'],
|
||||
]);
|
||||
|
||||
($this->listeners[FormEvents::PRE_SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testPreSubmitDoesNotInjectForExistingRuleWithNoKeyPresent(): void
|
||||
{
|
||||
$rule = $this->createMock(PromotionRuleInterface::class);
|
||||
$innerForm = $this->createMock(FormInterface::class);
|
||||
$innerForm->method('getData')->willReturn($rule);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(['type' => 'item_total']);
|
||||
$event->method('getForm')->willReturn($innerForm);
|
||||
$event->expects($this->never())->method('setData');
|
||||
|
||||
($this->listeners[FormEvents::PRE_SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testPreSubmitDoesNotInjectWhenKeyAlreadyPresent(): void
|
||||
{
|
||||
$innerForm = $this->createMock(FormInterface::class);
|
||||
$innerForm->method('getData')->willReturn(null);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(['type' => 'item_total', self::KEY => ['WEB']]);
|
||||
$event->method('getForm')->willReturn($innerForm);
|
||||
$event->expects($this->never())->method('setData');
|
||||
|
||||
($this->listeners[FormEvents::PRE_SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testPreSubmitDoesNothingForNonArrayData(): void
|
||||
{
|
||||
$innerForm = $this->createMock(FormInterface::class);
|
||||
$innerForm->method('getData')->willReturn(null);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(null);
|
||||
$event->method('getForm')->willReturn($innerForm);
|
||||
$event->expects($this->never())->method('setData');
|
||||
|
||||
($this->listeners[FormEvents::PRE_SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testPostSetDataSetsAllChannelsCheckedForNewRule(): void
|
||||
{
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->expects($this->once())->method('setData')->with(['WEB', 'MOBILE']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(null);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::POST_SET_DATA])($event);
|
||||
}
|
||||
|
||||
public function testPostSetDataSetsAllChannelsCheckedWhenNoExclusions(): void
|
||||
{
|
||||
$rule = $this->createMock(PromotionRuleInterface::class);
|
||||
$rule->method('getConfiguration')->willReturn([self::KEY => []]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->expects($this->once())->method('setData')->with(['WEB', 'MOBILE']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($rule);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::POST_SET_DATA])($event);
|
||||
}
|
||||
|
||||
public function testPostSetDataSetsOnlyNonExcludedChannelsChecked(): void
|
||||
{
|
||||
$rule = $this->createMock(PromotionRuleInterface::class);
|
||||
$rule->method('getConfiguration')->willReturn([self::KEY => ['MOBILE']]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->expects($this->once())->method('setData')->with(['WEB']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($rule);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::POST_SET_DATA])($event);
|
||||
}
|
||||
|
||||
public function testSubmitComputesExcludedChannelsFromSelectedChannels(): void
|
||||
{
|
||||
$rule = $this->createMock(PromotionRuleInterface::class);
|
||||
$rule->method('getConfiguration')->willReturn([]);
|
||||
$rule->expects($this->once())->method('setConfiguration')->with([
|
||||
self::KEY => ['MOBILE'],
|
||||
]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->method('getData')->willReturn(['WEB']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($rule);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testSubmitStoresEmptyExclusionsWhenAllChannelsSelected(): void
|
||||
{
|
||||
$rule = $this->createMock(PromotionRuleInterface::class);
|
||||
$rule->method('getConfiguration')->willReturn([]);
|
||||
$rule->expects($this->once())->method('setConfiguration')->with([
|
||||
self::KEY => [],
|
||||
]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->method('getData')->willReturn(['WEB', 'MOBILE']);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($rule);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testSubmitStoresAllChannelsExcludedWhenNoneSelected(): void
|
||||
{
|
||||
$rule = $this->createMock(PromotionRuleInterface::class);
|
||||
$rule->method('getConfiguration')->willReturn([]);
|
||||
$rule->expects($this->once())->method('setConfiguration')->with([
|
||||
self::KEY => ['WEB', 'MOBILE'],
|
||||
]);
|
||||
|
||||
$channelField = $this->createMock(FormInterface::class);
|
||||
$channelField->method('getData')->willReturn([]);
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('get')->with(self::KEY)->willReturn($channelField);
|
||||
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn($rule);
|
||||
$event->method('getForm')->willReturn($form);
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
|
||||
public function testSubmitDoesNothingForNonRuleData(): void
|
||||
{
|
||||
$event = $this->createMock(FormEvent::class);
|
||||
$event->method('getData')->willReturn(null);
|
||||
$event->expects($this->never())->method('getForm');
|
||||
|
||||
($this->listeners[FormEvents::SUBMIT])($event);
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ use Sylius\Bundle\CoreBundle\Validator\Constraints\ChannelCodeCollectionValidato
|
|||
use Sylius\Component\Channel\Model\ChannelsAwareInterface;
|
||||
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
|
||||
use Sylius\Component\Core\Model\ChannelInterface;
|
||||
use Sylius\Component\Core\Promotion\ChannelAwareConfigurationInterface;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
|
@ -255,4 +256,29 @@ final class ChannelCodeCollectionValidatorTest extends TestCase
|
|||
'validateAgainstAllChannels' => true,
|
||||
]));
|
||||
}
|
||||
|
||||
public function testItValidatesCollectionsForRemainingChannelsWhenExcludedChannelsKeyIsPresent(): void
|
||||
{
|
||||
$validator = $this->createMock(ValidatorInterface::class);
|
||||
$contextualValidator = $this->createMock(ContextualValidatorInterface::class);
|
||||
|
||||
$this->channelRepository->method('findAllWithBasicData')->willReturn([
|
||||
['code' => 'WEB'], ['code' => 'MOBILE'],
|
||||
]);
|
||||
|
||||
$value = [
|
||||
'WEB' => ['amount' => 1000],
|
||||
ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE'],
|
||||
];
|
||||
|
||||
$this->executionContext->method('getValidator')->willReturn($validator);
|
||||
$validator->method('inContext')->willReturn($contextualValidator);
|
||||
$contextualValidator->expects($this->once())->method('validate');
|
||||
|
||||
$this->validator->validate($value, new ChannelCodeCollection([
|
||||
'constraints' => [new NotBlank(), new Type('numeric')],
|
||||
'groups' => ['Default'],
|
||||
'validateAgainstAllChannels' => true,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ final class PromotionConfigurationChannelCodesValidatorTest extends TestCase
|
|||
$this->executionContext->expects($this->never())->method('buildViolation');
|
||||
|
||||
$this->validator->validate(
|
||||
[ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => []],
|
||||
[ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => []],
|
||||
new PromotionConfigurationChannelCodes(),
|
||||
);
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ final class PromotionConfigurationChannelCodesValidatorTest extends TestCase
|
|||
$this->executionContext->expects($this->never())->method('buildViolation');
|
||||
|
||||
$this->validator->validate(
|
||||
[ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB', 'MOBILE']],
|
||||
[ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['WEB', 'MOBILE']],
|
||||
new PromotionConfigurationChannelCodes(),
|
||||
);
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ final class PromotionConfigurationChannelCodesValidatorTest extends TestCase
|
|||
$violationBuilder
|
||||
->expects($this->once())
|
||||
->method('atPath')
|
||||
->with('[' . ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY . ']')
|
||||
->with('[' . ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY . ']')
|
||||
->willReturn($violationBuilder);
|
||||
$violationBuilder->expects($this->once())->method('addViolation');
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ final class PromotionConfigurationChannelCodesValidatorTest extends TestCase
|
|||
->willReturn($violationBuilder);
|
||||
|
||||
$this->validator->validate(
|
||||
[ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['INVALID_CODE']],
|
||||
[ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['INVALID_CODE']],
|
||||
new PromotionConfigurationChannelCodes(),
|
||||
);
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ final class PromotionConfigurationChannelCodesValidatorTest extends TestCase
|
|||
->willReturn($violationBuilder);
|
||||
|
||||
$this->validator->validate(
|
||||
[ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB', 'INVALID_ONE', 'INVALID_TWO']],
|
||||
[ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['WEB', 'INVALID_ONE', 'INVALID_TWO']],
|
||||
new PromotionConfigurationChannelCodes(),
|
||||
);
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ final class PromotionConfigurationChannelCodesValidatorTest extends TestCase
|
|||
->willReturn($violationBuilder);
|
||||
|
||||
$this->validator->validate(
|
||||
[ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => [42]],
|
||||
[ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => [42]],
|
||||
new PromotionConfigurationChannelCodes(),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
$this->channel->method('getCode')->willReturn('MOBILE');
|
||||
|
|
@ -137,7 +137,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
$this->action->expects($this->once())->method('getType')->willReturn('order_percentage_discount');
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
|
|
@ -164,7 +164,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => []]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => []]);
|
||||
$this->action->expects($this->once())->method('getType')->willReturn('order_percentage_discount');
|
||||
|
||||
$this->serviceRegistry->expects($this->once())->method('get')->willReturn($this->actionCommand);
|
||||
|
|
@ -188,7 +188,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
$this->action->expects($this->once())->method('getType')->willReturn('order_percentage_discount');
|
||||
|
||||
$this->serviceRegistry->expects($this->once())->method('get')->willReturn($this->actionCommand);
|
||||
|
|
@ -203,7 +203,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->applicator->apply($this->subject, $this->promotion);
|
||||
}
|
||||
|
||||
public function testShouldStripChannelsKeyFromConfigurationDuringApply(): void
|
||||
public function testShouldStripExcludedChannelsKeyFromConfigurationDuringApply(): void
|
||||
{
|
||||
$this->promotion->expects($this->once())->method('getActions')->willReturn(
|
||||
new ArrayCollection([$this->action]),
|
||||
|
|
@ -214,7 +214,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
->method('getConfiguration')
|
||||
->willReturn([
|
||||
'amount' => 100,
|
||||
ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB'],
|
||||
ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE'],
|
||||
]);
|
||||
$this->action->expects($this->once())->method('getType')->willReturn('order_fixed_discount');
|
||||
|
||||
|
|
@ -244,7 +244,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
|
||||
$secondAction->expects($this->exactly(2))->method('getConfiguration')->willReturn([]);
|
||||
$secondAction->expects($this->once())->method('getType')->willReturn('order_percentage_discount');
|
||||
|
|
@ -275,11 +275,11 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
$secondAction
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
$this->channel->method('getCode')->willReturn('MOBILE');
|
||||
|
|
@ -299,7 +299,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
$this->channel->method('getCode')->willReturn('MOBILE');
|
||||
|
|
@ -320,7 +320,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->action
|
||||
->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
$this->action->expects($this->once())->method('getType')->willReturn('order_percentage_discount');
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
|
|
@ -337,7 +337,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
$this->applicator->revert($this->order, $this->promotion);
|
||||
}
|
||||
|
||||
public function testShouldStripChannelsKeyFromConfigurationDuringRevert(): void
|
||||
public function testShouldStripExcludedChannelsKeyFromConfigurationDuringRevert(): void
|
||||
{
|
||||
$this->promotion->expects($this->once())->method('getActions')->willReturn(
|
||||
new ArrayCollection([$this->action]),
|
||||
|
|
@ -348,7 +348,7 @@ final class ChannelAwarePromotionApplicatorTest extends TestCase
|
|||
->method('getConfiguration')
|
||||
->willReturn([
|
||||
'amount' => 100,
|
||||
ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB'],
|
||||
ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE'],
|
||||
]);
|
||||
$this->action->expects($this->once())->method('getType')->willReturn('order_fixed_discount');
|
||||
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->assertFalse($this->checker->isEligible($this->order, $this->promotion));
|
||||
}
|
||||
|
||||
public function testShouldSkipRuleIfCurrentChannelNotInChannelsList(): void
|
||||
public function testShouldSkipRuleIfCurrentChannelIsInExcludedChannelsList(): void
|
||||
{
|
||||
$this->promotion->expects($this->once())->method('hasRules')->willReturn(true);
|
||||
$this->promotion->expects($this->once())->method('getRules')->willReturn(
|
||||
|
|
@ -151,7 +151,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->rule
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
$this->channel->method('getCode')->willReturn('MOBILE');
|
||||
|
|
@ -161,7 +161,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->assertTrue($this->checker->isEligible($this->order, $this->promotion));
|
||||
}
|
||||
|
||||
public function testShouldNotSkipRuleIfCurrentChannelIsInChannelsList(): void
|
||||
public function testShouldNotSkipRuleIfCurrentChannelIsNotInExcludedChannelsList(): void
|
||||
{
|
||||
$this->promotion->expects($this->once())->method('hasRules')->willReturn(true);
|
||||
$this->promotion->expects($this->once())->method('getRules')->willReturn(
|
||||
|
|
@ -171,7 +171,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->rule
|
||||
->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
$this->rule->expects($this->once())->method('getType')->willReturn('item_total');
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
|
|
@ -193,7 +193,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->rule
|
||||
->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => []]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => []]);
|
||||
$this->rule->expects($this->once())->method('getType')->willReturn('item_total');
|
||||
|
||||
$this->serviceRegistry->expects($this->once())->method('get')->willReturn($this->ruleChecker);
|
||||
|
|
@ -212,7 +212,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->rule
|
||||
->expects($this->exactly(2))
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
$this->rule->expects($this->once())->method('getType')->willReturn('item_total');
|
||||
|
||||
$this->serviceRegistry->expects($this->once())->method('get')->willReturn($this->ruleChecker);
|
||||
|
|
@ -221,7 +221,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->assertTrue($this->checker->isEligible($this->subject, $this->promotion));
|
||||
}
|
||||
|
||||
public function testShouldStripChannelsKeyFromConfigurationBeforePassingToRuleChecker(): void
|
||||
public function testShouldStripExcludedChannelsKeyFromConfigurationBeforePassingToRuleChecker(): void
|
||||
{
|
||||
$this->promotion->expects($this->once())->method('hasRules')->willReturn(true);
|
||||
$this->promotion->expects($this->once())->method('getRules')->willReturn(
|
||||
|
|
@ -233,7 +233,7 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
->method('getConfiguration')
|
||||
->willReturn([
|
||||
'count' => 3,
|
||||
ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB'],
|
||||
ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE'],
|
||||
]);
|
||||
$this->rule->expects($this->once())->method('getType')->willReturn('cart_quantity');
|
||||
|
||||
|
|
@ -262,11 +262,11 @@ final class ChannelAwarePromotionRulesEligibilityCheckerTest extends TestCase
|
|||
$this->rule
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
$secondRule
|
||||
->expects($this->once())
|
||||
->method('getConfiguration')
|
||||
->willReturn([ChannelAwareConfigurationInterface::CHANNELS_CONFIGURATION_KEY => ['WEB']]);
|
||||
->willReturn([ChannelAwareConfigurationInterface::EXCLUDED_CHANNELS_CONFIGURATION_KEY => ['MOBILE']]);
|
||||
|
||||
$this->order->method('getChannel')->willReturn($this->channel);
|
||||
$this->channel->method('getCode')->willReturn('MOBILE');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue