Skip to content

Commit

Permalink
Test using saxonb-xslt, add procedureCreateCadenaOrigenExpectedContent
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Nov 10, 2017
1 parent d45d3ca commit 55e099d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
72 changes: 65 additions & 7 deletions tests/CfdiUtilsTests/CadenaOrigen/CadenaOrigenBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,75 @@

class CadenaOrigenBuilderTest extends TestCase
{
public function testBuildWithLocalResource()
/**
* The file cfdi33-valid-cadenaorigen.txt was created using the command line util saxonb-xslt
* available in debian in the package libsaxonb-java.
* To recreate these files use the method procedureCreateCadenaOrigenExpectedContent
*
* @see procedureCreateCadenaOrigenExpectedContent
* @return array
*/
public function providerCfdiToCadenaOrigen()
{
$local = $this->downloadResourceIfNotExists(DefaultLocations::XSLT_32);
return [
['cfdi32-real.xml', 'cfdi32-real-cadenaorigen.txt', DefaultLocations::XSLT_32],
['cfdi33-valid.xml', 'cfdi33-valid-cadenaorigen.txt', DefaultLocations::XSLT_33],
];
}

$co = new CadenaOrigenBuilder();
/**
* @param $xmlLocation
* @param $expectedCadenaOrigen
* @param $xsltLocation
* @dataProvider providerCfdiToCadenaOrigen
*/
public function testCfdiToCadenaOrigen($xmlLocation, $expectedCadenaOrigen, $xsltLocation)
{
$xsltLocation = $this->downloadResourceIfNotExists($xsltLocation);

$fileCfdi = $this->utilAsset('cfdi32-real.xml');
$fileExpectedCadenaOrigen = $this->utilAsset('cfdi32-real-cadenaorigen.txt');
$xmlLocation = $this->utilAsset($xmlLocation);
$expectedCadenaOrigen = $this->utilAsset($expectedCadenaOrigen);
$expected = rtrim(file_get_contents($expectedCadenaOrigen));

$cadenaOrigen = $co->build(file_get_contents($fileCfdi), $local);
$this->assertStringEqualsFile($fileExpectedCadenaOrigen, $cadenaOrigen . "\n");
$co = new CadenaOrigenBuilder();
$cadenaOrigen = $co->build(file_get_contents($xmlLocation), $xsltLocation);
$this->assertEquals($expected, $cadenaOrigen);
}

/**
* Use this procedure to recreate the expected files using saxonb-xslt.
* It will not download anything, it will use internet locations
*
* NOTE: This procedure will not run unless you add the "test" annotation.
* @ test
*
* @param $xmlLocation
* @param $expectedCadenaOrigen
* @param $xsltLocation
* @dataProvider providerCfdiToCadenaOrigen
*/
public function procedureCreateCadenaOrigenExpectedContent($xmlLocation, $expectedCadenaOrigen, $xsltLocation)
{
$xmlLocation = $this->utilAsset($xmlLocation);
$expectedCadenaOrigen = $this->utilAsset($expectedCadenaOrigen);
// uncomment the following line if you want to use local resources instead of internet
// $xsltLocation = $this->downloadResourceIfNotExists($xsltLocation);

$saxonb = shell_exec('which saxonb-xslt');
if ('' === $saxonb) {
$this->markTestSkipped('There is no saxonb-xslt installed');
return;
}
$command = implode(' ', [
escapeshellcmd($saxonb),
escapeshellarg('-s:' . $xmlLocation),
escapeshellarg('-xsl:' . $xsltLocation),
'2>/dev/null',
]);
$cadenaOrigen = shell_exec($command);

file_put_contents($expectedCadenaOrigen, $cadenaOrigen . PHP_EOL);
$this->assertFileExists($expectedCadenaOrigen);
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/assets/cfdi33-valid-cadenaorigen.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
||3.3|A|167ABC|2017-07-05T09:09:23|01|30001000000300023708|CONDICIONES|2269400|0.00|MXN|1|2382870|I|PUE|45079|01|A39DA66B-52CA-49E3-879B-5C05185B0EF7|AAA010101AAA|ACCEM SERVICIOS EMPRESARIALES SC|601|COSC8001137NA|CARLOS CORTES SOTO|G01|01010101|00001|1.5|F52|TONELADA|ACERO|1500000|2250000|2250000|001|Tasa|0.160000|360000|2250000|002|Tasa|0.110000|247500|51888|01010101|00002|1.6|F52|TONELADA|ALUMINIO|1500|2400|2400|001|Tasa|0.160000|384|2400|002|Tasa|0.110000|264|15 48 4567 6001234|01010101|00003|1.7|F52|TONELADA|ZAMAC|10000|17000|17000|001|Tasa|0.160000|2720|17000|002|Tasa|0.110000|1870|01010101|055155|1.0|UNIDAD|PARTE EJEMPLO|1.00|1.00|15 48 4567 6981235|002|249634|249634|001|Tasa|0.160000|363104|363104||

0 comments on commit 55e099d

Please sign in to comment.