2021-02-26 16:16:17 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Class QRStringTest
|
|
|
|
*
|
|
|
|
* @filesource QRStringTest.php
|
|
|
|
* @created 24.12.2017
|
|
|
|
* @package chillerlan\QRCodeTest\Output
|
|
|
|
* @author Smiley <smiley@chillerlan.net>
|
|
|
|
* @copyright 2017 Smiley
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace chillerlan\QRCodeTest\Output;
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
use chillerlan\QRCodeExamples\MyCustomOutput;
|
|
|
|
use chillerlan\QRCode\{QRCode, QROptions};
|
|
|
|
use chillerlan\QRCode\Output\{QROutputInterface, QRString};
|
2021-02-26 16:16:17 +00:00
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
/**
|
|
|
|
* Tests the QRString output module
|
|
|
|
*/
|
2021-02-26 16:16:17 +00:00
|
|
|
class QRStringTest extends QROutputTestAbstract{
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
protected function getOutputInterface(QROptions $options):QROutputInterface{
|
|
|
|
return new QRString($options, $this->matrix);
|
|
|
|
}
|
2021-02-26 16:16:17 +00:00
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
public function types():array{
|
2021-02-26 16:16:17 +00:00
|
|
|
return [
|
|
|
|
'json' => [QRCode::OUTPUT_STRING_JSON],
|
|
|
|
'text' => [QRCode::OUTPUT_STRING_TEXT],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-02 14:01:51 +00:00
|
|
|
* @inheritDoc
|
2021-02-26 16:16:17 +00:00
|
|
|
*/
|
2022-07-02 14:01:51 +00:00
|
|
|
public function testSetModuleValues():void{
|
2021-02-26 16:16:17 +00:00
|
|
|
|
|
|
|
$this->options->moduleValues = [
|
|
|
|
// data
|
|
|
|
1024 => 'A',
|
|
|
|
4 => 'B',
|
|
|
|
];
|
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
$this->outputInterface = $this->getOutputInterface($this->options);
|
|
|
|
$data = $this->outputInterface->dump();
|
|
|
|
|
|
|
|
$this::assertStringContainsString('A', $data);
|
|
|
|
$this::assertStringContainsString('B', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* covers the custom output functionality via an example
|
|
|
|
*/
|
|
|
|
public function testCustomOutput():void{
|
|
|
|
$this->options->version = 5;
|
|
|
|
$this->options->eccLevel = QRCode::ECC_L;
|
|
|
|
$this->options->outputType = QRCode::OUTPUT_CUSTOM;
|
|
|
|
$this->options->outputInterface = MyCustomOutput::class;
|
2021-02-26 16:16:17 +00:00
|
|
|
|
2022-07-02 14:01:51 +00:00
|
|
|
$this::assertSame(
|
|
|
|
file_get_contents(__DIR__.'/samples/custom'),
|
|
|
|
(new QRCode($this->options))->render('test')
|
|
|
|
);
|
2021-02-26 16:16:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|