/** @test */
 public function registeredOperatorParser()
 {
     $operatorParserMock = $this->getMockBuilder('Superruzafa\\Rules\\Loader\\Xml\\OperatorParser')->setMethods(array('getElementName'))->getMockForAbstractClass();
     $operatorParserMock->expects($this->exactly(2))->method('getElementName')->will($this->returnValue('JARL'));
     OperatorParserFactoryMethod::registerParser($operatorParserMock);
     $this->assertSame($operatorParserMock, OperatorParserFactoryMethod::create('JARL'));
     OperatorParserFactoryMethod::unregisterParser($operatorParserMock);
 }
示例#2
0
 /**
  * Parses the operands defined in an XML element and adds them to an operator
  *
  * @param Operator $operator
  * @param \DOMElement $operatorElement
  * @param \DOMXPath $xpath
  * @return Operator
  */
 protected function parseOperands(Operator $operator, \DOMElement $operatorElement, \DOMXPath $xpath)
 {
     foreach ($operatorElement->attributes as $attribute) {
         $operator->addOperand(Primitive::create($attribute->nodeValue));
     }
     $nodes = $xpath->query(sprintf('*[namespace-uri() = "%s"]', XmlLoader::XMLNS_LOADER), $operatorElement);
     foreach ($nodes as $node) {
         $parser = OperatorParserFactoryMethod::create($node->localName);
         $operator->addOperand($parser->parse($node, $xpath));
     }
     return $operator;
 }
示例#3
0
 /** @test */
 public function parseElementOperands()
 {
     $operand = $this->getMockForAbstractClass('Superruzafa\\Rules\\Expression');
     $operatorParser = $this->getMockBuilder('Superruzafa\\Rules\\Loader\\Xml\\OperatorParser')->setMethods(array('getElementName', 'parse'))->getMockForAbstractClass();
     $operatorParser->expects($this->once())->method('getElementName')->will($this->returnValue('operator-element-name'));
     $operatorParser->expects($this->exactly(2))->method('parse')->will($this->returnValue($operand));
     OperatorParserFactoryMethod::registerParser($operatorParser);
     $doc = new \DOMDocument();
     $operatorElement = $doc->createElement('operator-element-name');
     $xpath = $this->getMockBuilder('DOMXPath')->disableOriginalConstructor()->setMethods(array('query'))->getMock();
     $xpath->expects($this->once())->method('query')->will($this->returnValue(array($operatorElement, $operatorElement)));
     $operator = $this->getMockBuilder('Superruzafa\\Rules\\Expression\\Operator')->setMethods(array('addOperand'))->getMockForAbstractClass();
     $operator->expects($this->exactly(2))->method('addOperand')->with($operand);
     $class = new \ReflectionObject($this->operator);
     $method = $class->getMethod('parseOperands');
     $method->setAccessible(true);
     $this->assertSame($operator, $method->invoke($this->operator, $operator, $operatorElement, $xpath));
 }
示例#4
0
 private function parseConditionElement(DOMElement $conditionElement)
 {
     $operatorElements = $this->xpath->query(sprintf('*[namespace-uri() = "%s"]', self::XMLNS_LOADER), $conditionElement);
     $operators = array();
     foreach ($operatorElements as $operatorElement) {
         $operatorParser = OperatorParserFactoryMethod::create($operatorElement->localName);
         $operators[] = $operatorParser->parse($operatorElement, $this->xpath);
     }
     switch (count($operators)) {
         case 0:
             return Boolean::true();
         case 1:
             return $operators[0];
         default:
             $and = new AndOp();
             array_map(function ($operator) use($and) {
                 $and->addOperand($operator);
             }, $operators);
             return $and;
     }
 }