Commit 63cdba43 authored by Dainis Abols's avatar Dainis Abols
Browse files

Fixed hardcoded API urls

v3.0.7
parent 81b774a2
......@@ -19,21 +19,23 @@ class CourseContinueTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=course-continue/search/mate';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Course Continue test
*
* @test
*/
public function courseContinueTest()
public function testSearch()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=course-continue/search/mate';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,21 +19,23 @@ class CourseTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=course/search/mate';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Course test
*
* @test
*/
public function courseTest()
public function testSearch()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=course/search/mate';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -18,13 +18,6 @@ class DownloadTest extends UnitTestCase
{
protected $resetSingletonInstances = true;
/**
* Public API URL
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=download/purchase/';
/**
* Test file ID
*
......@@ -33,14 +26,23 @@ class DownloadTest extends UnitTestCase
private int $fileId = 15882;
/**
* Download test
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* @test
*/
public function downloadTest()
public function testSearch()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url.'0';
$url = $testUrl.'?r=download/purchase/0';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......@@ -48,7 +50,7 @@ class DownloadTest extends UnitTestCase
$this->assertEquals(200, $code, 'Download Url read failed ['.$url.']');
// Check empty results
$url = $this->url.$this->fileId;
$url = $testUrl.'?r=download/purchase/'.$this->fileId;
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,21 +19,23 @@ class EmailTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=email/search';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Email test
*
* @test
*/
public function emailTest()
public function testSearch()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=email/search';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,11 +19,11 @@ class LessonsTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Lesson item structure
......@@ -44,8 +44,12 @@ class LessonsTest extends UnitTestCase
*/
public function lessonsJSONTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url.'dabas-maja/search';
$url = $testUrl.'?r=dabas-maja/search';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......@@ -80,9 +84,14 @@ class LessonsTest extends UnitTestCase
*/
public function lessonsSingleRoomJSONTest()
{
// Get room url
$url = $this->url.'dabas-maja/search';
$result = (new DataHelper())->fetchUrl($url);
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $testUrl.'?r=dabas-maja/search';
$result = (new DataHelper())->fetchUrl($url);
$content = @$result->getBody()->getContents();
$content = json_decode($content, true);
$room_url = $content['items'][0]['room_url'];
......@@ -121,8 +130,12 @@ class LessonsTest extends UnitTestCase
*/
public function lessonsHTMLTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url.'zinatnu-maja/search&visual=1';
$url = $testUrl.'?r=zinatnu-maja/search&visual=1';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......@@ -142,9 +155,14 @@ class LessonsTest extends UnitTestCase
*/
public function lessonsSingleRoomHTMLTest()
{
// Get room url
$url = $this->url.'dabas-maja/search';
$result = (new DataHelper())->fetchUrl($url);
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $testUrl.'?r=dabas-maja/search';
$result = (new DataHelper())->fetchUrl($url);
$content = @$result->getBody()->getContents();
$content = json_decode($content, true);
$room_url = $content['items'][0]['room_url'];
......
......@@ -19,11 +19,11 @@ class NabaLiveTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=naba-live/search';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* NABA Live test
......@@ -32,8 +32,12 @@ class NabaLiveTest extends UnitTestCase
*/
public function nabaLiveTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=naba-live/search';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,11 +19,11 @@ class NabaStoreTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=naba-store';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* NABA Store test
......@@ -32,8 +32,12 @@ class NabaStoreTest extends UnitTestCase
*/
public function nabaStoreTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=naba-store';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,11 +19,11 @@ class NamedaysTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=namedays/search/';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Namedays test
......@@ -32,8 +32,12 @@ class NamedaysTest extends UnitTestCase
*/
public function namedaysTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url.'aaa';
$url = $testUrl.'?r=namedays/search/aaa';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......@@ -49,7 +53,7 @@ class NamedaysTest extends UnitTestCase
$this->assertEmpty($content, 'Namesdays data received unsuccessfully');
// Check results by name
$url = $this->url.'jānis';
$url = $testUrl.'?r=namedays/search/jānis';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......@@ -70,8 +74,8 @@ class NamedaysTest extends UnitTestCase
$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);
$url = $testUrl.'?r=namedays/search/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');
......
......@@ -19,11 +19,11 @@ class ProgramContinueTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=program-continue/search/mate';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Program Continue test
......@@ -32,8 +32,12 @@ class ProgramContinueTest extends UnitTestCase
*/
public function programContinueTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=program-continue/search/mate';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,11 +19,11 @@ class ProgramTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=program/search/mate';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Program test
......@@ -32,8 +32,12 @@ class ProgramTest extends UnitTestCase
*/
public function programTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=program/search/mate';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,11 +19,11 @@ class PurchaseTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/?r=purchase';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Purchases test
......@@ -32,8 +32,12 @@ class PurchaseTest extends UnitTestCase
*/
public function purchaseTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url;
$url = $testUrl.'?r=purchase';
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......
......@@ -19,12 +19,11 @@ class QRCodeTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @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/';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* QR Code test
......@@ -33,8 +32,12 @@ class QRCodeTest extends UnitTestCase
*/
public function qrcodeTest()
{
// Read settings
$conf = @include $this->LocalConfiguration;
$testUrl = @$conf['EXTENSIONS']['lu_api']['testAPIUrl'];
// Read url
$url = $this->url.urlencode('https://www.lu.lv/');
$url = $testUrl.'?r=qrcode/generate/'.urlencode($testUrl);
$result = (new DataHelper())->fetchUrl($url);
// Assert url read
......@@ -42,7 +45,7 @@ class QRCodeTest extends UnitTestCase
$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');
$this->assertTrue($result->getHeader('Content-Type')[0] === 'image/png', 'QRCode Response is not an image ['.$url.']');
// Assert image size 400x400
$result = @getimagesizefromstring($result->getBody()->getContents());
......
......@@ -19,11 +19,11 @@ class RoutesTest extends UnitTestCase
protected $resetSingletonInstances = true;
/**
* Public API URL
* LocalConfiguration file name and relative location
*
* @var string
*/
private string $url = 'https://www.lu.lv/api/';
private string $LocalConfiguration = 'public/typo3conf/LocalConfiguration.php';
/**
* Main API Test
......@@ -32,7 +32,7 @@ class RoutesTest extends UnitTestCase
*/
public function apiTest()
{
$url = $this->url;
$url = $this->getUrl();
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -44,7 +44,7 @@ class RoutesTest extends UnitTestCase
*/
public function downloadTest()
{
$url = $this->url.'?r=download/purchase/0';
$url = $this->getUrl().'?r=download/purchase/0';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -56,8 +56,7 @@ class RoutesTest extends UnitTestCase
*/
public function qrcodeTest()
{
// $url = $this->url.'?r=qrcode/generate/'.urlencode($this->url); // @TODO UNCOMMENT THIS
$url = 'https://typo3-dev2.lu.lv/api/?r=qrcode/generate/'.urlencode($this->url);
$url = $this->getUrl().'?r=qrcode/generate/'.urlencode($this->getUrl());
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -69,7 +68,7 @@ class RoutesTest extends UnitTestCase
*/
public function courseTest()
{
$url = $this->url.'?r=course/search/aaa';
$url = $this->getUrl().'?r=course/search/aaa';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -81,7 +80,7 @@ class RoutesTest extends UnitTestCase
*/
public function courseContinueTest()
{
$url = $this->url.'?r=course-continue/search/aaa';
$url = $this->getUrl().'?r=course-continue/search/aaa';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -93,7 +92,7 @@ class RoutesTest extends UnitTestCase
*/
public function programTest()
{
$url = $this->url.'?r=program/search/aaa';
$url = $this->getUrl().'?r=program/search/aaa';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -105,7 +104,7 @@ class RoutesTest extends UnitTestCase
*/
public function programContinueTest()
{
$url = $this->url.'?r=program-continue/search/aaa';
$url = $this->getUrl().'?r=program-continue/search/aaa';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -117,7 +116,7 @@ class RoutesTest extends UnitTestCase
*/
public function purchaseRouteTest()
{
$url = $this->url.'?r=purchase';
$url = $this->getUrl().'?r=purchase';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -129,7 +128,7 @@ class RoutesTest extends UnitTestCase
*/
public function namedaysTest()
{
$url = $this->url.'?r=namedays/search/';
$url = $this->getUrl().'?r=namedays/search/';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -141,7 +140,7 @@ class RoutesTest extends UnitTestCase
*/
public function nabaLiveTest()
{
$url = $this->url.'?r=naba-live/search/';
$url = $this->getUrl().'?r=naba-live/search/';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -153,7 +152,7 @@ class RoutesTest extends UnitTestCase
*/
public function nabaStoreTest()
{
$url = $this->url.'?r=naba-store';
$url = $this->getUrl().'?r=naba-store';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -165,7 +164,7 @@ class RoutesTest extends UnitTestCase
*/
public function dabasMajaTest()
{
$url = $this->url.'?r=dabas-maja/search/1';
$url = $this->getUrl().'?r=dabas-maja/search/1';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -177,7 +176,7 @@ class RoutesTest extends UnitTestCase
*/
public function zinatnuMajaTest()
{
$url = $this->url.'?r=zinatnu-maja/search/1';
$url = $this->getUrl().'?r=zinatnu-maja/search/1';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
......@@ -189,7 +188,20 @@ class RoutesTest extends UnitTestCase
*/
public function emailTest()
{
$url = $this->url.'?r=email/search';
$url = $this->getUrl().'?r=email/search';
$this->assertEquals(200, (new DataHelper())->fetchUrl($url, true), 'Url read failed ['.$url.']');
}
/**
* Fetch url from settings
*
* @return string
*/
private function getUrl(): string
{
// Read settings
$conf = @include $this->LocalConfiguration;
return $conf['EXTENSIONS']['lu_api']['testAPIUrl'] ?? '';
}
}
{
"name": "luitd/lu-api",
"version": "3.0.6",
"version": "3.0.7",
"description": "REST API Integration for TYPO3",
"type": "typo3-cms-extension",
"keywords": [
......
# General settings
# Settings
###########################
# cat=General/set; type=string; label=Configuration file location
......@@ -53,4 +53,7 @@ solrDatabase.LuisUser =
solrDatabase.LuisPass =
# cat=StorageDIR/set; type=string; label=Purchases file storage directory path
storage.lupurchases = /home/portal/typo3data/storage/purchases/
\ No newline at end of file
storage.lupurchases = /home/portal/typo3data/storage/purchases/
# cat=Testing/set; type=string; label=Public API site
testAPIUrl = https://www.lu.lv/api/