summaryrefslogtreecommitdiff
path: root/vendor/chillerlan/php-qrcode/tests/Output
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-26 19:16:17 +0300
committerAndrew Dolgov <[email protected]>2021-02-26 19:16:17 +0300
commit3fd785654372d493c031d9b541ab33a881023a32 (patch)
tree0a76cb410217074378de3d7012b95754cd3c7e6f /vendor/chillerlan/php-qrcode/tests/Output
parentbc4475b6698f5a74e475674aa7af43253c459892 (diff)
* switch to composer for qrcode and otp dependencies
* move most OTP-related stuff into userhelper * remove old phpqrcode and otphp libraries
Diffstat (limited to 'vendor/chillerlan/php-qrcode/tests/Output')
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Output/QRFpdfTest.php83
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Output/QRImageTest.php69
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Output/QRImagickTest.php66
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Output/QRMarkupTest.php79
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php71
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Output/QRStringTest.php56
6 files changed, 424 insertions, 0 deletions
diff --git a/vendor/chillerlan/php-qrcode/tests/Output/QRFpdfTest.php b/vendor/chillerlan/php-qrcode/tests/Output/QRFpdfTest.php
new file mode 100644
index 000000000..1b49182d2
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Output/QRFpdfTest.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * Class QRFpdfTest
+ *
+ * @filesource QRFpdfTest.php
+ * @created 03.06.2020
+ * @package chillerlan\QRCodeTest\Output
+ * @author smiley <[email protected]>
+ * @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{
+
+ protected $FQCN = QRFpdf::class;
+
+ /**
+ * @inheritDoc
+ * @internal
+ */
+ public function setUp():void{
+
+ if(!class_exists(FPDF::class)){
+ $this->markTestSkipped('FPDF not available');
+ return;
+ }
+
+ parent::setUp();
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function testSetModuleValues():void{
+
+ $this->options->moduleValues = [
+ // data
+ 1024 => [0, 0, 0],
+ 4 => [255, 255, 255],
+ ];
+
+ $this->outputInterface->dump();
+
+ $this::assertTrue(true); // tricking the code coverage
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function testRenderImage():void{
+ $type = QRCode::OUTPUT_FPDF;
+
+ $this->options->outputType = $type;
+ $this->options->imageBase64 = false;
+ $this->outputInterface->dump($this::cachefile.$type);
+
+ // substr() to avoid CreationDate
+ $expected = substr(file_get_contents($this::cachefile.$type), 0, 2000);
+ $actual = substr($this->outputInterface->dump(), 0, 2000);
+
+ $this::assertSame($expected, $actual);
+ }
+
+ public function testOutputGetResource():void{
+ $this->options->returnResource = true;
+
+ $this->setOutputInterface();
+
+ $this::assertInstanceOf(FPDF::class, $this->outputInterface->dump());
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Output/QRImageTest.php b/vendor/chillerlan/php-qrcode/tests/Output/QRImageTest.php
new file mode 100644
index 000000000..34ecf4f91
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Output/QRImageTest.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Class QRImageTest
+ *
+ * @filesource QRImageTest.php
+ * @created 24.12.2017
+ * @package chillerlan\QRCodeTest\Output
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Output;
+
+use chillerlan\QRCode\{QRCode, Output\QRImage};
+
+class QRImageTest extends QROutputTestAbstract{
+
+ protected $FQCN = QRImage::class;
+
+ public function types(){
+ return [
+ 'png' => [QRCode::OUTPUT_IMAGE_PNG],
+ 'gif' => [QRCode::OUTPUT_IMAGE_GIF],
+ 'jpg' => [QRCode::OUTPUT_IMAGE_JPG],
+ ];
+ }
+
+ /**
+ * @dataProvider types
+ * @param $type
+ */
+ public function testImageOutput($type){
+ $this->options->outputType = $type;
+ $this->options->imageBase64 = false;
+
+ $this->setOutputInterface();
+ $this->outputInterface->dump($this::cachefile.$type);
+ $img = $this->outputInterface->dump();
+
+ if($type === QRCode::OUTPUT_IMAGE_JPG){ // jpeg encoding may cause different results
+ $this->markAsRisky();
+ }
+
+ $this->assertSame($img, file_get_contents($this::cachefile.$type));
+ }
+
+ public function testSetModuleValues(){
+
+ $this->options->moduleValues = [
+ // data
+ 1024 => [0, 0, 0],
+ 4 => [255, 255, 255],
+ ];
+
+ $this->setOutputInterface()->dump();
+
+ $this->assertTrue(true); // tricking the code coverage
+ }
+
+ public function testOutputGetResource():void{
+ $this->options->returnResource = true;
+
+ $this->setOutputInterface();
+
+ $this::assertIsResource($this->outputInterface->dump());
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Output/QRImagickTest.php b/vendor/chillerlan/php-qrcode/tests/Output/QRImagickTest.php
new file mode 100644
index 000000000..c927cc64e
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Output/QRImagickTest.php
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Class QRImagickTest
+ *
+ * @filesource QRImagickTest.php
+ * @created 04.07.2018
+ * @package chillerlan\QRCodeTest\Output
+ * @author smiley <[email protected]>
+ * @copyright 2018 smiley
+ * @license MIT
+ *
+ * @noinspection PhpComposerExtensionStubsInspection
+ */
+
+namespace chillerlan\QRCodeTest\Output;
+
+use Imagick;
+use chillerlan\QRCode\{QRCode, Output\QRImagick};
+
+class QRImagickTest extends QROutputTestAbstract{
+
+ protected $FQCN = QRImagick::class;
+
+ public function setUp():void{
+
+ if(!extension_loaded('imagick')){
+ $this->markTestSkipped('ext-imagick not loaded');
+ return;
+ }
+
+ parent::setUp();
+ }
+
+ public function testImageOutput(){
+ $type = QRCode::OUTPUT_IMAGICK;
+
+ $this->options->outputType = $type;
+ $this->setOutputInterface();
+ $this->outputInterface->dump($this::cachefile.$type);
+ $img = $this->outputInterface->dump();
+
+ $this->assertSame($img, file_get_contents($this::cachefile.$type));
+ }
+
+ public function testSetModuleValues(){
+
+ $this->options->moduleValues = [
+ // data
+ 1024 => '#4A6000',
+ 4 => '#ECF9BE',
+ ];
+
+ $this->setOutputInterface()->dump();
+
+ $this->assertTrue(true); // tricking the code coverage
+ }
+
+ public function testOutputGetResource():void{
+ $this->options->returnResource = true;
+
+ $this->setOutputInterface();
+
+ $this::assertInstanceOf(Imagick::class, $this->outputInterface->dump());
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Output/QRMarkupTest.php b/vendor/chillerlan/php-qrcode/tests/Output/QRMarkupTest.php
new file mode 100644
index 000000000..24fdc3ce6
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Output/QRMarkupTest.php
@@ -0,0 +1,79 @@
+<?php
+/**
+ * Class QRMarkupTest
+ *
+ * @filesource QRMarkupTest.php
+ * @created 24.12.2017
+ * @package chillerlan\QRCodeTest\Output
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Output;
+
+use chillerlan\QRCode\{QRCode, Output\QRMarkup};
+
+class QRMarkupTest extends QROutputTestAbstract{
+
+ protected $FQCN = QRMarkup::class;
+
+ public function types(){
+ return [
+ 'html' => [QRCode::OUTPUT_MARKUP_HTML],
+ 'svg' => [QRCode::OUTPUT_MARKUP_SVG],
+ ];
+ }
+
+ /**
+ * @dataProvider types
+ * @param $type
+ */
+ public function testMarkupOutputFile($type){
+ $this->options->outputType = $type;
+ $this->options->cachefile = $this::cachefile.$type;
+ $this->setOutputInterface();
+ $data = $this->outputInterface->dump();
+
+ $this->assertSame($data, file_get_contents($this->options->cachefile));
+ }
+
+ /**
+ * @dataProvider types
+ * @param $type
+ */
+ public function testMarkupOutput($type){
+ $this->options->imageBase64 = false;
+ $this->options->outputType = $type;
+ $this->setOutputInterface();
+
+ $expected = explode($this->options->eol, file_get_contents($this::cachefile.$type));
+ // cut off the doctype & head
+ array_shift($expected);
+
+ if($type === QRCode::OUTPUT_MARKUP_HTML){
+ // cut off the </body> tag
+ array_pop($expected);
+ }
+
+ $expected = implode($this->options->eol, $expected);
+
+ $this->assertSame(trim($expected), trim($this->outputInterface->dump()));
+ }
+
+ public function testSetModuleValues(){
+
+ $this->options->imageBase64 = false;
+ $this->options->moduleValues = [
+ // data
+ 1024 => '#4A6000',
+ 4 => '#ECF9BE',
+ ];
+
+ $this->setOutputInterface();
+ $data = $this->outputInterface->dump();
+ $this->assertStringContainsString('#4A6000', $data);
+ $this->assertStringContainsString('#ECF9BE', $data);
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php b/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php
new file mode 100644
index 000000000..6cd95d080
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Class QROutputTestAbstract
+ *
+ * @filesource QROutputTestAbstract.php
+ * @created 24.12.2017
+ * @package chillerlan\QRCodeTest\Output
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Output;
+
+use chillerlan\QRCode\QROptions;
+use chillerlan\QRCode\Data\Byte;
+use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
+use chillerlan\QRCodeTest\QRTestAbstract;
+
+use function dirname, file_exists, mkdir;
+
+abstract class QROutputTestAbstract extends QRTestAbstract{
+
+ const cachefile = __DIR__.'/../../.build/output_test/test.';
+
+ /**
+ * @var \chillerlan\QRCode\Output\QROutputInterface
+ */
+ protected $outputInterface;
+
+ /**
+ * @var \chillerlan\QRCode\QROptions
+ */
+ protected $options;
+
+ /**
+ * @var \chillerlan\QRCode\Data\QRMatrix
+ */
+ protected $matrix;
+
+ protected function setUp():void{
+ parent::setUp();
+
+ $buildDir = dirname($this::cachefile);
+ if(!file_exists($buildDir)){
+ mkdir($buildDir, 0777, true);
+ }
+
+ $this->options = new QROptions;
+ $this->setOutputInterface();
+ }
+
+ protected function setOutputInterface(){
+ $this->outputInterface = $this->reflection->newInstanceArgs([$this->options, (new Byte($this->options, 'testdata'))->initMatrix(0)]);
+ return $this->outputInterface;
+ }
+
+ public function testInstance(){
+ $this->assertInstanceOf(QROutputInterface::class, $this->outputInterface);
+ }
+
+ public function testSaveException(){
+ $this->expectException(QRCodeOutputException::class);
+ $this->expectExceptionMessage('Could not write data to cache file: /foo');
+
+ $this->options->cachefile = '/foo';
+ $this->setOutputInterface();
+ $this->outputInterface->dump();
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Output/QRStringTest.php b/vendor/chillerlan/php-qrcode/tests/Output/QRStringTest.php
new file mode 100644
index 000000000..5dbd34010
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Output/QRStringTest.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Class QRStringTest
+ *
+ * @filesource QRStringTest.php
+ * @created 24.12.2017
+ * @package chillerlan\QRCodeTest\Output
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Output;
+
+use chillerlan\QRCode\{QRCode, Output\QRString};
+
+class QRStringTest extends QROutputTestAbstract{
+
+ protected $FQCN = QRString::class;
+
+ public function types(){
+ return [
+ 'json' => [QRCode::OUTPUT_STRING_JSON],
+ 'text' => [QRCode::OUTPUT_STRING_TEXT],
+ ];
+ }
+
+ /**
+ * @dataProvider types
+ * @param $type
+ */
+ public function testStringOutput($type){
+ $this->options->outputType = $type;
+ $this->options->cachefile = $this::cachefile.$type;
+ $this->setOutputInterface();
+ $data = $this->outputInterface->dump();
+
+ $this->assertSame($data, file_get_contents($this->options->cachefile));
+ }
+
+ public function testSetModuleValues(){
+
+ $this->options->moduleValues = [
+ // data
+ 1024 => 'A',
+ 4 => 'B',
+ ];
+
+ $this->setOutputInterface();
+ $data = $this->outputInterface->dump();
+
+ $this->assertStringContainsString('A', $data);
+ $this->assertStringContainsString('B', $data);
+ }
+
+}