PromotionEntity example


class PromotionEntityTest extends TestCase
{
    /** * This test verifies, that we only get an * empty AND rule, if no precondition has been added. * * @group promotions */
    public function testPreconditionRuleEmpty(): void
    {
        $promotion = new PromotionEntity();

        $expected = new AndRule();

        static::assertEquals($expected$promotion->getPreconditionRule());
    }

    /** * This test verifies, that we have the correct persona * rule inside our precondition rule structure. * We simulate a new rule and rule entity, and add * that to the promotion. * * @group promotions */
class PromotionItemBuilderPayloadTest extends TestCase
{
    private PromotionEntity $promotion;

    /** * @var MockObject&SalesChannelContext */
    private SalesChannelContext $salesChannelContext;

    protected function setUp(): void
    {
        $this->promotion = new PromotionEntity();
        $this->promotion->setId('PR-1');
        $this->promotion->setUseCodes(false);
        $this->promotion->setUseIndividualCodes(false);
        $this->promotion->setUseSetGroups(false);

        $this->salesChannelContext = $this->getMockBuilder(SalesChannelContext::class)->disableOriginalConstructor()->getMock();
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();

        $this->salesChannelContext->method('getContext')->willReturn($context);
    }

    
public function testGetDecoratedShouldThrowException(): void
    {
        static::expectException(DecorationPatternException::class);
        $this->searchIndexer->getDecorated();
    }

    public function testGlobalData(): void
    {
        $context = Context::createDefaultContext();
        $repository = $this->createMock(EntityRepository::class);
        $promotion = new PromotionEntity();
        $promotion->setUniqueIdentifier(Uuid::randomHex());
        $repository->method('search')->willReturn(
            new EntitySearchResult(
                'promotion',
                1,
                new EntityCollection([$promotion]),
                null,
                new Criteria(),
                $context
            )
        );

        
class PromotionCodeTupleTest extends TestCase
{
    /** * This test verifies that our code is correctly * assigned in the tuple and our getter * does return that value. * * @group promotions */
    public function testCode(): void
    {
        $promotion1 = new PromotionEntity();

        $tuple = new PromotionCodeTuple('codeA', $promotion1);

        static::assertEquals('codeA', $tuple->getCode());
    }

    /** * This test verifies that our promotion is correctly * assigned in the tuple and our getter * does return that object. * * @group promotions */

class AdminSearchControllerTest extends TestCase
{
    private AdminSearcher $searcher;

    protected function setUp(): void
    {
        $this->searcher = $this->getMockBuilder(AdminSearcher::class)->disableOriginalConstructor()->getMock();

        $promotion = new PromotionEntity();
        $promotion->setUniqueIdentifier(Uuid::randomHex());
        $this->searcher->method('search')->willReturn([
            'promotion' => [
                'total' => 1,
                'data' => new EntityCollection([$promotion]),
                'indexer' => 'promotion-listing',
                'index' => 'sw-admin-promotion-listing',
            ],
        ]);
    }

    
class PromotionItemBuilderTest extends TestCase
{
    private PromotionEntity $promotion;

    /** * @var MockObject&SalesChannelContext */
    private SalesChannelContext $salesChannelContext;

    protected function setUp(): void
    {
        $this->promotion = new PromotionEntity();
        $this->promotion->setId('PR-1');
        $this->promotion->setUseCodes(false);
        $this->promotion->setUseIndividualCodes(false);
        $this->promotion->setUseSetGroups(false);

        $this->salesChannelContext = $this->getMockBuilder(SalesChannelContext::class)->disableOriginalConstructor()->getMock();
        $context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();

        $this->salesChannelContext->method('getContext')->willReturn($context);
    }

    

    public function testAutomaticPromotionHasEmptyCode(): void
    {
        $definition = new CartPromotionsDataDefinition();
        $definition->addAutomaticPromotions([new PromotionEntity()]);

        /** @var PromotionCodeTuple[] $tuples */
        $tuples = $definition->getPromotionCodeTuples();

        static::assertEquals('', $tuples[0]->getCode());
    }

    /** * This test verifies that promotions with code get the * correct code within its tuple object. * We add 1 promotion with code, and verify the single tuple * that will be generated. * * @group promotions */
Home | Imprint | This part of the site doesn't use cookies.