| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace Tools\Test\TestCase\View\Helper;
- use Cake\View\View;
- use Shim\TestSuite\TestCase;
- use Tools\View\Helper\QrCodeHelper;
- /**
- * QrCodeHelper Test Case
- */
- class QrCodeHelperTest extends TestCase {
- /**
- * @var string
- */
- public const QR_TEST_STRING = 'Some Text to Translate';
- /**
- * @var string
- */
- public const QR_TEST_STRING_UTF = 'Some äöü Test String with $ and @ etc';
- /**
- * @var \Tools\View\Helper\QrCodeHelper
- */
- protected $QrCode;
- /**
- * @var string
- */
- protected $testEmail;
- /**
- * SetUp method
- *
- * @return void
- */
- public function setUp(): void {
- parent::setUp();
- $this->loadRoutes();
- $this->testEmail = 'foo@bar.local'; // For testing normal behavior
- $this->QrCode = new QrCodeHelper(new View(null));
- }
- /**
- * TearDown method
- *
- * @return void
- */
- public function tearDown(): void {
- parent::tearDown();
- unset($this->QrCode);
- }
- /**
- * @return void
- */
- public function testImage() {
- $is = $this->QrCode->image('Foo Bar');
- $expected = '<img src="http://chart.apis.google.com/chart?chl=Foo%20Bar&cht=qr&choe=UTF-8&chs=74x74&chld=" alt="">';
- $this->assertSame($expected, $is);
- }
- /**
- * @return void
- */
- public function testFormatText() {
- $is = $this->QrCode->formatText(['controller' => 'Foo', 'action' => 'bar'], 'url');
- $this->assertSame('//localhost/foo/bar', $is);
- }
- /**
- * @return void
- */
- public function testFormatCard() {
- $data = [
- 'name' => 'My name',
- 'nickname' => 'Nick',
- 'note' => 'Note',
- 'birthday' => '2015-01-03',
- ];
- $is = $this->QrCode->formatCard($data);
- $expected = 'MECARD:N:My name;NICKNAME:Nick;NOTE:Note;BDAY:20151-;';
- $this->assertSame($expected, $is);
- }
- /**
- * @return void
- */
- public function testSetSize() {
- $is = $this->QrCode->setSize(1000);
- $this->assertFalse($is);
- $is = $this->QrCode->setSize(300);
- $this->assertTrue($is);
- }
- /**
- * @return void
- */
- public function testImagesModified() {
- $this->QrCode->reset();
- $this->QrCode->setLevel('H');
- $is = $this->QrCode->image(static::QR_TEST_STRING);
- $this->assertTrue(!empty($is));
- $this->QrCode->reset();
- $this->QrCode->setLevel('H', 20);
- $is = $this->QrCode->image(static::QR_TEST_STRING_UTF);
- $this->assertTrue(!empty($is));
- $this->QrCode->reset();
- $this->QrCode->setSize(300);
- $this->QrCode->setLevel('L', 1);
- $is = $this->QrCode->image(static::QR_TEST_STRING);
- $this->assertTrue(!empty($is));
- $this->QrCode->reset();
- $this->QrCode->setSize(300);
- $this->QrCode->setLevel('H', 1);
- $is = $this->QrCode->image(static::QR_TEST_STRING);
- $this->assertTrue(!empty($is));
- }
- /**
- * @return void
- */
- public function testSpecialImages() {
- $this->QrCode->reset();
- $this->QrCode->setSize(300);
- $this->QrCode->setLevel('H');
- //echo 'CARD'.BR;
- $string = $this->QrCode->formatCard([
- 'name' => 'Maier,Susanne',
- 'tel' => ['0111222123', '012224344'],
- 'nickname' => 'sssnick',
- 'birthday' => '1999-01-03',
- 'address' => 'Bluetenweg 11, 85375, Neufahrn, Deutschland',
- 'email' => 'test@test.de',
- 'note' => 'someNote;someOtherNote :)',
- 'url' => 'http://www.some_url.de',
- ]);
- $is = $this->QrCode->image($string);
- $this->assertTrue(!empty($is));
- }
- /**
- * @return void
- */
- public function testBitcoin() {
- $this->QrCode->reset();
- $this->QrCode->setSize(100);
- $this->QrCode->setLevel('H');
- $string = $this->QrCode->format('bitcoin', '18pnDgDYFMAKsHTA3ZqyAi6t8q9ztaWWXt');
- $is = $this->QrCode->image($string);
- $this->assertTrue(!empty($is));
- }
- }
|