From 3fd785654372d493c031d9b541ab33a881023a32 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 26 Feb 2021 19:16:17 +0300 Subject: * switch to composer for qrcode and otp dependencies * move most OTP-related stuff into userhelper * remove old phpqrcode and otphp libraries --- .../php-qrcode/tests/Output/QRFpdfTest.php | 83 ++++++++++++++++++++++ .../php-qrcode/tests/Output/QRImageTest.php | 69 ++++++++++++++++++ .../php-qrcode/tests/Output/QRImagickTest.php | 66 +++++++++++++++++ .../php-qrcode/tests/Output/QRMarkupTest.php | 79 ++++++++++++++++++++ .../tests/Output/QROutputTestAbstract.php | 71 ++++++++++++++++++ .../php-qrcode/tests/Output/QRStringTest.php | 56 +++++++++++++++ 6 files changed, 424 insertions(+) create mode 100644 vendor/chillerlan/php-qrcode/tests/Output/QRFpdfTest.php create mode 100644 vendor/chillerlan/php-qrcode/tests/Output/QRImageTest.php create mode 100644 vendor/chillerlan/php-qrcode/tests/Output/QRImagickTest.php create mode 100644 vendor/chillerlan/php-qrcode/tests/Output/QRMarkupTest.php create mode 100644 vendor/chillerlan/php-qrcode/tests/Output/QROutputTestAbstract.php create mode 100644 vendor/chillerlan/php-qrcode/tests/Output/QRStringTest.php (limited to 'vendor/chillerlan/php-qrcode/tests/Output') 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 @@ + + * @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 @@ + + * @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 @@ + + * @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 @@ + + * @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 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 @@ + + * @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 @@ + + * @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); + } + +} -- cgit v1.2.3