示例#1
0
    /**
     * Generate a valid Coupon model
     */
    public function generateCouponModel($facade, ConditionFactory $conditionFactory)
    {
        // Coupons
        $coupon1 = new Coupon();
        $coupon1->setCode('XMAS');
        $coupon1->setType('thelia.coupon.type.remove_x_amount');
        $coupon1->setTitle('Christmas coupon');
        $coupon1->setShortDescription('Coupon for Christmas removing 10€ if your total checkout is more than 40€');
        $coupon1->setDescription('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla.

Donec rhoncus leo mauris, id porttitor ante luctus tempus. Curabitur quis augue feugiat, ullamcorper mauris ac, interdum mi. Quisque aliquam lorem vitae felis lobortis, id interdum turpis mattis. Vestibulum diam massa, ornare congue blandit quis, facilisis at nisl. In tortor metus, venenatis non arcu nec, sollicitudin ornare nisl. Nunc erat risus, varius nec urna at, iaculis lacinia elit. Aenean ut felis tempus, tincidunt odio non, sagittis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae hendrerit elit. Nunc sit amet gravida risus, euismod lobortis massa. Nam a erat mauris. Nam a malesuada lorem. Nulla id accumsan dolor, sed rhoncus tellus. Quisque dictum felis sed leo auctor, at volutpat lectus viverra. Morbi rutrum, est ac aliquam imperdiet, nibh sem sagittis justo, ac mattis magna lacus eu nulla.

Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse potenti. Sed eu purus tellus. Nunc quis rhoncus metus. Fusce vitae tellus enim. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam tempor porttitor erat vitae iaculis. Sed est elit, consequat non ornare vitae, vehicula eget lectus. Etiam consequat sapien mauris, eget consectetur magna imperdiet eget. Nunc sollicitudin luctus velit, in commodo nulla adipiscing fermentum. Fusce nisi sapien, posuere vitae metus sit amet, facilisis sollicitudin dui. Fusce ultricies auctor enim sit amet iaculis. Morbi at vestibulum enim, eget adipiscing eros.

Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non.

Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.');
        $coupon1->setAmount(10.0);
        $coupon1->setIsUsed(true);
        $coupon1->setIsEnabled(true);
        $date = new \DateTime();
        $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months")));
        $condition1 = new MatchForTotalAmount($facade);
        $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL);
        $values = array(MatchForTotalAmount::CART_TOTAL => 40.0, MatchForTotalAmount::CART_CURRENCY => 'EUR');
        $condition1->setValidatorsFromForm($operators, $values);
        $condition2 = new MatchForTotalAmount($facade);
        $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL);
        $values = array(MatchForTotalAmount::CART_TOTAL => 400.0, MatchForTotalAmount::CART_CURRENCY => 'EUR');
        $condition2->setValidatorsFromForm($operators, $values);
        $conditions = new ConditionCollection();
        $conditions[] = $condition1;
        $conditions[] = $condition2;
        $serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
        $coupon1->setSerializedConditions($serializedConditions);
        $coupon1->setMaxUsage(40);
        $coupon1->setIsCumulative(true);
        $coupon1->setIsRemovingPostage(true);
        $coupon1->setIsAvailableOnSpecialOffers(true);
        return $coupon1;
    }
示例#2
0
 /**
  * Test condition serialization if collection is empty
  *
  * @covers Thelia\Condition\ConditionFactory::serializeConditionCollection
  */
 public function testSerializeConditionCollectionEmpty()
 {
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     /** @var FacadeInterface $stubFacade */
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $currencies = CurrencyQuery::create();
     $currencies = $currencies->find();
     $stubFacade->expects($this->any())->method('getAvailableCurrencies')->will($this->returnValue($currencies));
     $stubContainer = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\Container')->disableOriginalConstructor()->getMock();
     $stubContainer->expects($this->any())->method('get')->will($this->returnValue(new MatchForEveryone($stubFacade)));
     $stubContainer->expects($this->any())->method('has')->will($this->returnValue(true));
     $stubFacade->expects($this->any())->method('getContainer')->will($this->returnValue($stubContainer));
     $conditions = new ConditionCollection();
     $conditionFactory = new ConditionFactory($stubContainer);
     $conditionNone = new MatchForEveryone($stubFacade);
     $expectedCollection = new ConditionCollection();
     $expectedCollection[] = $conditionNone;
     $expected = $conditionFactory->serializeConditionCollection($expectedCollection);
     $actual = $conditionFactory->serializeConditionCollection($conditions);
     $this->assertEquals($expected, $actual);
 }
 /**
  * Check invalid currency
  *
  * @covers Thelia\Condition\Implementation\ConditionAbstract::isPriceValid
  * @expectedException \Thelia\Exception\InvalidConditionValueException
  *
  */
 public function testPriceAsZero()
 {
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     /** @var FacadeInterface $stubFacade */
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $currencies = CurrencyQuery::create();
     $currencies = $currencies->find();
     $stubFacade->expects($this->any())->method('getAvailableCurrencies')->will($this->returnValue($currencies));
     $condition1 = new MatchForTotalAmount($stubFacade);
     $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::EQUAL, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL);
     $values = array(MatchForTotalAmount::CART_TOTAL => 0.0, MatchForTotalAmount::CART_CURRENCY => 'EUR');
     $condition1->setValidatorsFromForm($operators, $values);
     $stubContainer = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\Container')->disableOriginalConstructor()->getMock();
     $stubContainer->expects($this->any())->method('get')->will($this->returnValue($condition1));
     $stubContainer->expects($this->any())->method('has')->will($this->returnValue(true));
     $stubFacade->expects($this->any())->method('getContainer')->will($this->returnValue($stubContainer));
     $conditionFactory = new ConditionFactory($stubContainer);
     $collection = new ConditionCollection();
     $collection[] = $condition1;
     $serialized = $conditionFactory->serializeConditionCollection($collection);
     $conditionFactory->unserializeConditionCollection($serialized);
 }