Commit 98aa495d authored by Dainis Abols's avatar Dainis Abols
Browse files

QRCodeTest

parent aa7ed7fd
<?php
declare(strict_types=1);
namespace Lu\LuApi\Functional;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Exception\GuzzleException;
use Lu\LuApi\Helpers\DataHelper;
use Vendor\MyExtension\Service\AbstractSomethingService;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* Test for route `?r=qrcode`
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 22.02.2022
*/
class QRCodeTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
/**
* Public API URL
*
* @var string
*/
// private string $url = 'https://www.lu.lv/api/?r=qrcode/generate/'; // @TODO UNCOMMENT THIS
private string $url = 'https://typo3-dev2.lu.lv/api/?r=qrcode/generate/';
/**
* QR Code test
*
* @test
*/
public function qrcodeTest()
{
// Read url
$url = $this->url.urlencode('https://www.lu.lv/');
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
$code = !empty($result) ? $result->getStatusCode() : 500;
$this->assertEquals(200, $code, 'QRCode Url read failed ['.$url.']');
// Assert response is image
$this->assertTrue($result->getHeader('Content-Type')[0] === 'image/png', 'QRCode Response is not an image');
// Assert image size 400x400
$result = @getimagesizefromstring($result->getBody()->getContents());
$size = function ($x, $y) use ($result) {
return $result[0] === $x && $result[1] === $y;
};
$this->assertTrue($size(400, 400), 'QRCode Response image size does not match');
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment