Commit 60bd0eb5 authored by Dainis Abols's avatar Dainis Abols
Browse files

PurchaseTest

parent 805308fa
<?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=purchase`
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 21.02.2022
*/
class PurchaseTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
/**
* Public API URL
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=purchase';
/**
* Purchases test
*
* @test
*/
public function purchaseTest()
{
// Read url
$url = $this->url;
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
$code = !empty($result) ? $result->getStatusCode() : 500;
$this->assertEquals(200, $code, 'Purchase Url read failed');
// Assert json return
$content = @$result->getBody()->getContents();
$this->assertJson($content, 'Purchase Url response is not JSON');
// Check top level structure
$content = json_decode($content, true);
$this->assertTrue(count($content) === 3, 'Purchase structure count does not match');
$structure = function ($c) {
return isset($c['recordsTotal']) && isset($c['recordsFiltered']) && isset($c['data']);
};
$this->assertTrue($structure($content), 'Purchase data structure does not match');
// Check data object
$this->assertNotEmpty($content['data'], 'Purchase has no data received');
// Check data object structure
$this->assertTrue(count($content['data'][0]) === 9, 'Purchase data count 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