Skip to content

Commit

Permalink
Added test for Issue #133
Browse files Browse the repository at this point in the history
  • Loading branch information
HorstOeko committed Oct 6, 2024
1 parent 5d150f4 commit ccafcda
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions tests/testcases/ProfileResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace horstoeko\zugferd\tests\testcases;

use horstoeko\zugferd\exception\ZugferdUnknownProfileIdException;
use Throwable;
use SimpleXMLElement;
use horstoeko\zugferd\tests\TestCase;
use horstoeko\zugferd\ZugferdProfileResolver;
use horstoeko\zugferd\ZugferdProfiles;
use horstoeko\zugferd\ZugferdProfileResolver;
use horstoeko\zugferd\exception\ZugferdUnknownProfileIdException;

class ProfileResolverTest extends TestCase
{
Expand Down Expand Up @@ -79,6 +81,11 @@ private function deliverInvalidXml(): string
HDR;
}

private function deliverStringWhichIsNotXml(): string
{
return "This is not a XML";
}

public function testResolveEn16931()
{
$resolved = ZugferdProfileResolver::resolve($this->deliverEn16931Header());
Expand Down Expand Up @@ -224,4 +231,41 @@ public function testResolveProfileDefByIdUnknown()

ZugferdProfileResolver::resolveProfileDefById(-1);
}

public function testResolveNotXml()
{
// Test clear LibXml Errors, when error previously occourred (See issue #133)

$prevUseInternalErrors = \libxml_use_internal_errors(true);

try {
libxml_clear_errors();
$xmldocument = new SimpleXMLElement($this->deliverStringWhichIsNotXml());
} catch (Throwable $e) {
// Do nothing
}

$resolved = ZugferdProfileResolver::resolveProfileDef($this->deliverEn16931Header());

$this->assertIsArray($resolved);
$this->assertArrayHasKey("name", $resolved);
$this->assertArrayHasKey("altname", $resolved);
$this->assertArrayHasKey("description", $resolved);
$this->assertArrayHasKey("contextparameter", $resolved);
$this->assertArrayHasKey("businessprocess", $resolved);
$this->assertArrayHasKey("attachmentfilename", $resolved);
$this->assertArrayHasKey("xmpname", $resolved);
$this->assertArrayHasKey("xsdfilename", $resolved);
$this->assertArrayHasKey("schematronfilename", $resolved);

$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['name'], $resolved["name"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['altname'], $resolved["altname"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['description'], $resolved["description"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['contextparameter'], $resolved["contextparameter"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['businessprocess'], $resolved["businessprocess"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['attachmentfilename'], $resolved["attachmentfilename"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['xmpname'], $resolved["xmpname"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['xsdfilename'], $resolved["xsdfilename"]);
$this->assertEquals(ZugferdProfiles::PROFILEDEF[ZugferdProfiles::PROFILE_EN16931]['schematronfilename'], $resolved["schematronfilename"]);
}
}

0 comments on commit ccafcda

Please sign in to comment.