-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
334 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "Resources/vendor/symfony"] | ||
path = Resources/vendor/symfony | ||
url = https://github.com/symfony/symfony.git | ||
[submodule "Resources/vendor/snappy"] | ||
path = Resources/vendor/snappy | ||
url = https://github.com/knplabs/snappy.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Knp\Bundle\SnappyBundle\Tests; | ||
|
||
use Symfony\Component\HttpKernel\Util\Filesystem; | ||
|
||
class FunctionalTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $kernel; | ||
private $filesystem; | ||
|
||
public function setUp() | ||
{ | ||
$this->kernel = new TestKernel(uniqid(), false); | ||
|
||
$this->filesystem = new Filesystem(); | ||
$this->filesystem->mkdir($this->kernel->getCacheDir()); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
$this->filesystem->remove($this->kernel->getCacheDir()); | ||
} | ||
|
||
public function testServicesAreBothAvailableOutOfTheBox() | ||
{ | ||
$this->kernel->setConfigurationFilename(__DIR__.'/fixtures/config/out_of_the_box.yml'); | ||
$this->kernel->boot(); | ||
|
||
$container = $this->kernel->getContainer(); | ||
|
||
$this->assertTrue($container->has('knp_snappy.pdf'), 'The pdf service is available.'); | ||
|
||
$pdf = $container->get('knp_snappy.pdf'); | ||
|
||
$this->assertInstanceof('Knp\Bundle\SnappyBundle\Snappy\LoggableGenerator', $pdf); | ||
$this->assertInstanceof('Knp\Snappy\Pdf', $pdf->getInternalGenerator()); | ||
$this->assertEquals('wkhtmltopdf', $pdf->getInternalGenerator()->getBinary()); | ||
|
||
$this->assertTrue($container->has('knp_snappy.image'), 'The image service is available.'); | ||
|
||
$image = $container->get('knp_snappy.image'); | ||
|
||
$this->assertInstanceof('Knp\Bundle\SnappyBundle\Snappy\LoggableGenerator', $image); | ||
$this->assertInstanceof('Knp\Snappy\Image', $image->getInternalGenerator()); | ||
$this->assertEquals('wkhtmltoimage', $image->getInternalGenerator()->getBinary()); | ||
} | ||
|
||
public function testChangeBinaries() | ||
{ | ||
$this->kernel->setConfigurationFilename(__DIR__.'/fixtures/config/change_binaries.yml'); | ||
$this->kernel->boot(); | ||
|
||
$container = $this->kernel->getContainer(); | ||
|
||
$this->assertTrue($container->has('knp_snappy.pdf')); | ||
|
||
$pdf = $container->get('knp_snappy.pdf'); | ||
|
||
$this->assertEquals('/custom/binary/for/wkhtmltopdf', $pdf->getInternalGenerator()->getBinary()); | ||
|
||
$this->assertTrue($container->has('knp_snappy.image')); | ||
|
||
$image = $container->get('knp_snappy.image'); | ||
|
||
$this->assertEquals('/custom/binary/for/wkhtmltoimage', $image->getInternalGenerator()->getBinary()); | ||
} | ||
|
||
public function testDisablePdf() | ||
{ | ||
$this->kernel->setConfigurationFilename(__DIR__.'/fixtures/config/disable_pdf.yml'); | ||
$this->kernel->boot(); | ||
|
||
$container = $this->kernel->getContainer(); | ||
|
||
$this->assertFalse($container->has('knp_snappy.pdf'), 'The pdf service is NOT available.'); | ||
$this->assertTrue($container->has('knp_snappy.image'), 'The image service is available.'); | ||
} | ||
|
||
public function testDisableImage() | ||
{ | ||
$this->kernel->setConfigurationFilename(__DIR__.'/fixtures/config/disable_image.yml'); | ||
$this->kernel->boot(); | ||
|
||
$container = $this->kernel->getContainer(); | ||
|
||
$this->assertTrue($container->has('knp_snappy.pdf'), 'The pdf service is available.'); | ||
$this->assertFalse($container->has('knp_snappy.image'), 'The image service is NOT available.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace Knp\Bundle\SnappyBundle\Tests\Snappy; | ||
|
||
use Knp\Bundle\SnappyBundle\Snappy\LoggableGenerator; | ||
|
||
class LoggableGeneratorTests extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGenerate() | ||
{ | ||
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); | ||
$internal | ||
->expects($this->once()) | ||
->method('generate') | ||
->with( | ||
$this->equalTo('the_input_file'), | ||
$this->equalTo('the_output_file'), | ||
$this->equalTo(array('foo' => 'bar')), | ||
$this->equalTo(true) | ||
) | ||
; | ||
|
||
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface'); | ||
$logger | ||
->expects($this->once()) | ||
->method('debug') | ||
->with($this->equalTo('Generate from file (the_input_file) to file (the_output_file).')) | ||
; | ||
|
||
$generator = new LoggableGenerator($internal, $logger); | ||
$generator->generate('the_input_file', 'the_output_file', array('foo' => 'bar'), true); | ||
} | ||
|
||
public function testGenerateFromHtml() | ||
{ | ||
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); | ||
$internal | ||
->expects($this->once()) | ||
->method('generateFromHtml') | ||
->with( | ||
$this->equalTo('<html>foo</html>'), | ||
$this->equalTo('the_output_file'), | ||
$this->equalTo(array('foo' => 'bar')), | ||
$this->equalTo(true) | ||
) | ||
; | ||
|
||
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface'); | ||
$logger | ||
->expects($this->once()) | ||
->method('debug') | ||
->with($this->equalTo('Generate from HTML (<html>foo</html>) to file (the_output_file).')) | ||
; | ||
|
||
$generator = new LoggableGenerator($internal, $logger); | ||
$generator->generateFromHtml('<html>foo</html>', 'the_output_file', array('foo' => 'bar'), true); | ||
} | ||
|
||
public function testOutput() | ||
{ | ||
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); | ||
$internal | ||
->expects($this->once()) | ||
->method('getOutput') | ||
->with( | ||
$this->equalTo('the_input_file'), | ||
$this->equalTo(array('foo' => 'bar')) | ||
) | ||
; | ||
|
||
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface'); | ||
$logger | ||
->expects($this->once()) | ||
->method('debug') | ||
->with($this->equalTo('Output from file (the_input_file).')) | ||
; | ||
|
||
$generator = new LoggableGenerator($internal, $logger); | ||
$generator->getOutput('the_input_file', array('foo' => 'bar'), true); | ||
} | ||
|
||
public function testOutputFromHtml() | ||
{ | ||
$internal = $this->getMock('Knp\Snappy\GeneratorInterface'); | ||
$internal | ||
->expects($this->once()) | ||
->method('getOutputFromHtml') | ||
->with( | ||
$this->equalTo('<html>foo</html>'), | ||
$this->equalTo(array('foo' => 'bar')) | ||
) | ||
; | ||
|
||
$logger = $this->getMock('Symfony\Component\HttpKernel\Log\LoggerInterface'); | ||
$logger | ||
->expects($this->once()) | ||
->method('debug') | ||
->with($this->equalTo('Output from HTML (<html>foo</html>).')) | ||
; | ||
|
||
$generator = new LoggableGenerator($internal, $logger); | ||
$generator->getOutputFromHtml('<html>foo</html>', array('foo' => 'bar'), true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Knp\Bundle\SnappyBundle\Tests; | ||
|
||
use Symfony\Component\HttpKernel\Kernel; | ||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
||
class TestKernel extends Kernel | ||
{ | ||
private $configurationFilename; | ||
|
||
/** | ||
* Defines the configuration filename | ||
* | ||
* @param string $filename | ||
*/ | ||
public function setConfigurationFilename($filename) | ||
{ | ||
$this->configurationFilename = $filename; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function registerBundles() | ||
{ | ||
return array( | ||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new \Knp\Bundle\SnappyBundle\KnpSnappyBundle() | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function registerContainerConfiguration(LoaderInterface $loader) | ||
{ | ||
$loader->load($this->configurationFilename); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
require_once $_SERVER['SYMFONY'].'/Symfony/Component/ClassLoader/UniversalClassLoader.php'; | ||
|
||
use Symfony\Component\ClassLoader\UniversalClassLoader; | ||
|
||
$loader = new UniversalClassLoader(); | ||
$loader->registerNamespaces(array( | ||
'Symfony' => $_SERVER['SYMFONY'], | ||
'Knp\\Snappy' => $_SERVER['SNAPPY'], | ||
)); | ||
$loader->register(); | ||
|
||
spl_autoload_register(function($class) { | ||
if (0 === strpos($class, 'Knp\\Bundle\\SnappyBundle\\')) { | ||
require_once __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 3)).'.php'; | ||
return true; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
framework: | ||
secret: ThisIsNotReallyASecretSoPleaseChangeIt | ||
charset: UTF-8 | ||
router: { resource: "%kernel.root_dir%/config/routing.yml" } | ||
form: true | ||
csrf_protection: true | ||
validation: { enabled: true, enable_annotations: true } | ||
templating: { engines: ['php'] } #assets_version: SomeVersionScheme | ||
session: | ||
default_locale: en | ||
lifetime: 3600 | ||
auto_start: true | ||
translator: { fallback: en } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
imports: | ||
- { resource: 'base.yml' } | ||
|
||
knp_snappy: | ||
pdf: | ||
binary: /custom/binary/for/wkhtmltopdf | ||
image: | ||
binary: /custom/binary/for/wkhtmltoimage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
imports: | ||
- { resource: 'base.yml' } | ||
|
||
knp_snappy: | ||
image: | ||
enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
imports: | ||
- { resource: 'base.yml' } | ||
|
||
knp_snappy: | ||
pdf: | ||
enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
imports: | ||
- { resource: 'base.yml' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
|
||
<phpunit | ||
backupGlobals = "false" | ||
backupStaticAttributes = "false" | ||
colors = "true" | ||
convertErrorsToExceptions = "true" | ||
convertNoticesToExceptions = "true" | ||
convertWarningsToExceptions = "true" | ||
processIsolation = "false" | ||
stopOnFailure = "false" | ||
syntaxCheck = "false" | ||
bootstrap = "./Tests/bootstrap.php.dist" > | ||
|
||
<testsuites> | ||
<testsuite name="KnpSnappyBundle Test Suite"> | ||
<directory>./Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<php> | ||
<server name="SYMFONY" value="./Resources/vendor/symfony/src" /> | ||
<server name="SNAPPY" value="./Resources/vendor/snappy/src" /> | ||
</php> | ||
|
||
|
||
<filter> | ||
<whitelist> | ||
<directory>.</directory> | ||
<exclude> | ||
<directory>./Tests</directory> | ||
</exclude> | ||
</whitelist> | ||
</filter> | ||
|
||
</phpunit> |