/** * @dataProvider getSchemaDefinitions */ public function testVisitAutomaton(array $xmlFiles, $name) { $xsd = new slDtdSchema(); foreach ($xmlFiles as $file) { $xsd->learnFile($file); } $visitor = new slSchemaXmlSchemaVisitor(); $result = $visitor->visit($xsd); // Read expectation from file, if available if (!is_file($file = __DIR__ . '/data/' . $name . '.xsd')) { $this->MarkTestSkipped("No comparision file ({$file}) available; Generated result:\n" . $result); } $this->assertEquals(file_get_contents($file), $result); }
/** * Visit single element in regular expression * * The return type of this method varies deping on the concrete visitor * implementation * * @param slRegularExpressionElement $element * @return mixed */ protected function visitElement(slRegularExpressionElement $element) { $schemaElement = $this->schemaVisitor->getType($element->getContent()->type); $node = $this->document->createElementNS('http://www.w3.org/2001/XMLSchema', 'element'); $node->setAttribute('name', $element->getContent()->name); if ($schemaElement->type->regularExpression instanceof slRegularExpressionEmpty && !count($schemaElement->type->attributes)) { if ($schemaElement->type->simpleTypeInferencer->inferenceType() !== 'empty') { $node->setAttribute('type', $this->schemaVisitor->getXmlSchemaSimpleType($schemaElement->type->simpleTypeInferencer)); } } else { $node->setAttribute('type', $schemaElement->type->name); } return $node; }
protected function getVisitor() { $schemaVisitor = new slSchemaXmlSchemaVisitor(); $schemaVisitor->setTypes(array('23' => new slSchemaElement('23', new slSchemaType('23')), 'a' => new slSchemaElement('a', new slSchemaType('a')), 'b' => new slSchemaElement('b', new slSchemaType('b')), 'b1' => new slSchemaElement('b1', new slSchemaType('b1')), 'b2' => new slSchemaElement('b2', new slSchemaType('b2')), 'c' => new slSchemaElement('c', new slSchemaType('c')))); return new slRegularExpressionXmlSchemaVisitor($schemaVisitor, new DOMDocument()); }