mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-17 18:53:34 +00:00
100 lines
2.5 KiB
PHP
Executable File
100 lines
2.5 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Class QRCodeTest
|
|
*
|
|
* @created 17.11.2017
|
|
* @author Smiley <smiley@chillerlan.net>
|
|
* @copyright 2017 Smiley
|
|
* @license MIT
|
|
*/
|
|
|
|
namespace chillerlan\QRCodeTest;
|
|
|
|
use chillerlan\QRCode\{QROptions, QRCode};
|
|
use chillerlan\QRCode\Data\QRCodeDataException;
|
|
use chillerlan\QRCode\Output\QRCodeOutputException;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Tests basic functions of the QRCode class
|
|
*/
|
|
class QRCodeTest extends TestCase{
|
|
|
|
/** @internal */
|
|
protected QRCode $qrcode;
|
|
/** @internal */
|
|
protected QROptions $options;
|
|
|
|
/**
|
|
* invoke test instances
|
|
*
|
|
* @internal
|
|
*/
|
|
protected function setUp():void{
|
|
$this->qrcode = new QRCode;
|
|
$this->options = new QROptions;
|
|
}
|
|
|
|
/**
|
|
* isNumber() should pass on any number and fail on anything else
|
|
*/
|
|
public function testIsNumber():void{
|
|
$this::assertTrue($this->qrcode->isNumber('0123456789'));
|
|
|
|
$this::assertFalse($this->qrcode->isNumber('ABC123'));
|
|
}
|
|
|
|
/**
|
|
* isAlphaNum() should pass on the 45 defined characters and fail on anything else (e.g. lowercase)
|
|
*/
|
|
public function testIsAlphaNum():void{
|
|
$this::assertTrue($this->qrcode->isAlphaNum('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:'));
|
|
|
|
$this::assertFalse($this->qrcode->isAlphaNum('abc'));
|
|
}
|
|
|
|
/**
|
|
* isKanji() should pass on Kanji/SJIS characters and fail on everything else
|
|
*/
|
|
public function testIsKanji():void{
|
|
$this::assertTrue($this->qrcode->isKanji('茗荷'));
|
|
|
|
$this::assertFalse($this->qrcode->isKanji('Ã'));
|
|
$this::assertFalse($this->qrcode->isKanji('ABC'));
|
|
$this::assertFalse($this->qrcode->isKanji('123'));
|
|
}
|
|
|
|
/**
|
|
* isByte() passses any binary string and only fails on empty strings
|
|
*/
|
|
public function testIsByte():void{
|
|
$this::assertTrue($this->qrcode->isByte("\x01\x02\x03"));
|
|
$this::assertTrue($this->qrcode->isByte(' ')); // not empty!
|
|
|
|
$this::assertFalse($this->qrcode->isByte(''));
|
|
}
|
|
|
|
/**
|
|
* tests if an exception is thrown when an invalid (built-in) output type is specified
|
|
*/
|
|
public function testInitDataInterfaceException():void{
|
|
$this->expectException(QRCodeOutputException::class);
|
|
$this->expectExceptionMessage('invalid output type');
|
|
|
|
$this->options->outputType = 'foo';
|
|
|
|
(new QRCode($this->options))->render('test');
|
|
}
|
|
|
|
/**
|
|
* tests if an exception is thrown when trying to call getMatrix() without data (empty string, no data set)
|
|
*/
|
|
public function testGetMatrixException():void{
|
|
$this->expectException(QRCodeDataException::class);
|
|
$this->expectExceptionMessage('QRCode::getMatrix() No data given.');
|
|
|
|
$this->qrcode->getMatrix();
|
|
}
|
|
|
|
}
|