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
96760f0e
Commit
96760f0e
authored
Feb 22, 2022
by
Dainis Abols
Browse files
Naba tests (live and store)
parent
672b1b4d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Tests/Functional/NabaLiveTest.php
0 → 100644
View file @
96760f0e
<?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=naba-live`
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 22.02.2022
*/
class
NabaLiveTest
extends
UnitTestCase
{
protected
$resetSingletonInstances
=
true
;
/**
* Public API URL
*
* @var string
*/
private
string
$url
=
'https://www.lu.lv/api/?r=naba-live/search'
;
/**
* NABA Live test
*
* @test
*/
public
function
nabaLiveTest
()
{
// Read url
$url
=
$this
->
url
;
$result
=
(
new
DataHelper
())
->
fetchUrl
(
$url
);
// Assert url read
$code
=
!
empty
(
$result
)
?
$result
->
getStatusCode
()
:
500
;
$this
->
assertEquals
(
200
,
$code
,
'NABA Live Url read failed'
);
// Assert json return
$content
=
@
$result
->
getBody
()
->
getContents
();
$this
->
assertJson
(
$content
,
'NABA Live Url response is not JSON'
);
// Check top level structure
$content
=
json_decode
(
$content
,
true
);
$this
->
assertTrue
(
count
(
$content
)
===
2
,
'NABA Live structure count does not match'
);
$structure
=
function
(
$c
)
{
return
isset
(
$c
[
'programme'
])
&&
isset
(
$c
[
'songString'
]);
};
$this
->
assertTrue
(
$structure
(
$content
),
'Naba Live structure does not match'
);
}
}
\ No newline at end of file
Tests/Functional/NabaStoreTest.php
0 → 100644
View file @
96760f0e
<?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=naba-store`
*
* @author Dainis Abols <dainis.abols@lu.lv>
* @owner University of Latvia
* @since 22.02.2022
*/
class
NabaStoreTest
extends
UnitTestCase
{
protected
$resetSingletonInstances
=
true
;
/**
* Public API URL
*
* @var string
*/
private
string
$url
=
'https://www.lu.lv/api/?r=naba-store'
;
/**
* NABA Store test
*
* @test
*/
public
function
nabaStoreTest
()
{
// Read url
$url
=
$this
->
url
;
$result
=
(
new
DataHelper
())
->
fetchUrl
(
$url
);
// Assert url read
$code
=
!
empty
(
$result
)
?
$result
->
getStatusCode
()
:
500
;
$this
->
assertEquals
(
200
,
$code
,
'NABA Store Url read failed'
);
// Assert json return
$content
=
@
$result
->
getBody
()
->
getContents
();
$this
->
assertJson
(
$content
,
'NABA Live Store response is not JSON'
);
// Check top level structure
$content
=
json_decode
(
$content
,
true
);
$this
->
assertTrue
(
$content
[
'success'
]
===
true
,
'NABA Store invalid response'
);
}
}
\ 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