diff --git a/tests/Integration/Einvoice/FACT1Test.php b/tests/Integration/Einvoice/FACT1Test.php index 09364f5fbd5b..c33b9b73009f 100644 --- a/tests/Integration/Einvoice/FACT1Test.php +++ b/tests/Integration/Einvoice/FACT1Test.php @@ -29,26 +29,34 @@ class FACT1Test extends TestCase } -// public function testValidationFact1() -// { + public function testValidationFact1() + { -// $files = [ -// 'tests/Integration/Einvoice/samples/fact1.xml', -// ]; + $files = [ + 'tests/Integration/Einvoice/samples/fact1_no_prefixes.xml', + ]; -// foreach($files as $f) { + foreach($files as $f) { -// $xml = file_get_contents($f); + $xml = file_get_contents($f); -// // Remove namespaces and prefixes -// $xmlWithoutNamespacesAndPrefixes = $this->removeNamespacesAndPrefixes($xml); + $xml = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA); + $json = json_encode($xml); + $array = json_decode($json, true); -// // Output the result -// nlog($xmlWithoutNamespacesAndPrefixes); + $i = Invoice::from($array); + + $rules = Invoice::getValidationRules($array); + + $this->assertIsArray($rules); + $validation_array = Invoice::validate($array); -// } + $this->assertIsArray($validation_array); + + } + } public function removeNamespacesFromArray($data) @@ -65,10 +73,7 @@ class FACT1Test extends TestCase } if (isset($item['attributes'])) { unset($item['attributes']); - // Process attributes if needed - // $item['attributes'] = array_map(function ($attr) { - // return preg_replace('/^\{\}(.+)/', '$1', $attr); - // }, $item['attributes']); + } } } @@ -77,68 +82,68 @@ class FACT1Test extends TestCase -function convertToKeyValue($data) -{ - $result = []; - foreach ($data as $item) { - // Remove namespace prefix if present - $name = preg_replace('/^\{\}(.+)/', '$1', $item['name']); - $result[$name] = $item['value']; - } - return $result; -} +// function convertToKeyValue($data) +// { +// $result = []; +// foreach ($data as $item) { +// // Remove namespace prefix if present +// $name = preg_replace('/^\{\}(.+)/', '$1', $item['name']); +// $result[$name] = $item['value']; +// } +// return $result; +// } -public function keyValueDeserializer(Reader $reader) -{ - $values = []; - $reader->read(); - $reader->next(); - foreach ($reader->parseGetElements() as $element) { - // Strip the namespace prefix - echo "merp".PHP_EOL; - $name = preg_replace('/^\{\}.*/', '', $element['name']); - $values[$name] = $element['value']; - } - return $values; -} +// public function keyValueDeserializer(Reader $reader) +// { +// $values = []; +// $reader->read(); +// $reader->next(); +// foreach ($reader->parseGetElements() as $element) { +// // Strip the namespace prefix +// echo "merp".PHP_EOL; +// $name = preg_replace('/^\{\}.*/', '', $element['name']); +// $values[$name] = $element['value']; +// } +// return $values; +// } - public function testFactToArray() - { + // public function testFactToArray() + // { - $xml = file_get_contents('tests/Integration/Einvoice/samples/fact1_no_prefixes.xml'); - $service = new Service(); + // $xml = file_get_contents('tests/Integration/Einvoice/samples/fact1_no_prefixes.xml'); + // $service = new Service(); - // $service->elementMap = [ - // '{}' => 'Sabre\Xml\Deserializer\keyValue', - // ]; + // // $service->elementMap = [ + // // '{}' => 'Sabre\Xml\Deserializer\keyValue', + // // ]; - // $service->elementMap = [ - // '{}*' => function (Reader $reader) use ($service) { - // return $this->keyValueDeserializer($reader); - // } - // ]; + // // $service->elementMap = [ + // // '{}*' => function (Reader $reader) use ($service) { + // // return $this->keyValueDeserializer($reader); + // // } + // // ]; - $result = $this->removeNamespacesFromArray($service->parse($xml)); + // $result = $this->removeNamespacesFromArray($service->parse($xml)); - // Convert parsed XML to key-value array - if (isset($result['value']) && is_array($result['value'])) { - $keyValueArray = $this->convertToKeyValue($result['value']); - } else { - $keyValueArray = []; - } + // // Convert parsed XML to key-value array + // if (isset($result['value']) && is_array($result['value'])) { + // $keyValueArray = $this->convertToKeyValue($result['value']); + // } else { + // $keyValueArray = []; + // } - // Output the result - nlog($keyValueArray); + // // Output the result + // nlog($keyValueArray); - // nlog($cleanedArray); - nlog($service->parse($xml)); + // // nlog($cleanedArray); + // nlog($service->parse($xml)); - } + // } // Output the result // ($xmlWithoutNamespaces); @@ -183,16 +188,16 @@ public function keyValueDeserializer(Reader $reader) // } - private function extractName($name): string - { + // private function extractName($name): string + // { - $pattern = '/\{[^{}]*\}([^{}]*)/'; + // $pattern = '/\{[^{}]*\}([^{}]*)/'; - if (preg_match($pattern, $name, $matches)) { - $extracted = $matches[1]; - return $extracted; - } + // if (preg_match($pattern, $name, $matches)) { + // $extracted = $matches[1]; + // return $extracted; + // } - return $name; - } + // return $name; + // } } \ No newline at end of file diff --git a/tests/Integration/Einvoice/samples/fact1_no_prefixes.xml b/tests/Integration/Einvoice/samples/fact1_no_prefixes.xml index 137b1e191255..1f34e62e3090 100644 --- a/tests/Integration/Einvoice/samples/fact1_no_prefixes.xml +++ b/tests/Integration/Einvoice/samples/fact1_no_prefixes.xml @@ -57,7 +57,7 @@ Someone - + 88282819832 some@email.com