Commit 047a2655 authored by Dainis Abols's avatar Dainis Abols
Browse files

NamesdayTest

parent 96760f0e
<?php
declare(strict_types=1);
namespace Lu\LuApi\Functional;
use Lu\LuApi\Helpers\DataHelper;
use Vendor\MyExtension\Service\AbstractSomethingService;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
/**
* Test for route `?r=namedays`
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 22.02.2022
*/
class NamedaysTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
/**
* Public API URL
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=namedays/search/';
/**
* Namedays test
*
* @test
*/
public function namedaysTest()
{
// Read url
$url = $this->url.'aaa';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
$code = !empty($result) ? $result->getStatusCode() : 500;
$this->assertEquals(200, $code, 'Namedays Url read failed ['.$url.']');
// Assert json return
$content = @$result->getBody()->getContents();
$this->assertJson($content, 'Namedays Url response is not JSON');
// Assert empty result
$content = json_decode($content, true);
$this->assertEmpty($content, 'Namesdays data received unsuccessfully');
// Check results by name
$url = $this->url.'jānis';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
$this->assertEquals(200, $result->getStatusCode(), 'Namedays Url read failed ['.$url.']');
// Assert json return
$content = @$result->getBody()->getContents();
$this->assertJson($content, 'Namedays Url response is not JSON');
// Assert empty result
$content = json_decode($content, true);
$this->assertNotEmpty($content, 'Namedays has no data received');
// Assert structure received
$structure = function ($c) {
return isset($c['date']) && isset($c['names']) && is_array($c['names']);
};
$this->assertTrue($structure($content[0]), 'Namedays data structure does not match');
// Assert exact result by date
$url = $this->url.'23.06.2000';
$result = (new DataHelper())->fetchUrl($url);
$content = @$result->getBody()->getContents();
$content = json_decode($content, true);
$this->assertTrue(in_array('Līga', $content[0]['names']), 'Namesday data returned wrong results');
}
}
\ 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