Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Open
LU API
Commits
047a2655
Commit
047a2655
authored
Feb 22, 2022
by
Dainis Abols
Browse files
NamesdayTest
parent
96760f0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Tests/Functional/NamedaysTest.php
0 → 100644
View file @
047a2655
<?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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment