Skip to content

Commit

Permalink
fix tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
craue committed Aug 10, 2015
1 parent 51f6d26 commit 033ccef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions test/Knp/Snappy/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public function dataForBuildCommand()
'http://the.url/',
'/the/path',
array(),
"{$theBinary} 'http://the.url/' '/the/path'"
$theBinary . ' ' . escapeshellarg('http://the.url/') . ' ' . escapeshellarg('/the/path')
),
array(
$theBinary,
Expand All @@ -494,7 +494,7 @@ public function dataForBuildCommand()
'bar' => false,
'baz' => array()
),
"{$theBinary} 'http://the.url/' '/the/path'"
$theBinary . ' ' . escapeshellarg('http://the.url/') . ' ' . escapeshellarg('/the/path')
),
array(
$theBinary,
Expand All @@ -505,7 +505,7 @@ public function dataForBuildCommand()
'bar' => array('barvalue1', 'barvalue2'),
'baz' => true
),
"{$theBinary} --foo 'foovalue' --bar 'barvalue1' --bar 'barvalue2' --baz 'http://the.url/' '/the/path'"
$theBinary . ' --foo ' . escapeshellarg('foovalue') . ' --bar ' . escapeshellarg('barvalue1') . ' --bar ' . escapeshellarg('barvalue2') . ' --baz ' . escapeshellarg('http://the.url/') . ' ' . escapeshellarg('/the/path')
),
array(
$theBinary,
Expand All @@ -515,7 +515,7 @@ public function dataForBuildCommand()
'cookie' => array('session' => 'bla', 'phpsess' => 12),
'no-background' => '1',
),
"{$theBinary} --cookie 'session' 'bla' --cookie 'phpsess' '12' --no-background '1' 'http://the.url/' '/the/path'"
$theBinary . ' --cookie ' . escapeshellarg('session') . ' ' . escapeshellarg('bla') . ' --cookie ' . escapeshellarg('phpsess') . ' ' . escapeshellarg('12') . ' --no-background ' . escapeshellarg('1') . ' ' . escapeshellarg('http://the.url/') . ' ' . escapeshellarg('/the/path')
),
array(
$theBinary,
Expand All @@ -525,7 +525,7 @@ public function dataForBuildCommand()
'allow' => array('/path1', '/path2'),
'no-background' => '1',
),
"{$theBinary} --allow '/path1' --allow '/path2' --no-background '1' 'http://the.url/' '/the/path'"
$theBinary . ' --allow ' . escapeshellarg('/path1') . ' --allow ' . escapeshellarg('/path2') . ' --no-background ' . escapeshellarg('1') . ' ' . escapeshellarg('http://the.url/') . ' ' . escapeshellarg('/the/path')
),
);
}
Expand Down
14 changes: 9 additions & 5 deletions test/Knp/Snappy/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class PdfTest extends \PHPUnit_Framework_TestCase
{
const SHELL_ARG_QUOTE_REGEX = '(?:"|\')'; // escapeshellarg produces double quotes on Windows, single quotes otherwise

public function testCreateInstance()
{
$testObject = new \Knp\Snappy\Pdf();
Expand All @@ -12,22 +14,24 @@ public function testCreateInstance()

public function testThatSomething()
{
$q = self::SHELL_ARG_QUOTE_REGEX;
$testObject = new PdfSpy();

$testObject->getOutputFromHtml('<html></html>', array('footer-html' => 'footer'));
$this->assertRegExp("/emptyBinary --lowquality --footer-html '.*' '.*' '.*'/", $testObject->getLastCommand());
$this->assertRegExp('/emptyBinary --lowquality --footer-html '.$q.'.*'.$q.' '.$q.'.*'.$q.' '.$q.'.*'.$q.'/', $testObject->getLastCommand());

$testObject->getOutputFromHtml('<html></html>', array());
$this->assertRegExp("/emptyBinary --lowquality '.*' '.*'/", $testObject->getLastCommand());
$this->assertRegExp('/emptyBinary --lowquality '.$q.'.*'.$q.' '.$q.'.*'.$q.'/', $testObject->getLastCommand());
}

public function testThatSomethingUsingTmpFolder()
{
$q = self::SHELL_ARG_QUOTE_REGEX;
$testObject = new PdfSpy();
$testObject->setTemporaryFolder(__DIR__);

$testObject->getOutputFromHtml('<html></html>', array('footer-html' => 'footer'));
$this->assertRegExp("/emptyBinary --lowquality --footer-html '.*' '.*' '.*'/", $testObject->getLastCommand());
$this->assertRegExp('/emptyBinary --lowquality --footer-html '.$q.'.*'.$q.' '.$q.'.*'.$q.' '.$q.'.*'.$q.'/', $testObject->getLastCommand());
}

public function testThatSomethingUsingNonexistentTmpFolder()
Expand All @@ -40,12 +44,12 @@ public function testThatSomethingUsingNonexistentTmpFolder()

public function testOptionsAreCorrectlySavedIfItIsLocalOrRemoteContent()
{
$q = self::SHELL_ARG_QUOTE_REGEX;
$testObject = new PdfSpy();
$testObject->setTemporaryFolder(__DIR__);

$testObject->getOutputFromHtml('<html></html>', array('footer-html' => 'footer', 'xsl-style-sheet' => 'http://google.com'));
$this->assertRegExp("/emptyBinary --lowquality --footer-html '.*.html' --xsl-style-sheet '.*.xsl' '.*.html' '.*.pdf'/", $testObject->getLastCommand());

$this->assertRegExp('/emptyBinary --lowquality --footer-html '.$q.'.*\.html'.$q.' --xsl-style-sheet '.$q.'.*\.xsl'.$q.' '.$q.'.*\.html'.$q.' '.$q.'.*\.pdf'.$q.'/', $testObject->getLastCommand());
}

public function testRemovesLocalFilesOnDestruct()
Expand Down

0 comments on commit 033ccef

Please sign in to comment.