summaryrefslogtreecommitdiff
path: root/vendor/chillerlan/php-qrcode/tests/Data
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/chillerlan/php-qrcode/tests/Data')
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Data/AlphaNumTest.php44
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Data/ByteTest.php38
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Data/DatainterfaceTestAbstract.php65
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Data/KanjiTest.php50
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Data/MaskPatternTesterTest.php29
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Data/NumberTest.php44
-rw-r--r--vendor/chillerlan/php-qrcode/tests/Data/QRMatrixTest.php260
7 files changed, 530 insertions, 0 deletions
diff --git a/vendor/chillerlan/php-qrcode/tests/Data/AlphaNumTest.php b/vendor/chillerlan/php-qrcode/tests/Data/AlphaNumTest.php
new file mode 100644
index 000000000..c29b1f639
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Data/AlphaNumTest.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Class AlphaNumTest
+ *
+ * @filesource AlphaNumTest.php
+ * @created 24.11.2017
+ * @package chillerlan\QRCodeTest\Data
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Data;
+
+use chillerlan\QRCode\Data\{AlphaNum, QRCodeDataException};
+
+class AlphaNumTest extends DatainterfaceTestAbstract{
+
+ protected $FQCN = AlphaNum::class;
+ protected $testdata = '0 $%*+-./:';
+ protected $expected = [
+ 32, 80, 36, 212, 252, 15, 175, 251,
+ 176, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 112, 43, 9, 248, 200, 194, 75, 25,
+ 205, 173, 154, 68, 191, 16, 128,
+ 92, 112, 20, 198, 27
+ ];
+
+ public function testGetCharCodeException(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('illegal char: "#" [35]');
+
+ $this->dataInterface->setData('#');
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Data/ByteTest.php b/vendor/chillerlan/php-qrcode/tests/Data/ByteTest.php
new file mode 100644
index 000000000..cbfe1fab2
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Data/ByteTest.php
@@ -0,0 +1,38 @@
+<?php
+/**
+ * Class ByteTest
+ *
+ * @filesource ByteTest.php
+ * @created 24.11.2017
+ * @package chillerlan\QRCodeTest\Data
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Data;
+
+use chillerlan\QRCode\Data\Byte;
+
+class ByteTest extends DatainterfaceTestAbstract{
+
+ protected $FQCN = Byte::class;
+ protected $testdata = '[¯\_(ツ)_/¯]';
+ protected $expected = [
+ 64, 245, 188, 42, 245, 197, 242, 142,
+ 56, 56, 66, 149, 242, 252, 42, 245,
+ 208, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 79, 89, 226, 48, 209, 89, 151, 1,
+ 12, 73, 42, 163, 11, 34, 255, 205,
+ 21, 47, 250, 101
+ ];
+
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Data/DatainterfaceTestAbstract.php b/vendor/chillerlan/php-qrcode/tests/Data/DatainterfaceTestAbstract.php
new file mode 100644
index 000000000..19d74617a
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Data/DatainterfaceTestAbstract.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * Class DatainterfaceTestAbstract
+ *
+ * @filesource DatainterfaceTestAbstract.php
+ * @created 24.11.2017
+ * @package chillerlan\QRCodeTest\Data
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Data;
+
+use chillerlan\QRCode\QROptions;
+use chillerlan\QRCode\Data\{QRCodeDataException, QRDataInterface, QRMatrix};
+use chillerlan\QRCodeTest\QRTestAbstract;
+
+abstract class DatainterfaceTestAbstract extends QRTestAbstract{
+
+ /**
+ * @var \chillerlan\QRCode\Data\QRDataAbstract
+ */
+ protected $dataInterface;
+
+ protected $testdata;
+ protected $expected;
+
+ protected function setUp():void{
+ parent::setUp();
+
+ $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions(['version' => 4])]);
+ }
+
+ public function testInstance(){
+ $this->dataInterface = $this->reflection->newInstanceArgs([new QROptions, $this->testdata]);
+
+ $this->assertInstanceOf(QRDataInterface::class, $this->dataInterface);
+ }
+
+ public function testSetData(){
+ $this->dataInterface->setData($this->testdata);
+
+ $this->assertSame($this->expected, $this->getProperty('matrixdata')->getValue($this->dataInterface));
+ }
+
+ public function testInitMatrix(){
+ $m = $this->dataInterface->setData($this->testdata)->initMatrix(0);
+
+ $this->assertInstanceOf(QRMatrix::class, $m);
+ }
+
+ public function testGetMinimumVersion(){
+ $this->assertSame(1, $this->getMethod('getMinimumVersion')->invoke($this->dataInterface));
+ }
+
+ public function testGetMinimumVersionException(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('data exceeds');
+
+ $this->getProperty('strlen')->setValue($this->dataInterface, 13370);
+ $this->getMethod('getMinimumVersion')->invoke($this->dataInterface);
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Data/KanjiTest.php b/vendor/chillerlan/php-qrcode/tests/Data/KanjiTest.php
new file mode 100644
index 000000000..108b8fed7
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Data/KanjiTest.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Class KanjiTest
+ *
+ * @filesource KanjiTest.php
+ * @created 24.11.2017
+ * @package chillerlan\QRCodeTest\Data
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Data;
+
+use chillerlan\QRCode\Data\{Kanji, QRCodeDataException};
+
+class KanjiTest extends DatainterfaceTestAbstract{
+
+ protected $FQCN = Kanji::class;
+ protected $testdata = '茗荷茗荷茗荷茗荷茗荷';
+ protected $expected = [
+ 128, 173, 85, 26, 95, 85, 70, 151,
+ 213, 81, 165, 245, 84, 105, 125, 85,
+ 26, 92, 0, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 195, 11, 221, 91, 141, 220, 163, 46,
+ 165, 37, 163, 176, 79, 0, 64, 68,
+ 96, 113, 54, 191
+ ];
+
+ public function testIllegalCharException1(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('illegal char at 1 [16191]');
+
+ $this->dataInterface->setData('ÃÃ');
+ }
+
+ public function testIllegalCharException2(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('illegal char at 1');
+
+ $this->dataInterface->setData('Ã');
+ }
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Data/MaskPatternTesterTest.php b/vendor/chillerlan/php-qrcode/tests/Data/MaskPatternTesterTest.php
new file mode 100644
index 000000000..ae4af9f29
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Data/MaskPatternTesterTest.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Class MaskPatternTesterTest
+ *
+ * @filesource MaskPatternTesterTest.php
+ * @created 24.11.2017
+ * @package chillerlan\QRCodeTest\Data
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Data;
+
+use chillerlan\QRCode\{QROptions, Data\Byte, Data\MaskPatternTester};
+use chillerlan\QRCodeTest\QRTestAbstract;
+
+class MaskPatternTesterTest extends QRTestAbstract{
+
+ protected $FQCN = MaskPatternTester::class;
+
+ // coverage
+ public function testMaskpattern(){
+ $matrix = (new Byte(new QROptions(['version' => 10]), 'test'))->initMatrix(3, true);
+
+ $this->assertSame(4243, (new MaskPatternTester($matrix))->testPattern());
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Data/NumberTest.php b/vendor/chillerlan/php-qrcode/tests/Data/NumberTest.php
new file mode 100644
index 000000000..983346a34
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Data/NumberTest.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Class NumberTest
+ *
+ * @filesource NumberTest.php
+ * @created 24.11.2017
+ * @package chillerlan\QRCodeTest\Data
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Data;
+
+use chillerlan\QRCode\Data\{Number, QRCodeDataException};
+
+class NumberTest extends DatainterfaceTestAbstract{
+
+ protected $FQCN = Number::class;
+ protected $testdata = '0123456789';
+ protected $expected = [
+ 16, 40, 12, 86, 106, 105, 0, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 17, 236, 17, 236, 17, 236, 17, 236,
+ 201, 141, 102, 116, 238, 162, 239, 230,
+ 222, 37, 79, 192, 42, 109, 188, 72,
+ 89, 63, 168, 151
+ ];
+
+ public function testGetCharCodeException(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('illegal char: "#" [35]');
+
+ $this->dataInterface->setData('#');
+ }
+
+}
diff --git a/vendor/chillerlan/php-qrcode/tests/Data/QRMatrixTest.php b/vendor/chillerlan/php-qrcode/tests/Data/QRMatrixTest.php
new file mode 100644
index 000000000..531c82eb2
--- /dev/null
+++ b/vendor/chillerlan/php-qrcode/tests/Data/QRMatrixTest.php
@@ -0,0 +1,260 @@
+<?php
+/**
+ * Class QRMatrixTest
+ *
+ * @filesource QRMatrixTest.php
+ * @created 17.11.2017
+ * @package chillerlan\QRCodeTest\Data
+ * @author Smiley <[email protected]>
+ * @copyright 2017 Smiley
+ * @license MIT
+ */
+
+namespace chillerlan\QRCodeTest\Data;
+
+use chillerlan\QRCode\QRCode;
+use chillerlan\QRCode\QROptions;
+use chillerlan\QRCode\Data\{QRCodeDataException, QRMatrix};
+use chillerlan\QRCodeTest\QRTestAbstract;
+use ReflectionClass;
+
+class QRMatrixTest extends QRTestAbstract{
+
+ protected $FQCN = QRMatrix::class;
+
+ protected $version = 7;
+
+ /**
+ * @var \chillerlan\QRCode\Data\QRMatrix
+ */
+ protected $matrix;
+
+ protected function setUp():void{
+ parent::setUp();
+
+ $this->matrix = $this->reflection->newInstanceArgs([$this->version, QRCode::ECC_L]);
+ }
+
+ public function testInvalidVersionException(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('invalid QR Code version');
+
+ $this->reflection->newInstanceArgs([42, 0]);
+ }
+
+ public function testInvalidEccException(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('invalid ecc level');
+
+ $this->reflection->newInstanceArgs([1, 42]);
+ }
+
+ public function testInstance(){
+ $this->assertInstanceOf($this->FQCN, $this->matrix);
+ }
+
+ public function testSize(){
+ $this->assertCount($this->matrix->size(), $this->matrix->matrix());
+ }
+
+ public function testVersion(){
+ $this->assertSame($this->version, $this->matrix->version());
+ }
+
+ public function testECC(){
+ $this->assertSame(QRCode::ECC_L, $this->matrix->eccLevel());
+ }
+
+ public function testMaskPattern(){
+ $this->assertSame(-1, $this->matrix->maskPattern());
+ }
+
+ public function testGetSetCheck(){
+ $this->matrix->set(10, 10, true, QRMatrix::M_TEST);
+ $this->assertSame(65280, $this->matrix->get(10, 10));
+ $this->assertTrue($this->matrix->check(10, 10));
+
+ $this->matrix->set(20, 20, false, QRMatrix::M_TEST);
+ $this->assertSame(255, $this->matrix->get(20, 20));
+ $this->assertFalse($this->matrix->check(20, 20));
+ }
+
+ public function testSetDarkModule(){
+ $this->matrix->setDarkModule();
+
+ $this->assertSame(QRMatrix::M_DARKMODULE << 8, $this->matrix->get(8, $this->matrix->size() - 8));
+ }
+
+ public function testSetFinderPattern(){
+ $this->matrix->setFinderPattern();
+
+ $this->assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get(0, 0));
+ $this->assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get(0, $this->matrix->size() - 1));
+ $this->assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get($this->matrix->size() - 1, 0));
+ }
+
+ public function testSetSeparators(){
+ $this->matrix->setSeparators();
+
+ $this->assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get(7, 0));
+ $this->assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get(0, 7));
+ $this->assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get(0, $this->matrix->size() - 8));
+ $this->assertSame(QRMatrix::M_SEPARATOR, $this->matrix->get($this->matrix->size() - 8, 0));
+ }
+
+ public function testSetAlignmentPattern(){
+ $this->matrix
+ ->setFinderPattern()
+ ->setAlignmentPattern()
+ ;
+
+ $alignmentPattern = (new ReflectionClass(QRMatrix::class))->getConstant('alignmentPattern')[$this->version];
+
+ foreach($alignmentPattern as $py){
+ foreach($alignmentPattern as $px){
+
+ if($this->matrix->get($px, $py) === QRMatrix::M_FINDER << 8){
+ $this->assertSame(QRMatrix::M_FINDER << 8, $this->matrix->get($px, $py), 'skipped finder pattern');
+ continue;
+ }
+
+ $this->assertSame(QRMatrix::M_ALIGNMENT << 8, $this->matrix->get($px, $py));
+ }
+ }
+
+ }
+
+ public function testSetTimingPattern(){
+ $this->matrix
+ ->setAlignmentPattern()
+ ->setTimingPattern()
+ ;
+
+ $size = $this->matrix->size();
+
+ for($i = 7; $i < $size - 7; $i++){
+ if($i % 2 === 0){
+ $p1 = $this->matrix->get(6, $i);
+
+ if($p1 === QRMatrix::M_ALIGNMENT << 8){
+ $this->assertSame(QRMatrix::M_ALIGNMENT << 8, $p1, 'skipped alignment pattern');
+ continue;
+ }
+
+ $this->assertSame(QRMatrix::M_TIMING << 8, $p1);
+ $this->assertSame(QRMatrix::M_TIMING << 8, $this->matrix->get($i, 6));
+ }
+ }
+ }
+
+ public function testSetVersionNumber(){
+ $this->matrix->setVersionNumber(true);
+
+ $this->assertSame(QRMatrix::M_VERSION, $this->matrix->get($this->matrix->size() - 9, 0));
+ $this->assertSame(QRMatrix::M_VERSION, $this->matrix->get($this->matrix->size() - 11, 5));
+ $this->assertSame(QRMatrix::M_VERSION, $this->matrix->get(0, $this->matrix->size() - 9));
+ $this->assertSame(QRMatrix::M_VERSION, $this->matrix->get(5, $this->matrix->size() - 11));
+ }
+
+ public function testSetFormatInfo(){
+ $this->matrix->setFormatInfo(0, true);
+
+ $this->assertSame(QRMatrix::M_FORMAT, $this->matrix->get(8, 0));
+ $this->assertSame(QRMatrix::M_FORMAT, $this->matrix->get(0, 8));
+ $this->assertSame(QRMatrix::M_FORMAT, $this->matrix->get($this->matrix->size() - 1, 8));
+ $this->assertSame(QRMatrix::M_FORMAT, $this->matrix->get($this->matrix->size() - 8, 8));
+ }
+
+ public function testSetQuietZone(){
+ $size = $this->matrix->size();
+ $q = 5;
+
+ $this->matrix->set(0, 0, true, QRMatrix::M_TEST);
+ $this->matrix->set($size - 1, $size - 1, true, QRMatrix::M_TEST);
+
+ $this->matrix->setQuietZone($q);
+
+ $this->assertCount($size + 2 * $q, $this->matrix->matrix());
+ $this->assertCount($size + 2 * $q, $this->matrix->matrix()[$size - 1]);
+
+ $size = $this->matrix->size();
+ $this->assertSame(QRMatrix::M_QUIETZONE, $this->matrix->get(0, 0));
+ $this->assertSame(QRMatrix::M_QUIETZONE, $this->matrix->get($size - 1, $size - 1));
+
+ $this->assertSame(QRMatrix::M_TEST << 8, $this->matrix->get($q, $q));
+ $this->assertSame(QRMatrix::M_TEST << 8, $this->matrix->get($size - 1 - $q, $size - 1 - $q));
+ }
+
+ public function testSetQuietZoneException(){
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('use only after writing data');
+
+ $this->matrix->setQuietZone();
+ }
+
+ public function testSetLogoSpaceOrientation():void{
+ $o = new QROptions;
+ $o->version = 10;
+ $o->eccLevel = QRCode::ECC_H;
+ $o->addQuietzone = false;
+
+ $matrix = (new QRCode($o))->getMatrix('testdata');
+ // also testing size adjustment to uneven numbers
+ $matrix->setLogoSpace(20, 14);
+
+ // NW corner
+ $this::assertNotSame(QRMatrix::M_LOGO, $matrix->get(17, 20));
+ $this::assertSame(QRMatrix::M_LOGO, $matrix->get(18, 21));
+
+ // SE corner
+ $this::assertSame(QRMatrix::M_LOGO, $matrix->get(38, 35));
+ $this::assertNotSame(QRMatrix::M_LOGO, $matrix->get(39, 36));
+ }
+
+ public function testSetLogoSpacePosition():void{
+ $o = new QROptions;
+ $o->version = 10;
+ $o->eccLevel = QRCode::ECC_H;
+ $o->addQuietzone = true;
+ $o->quietzoneSize = 10;
+
+ $m = (new QRCode($o))->getMatrix('testdata');
+
+ // logo space should not overwrite quiet zone & function patterns
+ $m->setLogoSpace(21, 21, -10, -10);
+ $this::assertSame(QRMatrix::M_QUIETZONE, $m->get(9, 9));
+ $this::assertSame(QRMatrix::M_FINDER << 8, $m->get(10, 10));
+ $this::assertSame(QRMatrix::M_FINDER << 8, $m->get(16, 16));
+ $this::assertSame(QRMatrix::M_SEPARATOR, $m->get(17, 17));
+ $this::assertSame(QRMatrix::M_FORMAT << 8, $m->get(18, 18));
+ $this::assertSame(QRMatrix::M_LOGO, $m->get(19, 19));
+ $this::assertSame(QRMatrix::M_LOGO, $m->get(20, 20));
+ $this::assertNotSame(QRMatrix::M_LOGO, $m->get(21, 21));
+
+ // i just realized that setLogoSpace() could be called multiple times
+ // on the same instance and i'm not going to do anything about it :P
+ $m->setLogoSpace(21, 21, 45, 45);
+ $this::assertNotSame(QRMatrix::M_LOGO, $m->get(54, 54));
+ $this::assertSame(QRMatrix::M_LOGO, $m->get(55, 55));
+ $this::assertSame(QRMatrix::M_QUIETZONE, $m->get(67, 67));
+ }
+
+ public function testSetLogoSpaceInvalidEccException():void{
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('ECC level "H" required to add logo space');
+
+ (new QRCode)->getMatrix('testdata')->setLogoSpace(50, 50);
+ }
+
+ public function testSetLogoSpaceMaxSizeException():void{
+ $this->expectException(QRCodeDataException::class);
+ $this->expectExceptionMessage('logo space exceeds the maximum error correction capacity');
+
+ $o = new QROptions;
+ $o->version = 5;
+ $o->eccLevel = QRCode::ECC_H;
+
+ (new QRCode($o))->getMatrix('testdata')->setLogoSpace(50, 50);
+ }
+
+}