2021-02-26 16:16:17 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class QRFpdfTest
|
|
|
|
*
|
|
|
|
* @filesource QRFpdfTest.php
|
|
|
|
* @created 03.06.2020
|
|
|
|
* @package chillerlan\QRCodeTest\Output
|
|
|
|
* @author smiley <smiley@chillerlan.net>
|
|
|
|
* @copyright 2020 smiley
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace chillerlan\QRCodeTest\Output;
|
|
|
|
|
|
|
|
use FPDF;
|
|
|
|
use chillerlan\QRCode\Output\{QRFpdf, QROutputInterface};
|
|
|
|
use chillerlan\QRCode\{QRCode, QROptions};
|
|
|
|
|
|
|
|
use function class_exists, substr;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests the QRFpdf output module
|
|
|
|
*/
|
|
|
|
class QRFpdfTest extends QROutputTestAbstract{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function setUp():void{
|
|
|
|
|
|
|
|
if(!class_exists(FPDF::class)){
|
|
|
|
$this->markTestSkipped('FPDF not available');
|
2022-07-02 14:01:51 +00:00
|
|
|
|
|
|
|
/** @noinspection PhpUnreachableStatementInspection */
|
2021-02-26 16:16:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
protected function getOutputInterface(QROptions $options):QROutputInterface{
|
|
|
|
return new QRFpdf($options, $this->matrix);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function types():array{
|
|
|
|
return [
|
|
|
|
'fpdf' => [QRCode::OUTPUT_FPDF],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-02-26 16:16:17 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function testSetModuleValues():void{
|
|
|
|
|
|
|
|
$this->options->moduleValues = [
|
|
|
|
// data
|
|
|
|
1024 => [0, 0, 0],
|
|
|
|
4 => [255, 255, 255],
|
|
|
|
];
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
$this->outputInterface = $this->getOutputInterface($this->options);
|
2021-02-26 16:16:17 +00:00
|
|
|
$this->outputInterface->dump();
|
|
|
|
|
|
|
|
$this::assertTrue(true); // tricking the code coverage
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
2022-07-02 14:01:51 +00:00
|
|
|
* @dataProvider types
|
2021-02-26 16:16:17 +00:00
|
|
|
*/
|
2022-07-02 14:01:51 +00:00
|
|
|
public function testRenderImage(string $type):void{
|
2021-02-26 16:16:17 +00:00
|
|
|
$this->options->outputType = $type;
|
|
|
|
$this->options->imageBase64 = false;
|
|
|
|
|
|
|
|
// substr() to avoid CreationDate
|
2022-07-02 14:01:51 +00:00
|
|
|
$expected = substr(file_get_contents(__DIR__.'/samples/'.$type), 0, 2500);
|
|
|
|
$actual = substr((new QRCode($this->options))->render('test'), 0, 2500);
|
2021-02-26 16:16:17 +00:00
|
|
|
|
|
|
|
$this::assertSame($expected, $actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testOutputGetResource():void{
|
|
|
|
$this->options->returnResource = true;
|
2022-07-02 14:01:51 +00:00
|
|
|
$this->outputInterface = $this->getOutputInterface($this->options);
|
2021-02-26 16:16:17 +00:00
|
|
|
|
|
|
|
$this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|