コード例 #1
0
 /**
  * Check the Rules serialization module
  */
 public function testBuild()
 {
     $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 MatchForTotalAmount($stubFacade)));
     $stubContainer->expects($this->any())->method('has')->will($this->returnValue(true));
     $stubFacade->expects($this->any())->method('getContainer')->will($this->returnValue($stubContainer));
     $condition1 = new MatchForTotalAmount($stubFacade);
     $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);
     $conditionFactory = new ConditionFactory($stubContainer);
     $ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values);
     $expected = $condition1;
     $actual = $ruleManager1;
     $this->assertEquals($expected, $actual);
     $this->assertEquals($condition1->getServiceId(), $ruleManager1->getServiceId());
     $this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators());
 }
コード例 #2
0
 /**
  * Check validator
  *
  * @covers Thelia\Condition\Implementation\MatchForTotalAmount::generateInputs
  *
  */
 public function testGetValidator()
 {
     $stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
     /** @var FacadeInterface $stubFacade */
     $condition1 = new MatchForTotalAmount($stubFacade);
     $operators = array(MatchForTotalAmount::CART_TOTAL => Operators::EQUAL, MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL);
     $values = array(MatchForTotalAmount::CART_TOTAL => 400.0, MatchForTotalAmount::CART_CURRENCY => 'EUR');
     $condition1->setValidatorsFromForm($operators, $values);
     $actual = $condition1->getValidators();
     $validators = array('inputs' => array(MatchForTotalAmount::CART_TOTAL => array('availableOperators' => array('<' => 'Price', '<=' => 'Price', '==' => 'Price', '>=' => 'Price', '>' => 'Price'), 'availableValues' => '', 'value' => '', 'selectedOperator' => ''), MatchForTotalAmount::CART_CURRENCY => array('availableOperators' => array('==' => 'Price'), 'availableValues' => array('EUR' => '€', 'USD' => '$', 'GBP' => '£'), 'value' => '', 'selectedOperator' => Operators::EQUAL)), 'setOperators' => array('price' => '==', 'currency' => '=='), 'setValues' => array('price' => 400, 'currency' => 'EUR'));
     $expected = $validators;
     $this->assertEquals($expected, $actual);
 }