2FAuth/tests/Unit/QrcodeTest.php

80 lines
1.9 KiB
PHP
Raw Normal View History

2020-03-02 17:11:17 +01:00
<?php
namespace Tests\Unit;
2020-11-05 22:54:49 +01:00
use App\User;
2020-03-02 17:11:17 +01:00
use Zxing\QrReader;
2020-11-05 22:54:49 +01:00
use Tests\TestCase;
use App\TwoFAccount;
use App\Classes\Options;
use Tests\Classes\LocalFile;
2020-03-02 17:11:17 +01:00
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class QrcodeTest extends TestCase
{
use WithoutMiddleware;
/**
2020-03-03 17:06:40 +01:00
* test Decode a qrcode without providing a file resource via API
2020-03-02 17:11:17 +01:00
*
* @test
*/
public function testQrcodeDecodeWithMissingImage()
{
$response = $this->json('POST', '/api/qrcode/decode', [
'qrcode' => '',
])
->assertStatus(422);
}
/**
2020-11-05 22:54:49 +01:00
* test decode an invalid QR code uplloaded via API
2020-03-02 17:11:17 +01:00
*
* @test
*/
2020-11-22 12:26:39 +01:00
// public function testDecodeInvalidQrcode()
// {
// $file = LocalFile::fake()->invalidQrcode();
2020-03-03 17:06:40 +01:00
2020-11-22 12:26:39 +01:00
// $response = $this->withHeaders([
// 'Content-Type' => 'multipart/form-data',
// ])
// ->json('POST', '/api/qrcode/decode', [
// 'qrcode' => $file,
// 'inputFormat' => 'fileUpload'
// ]);
2020-03-02 17:11:17 +01:00
2020-11-22 12:26:39 +01:00
// $response->assertStatus(422);
// }
2020-05-07 21:24:14 +02:00
2020-03-03 17:06:40 +01:00
/**
* test Decode a qrcode via API
*
* @test
*/
public function testDecodeValidQrcode()
2020-05-07 21:24:14 +02:00
{
Options::store(array('useBasicQrcodeReader' => true));
2020-03-03 17:06:40 +01:00
$file = LocalFile::fake()->validQrcode();
$response = $this->withHeaders(['Content-Type' => 'multipart/form-data'])
->json('POST', '/api/qrcode/decode', [
2020-11-05 22:54:49 +01:00
'qrcode' => $file,
'inputFormat' => 'fileUpload'
2020-03-03 17:06:40 +01:00
]);
$response->assertStatus(200)
2020-11-22 12:26:39 +01:00
->assertJsonStructure([
'uri',
2020-03-03 17:06:40 +01:00
]);
2020-03-02 17:11:17 +01:00
}
}