laravel-nami-api/tests/TestCase.php

59 lines
2.4 KiB
PHP
Raw Normal View History

2020-06-27 23:45:49 +02:00
<?php
namespace Zoomyboy\LaravelNami\Tests;
2020-06-28 00:25:41 +02:00
use Illuminate\Support\Facades\Config;
2020-06-29 00:30:57 +02:00
use Illuminate\Support\Facades\Http;
2021-06-21 22:37:23 +02:00
use Zoomyboy\LaravelNami\Cookies\Cookie;
use Zoomyboy\LaravelNami\Cookies\FakeCookie;
2022-02-10 23:19:31 +01:00
use Zoomyboy\LaravelNami\Providers\NamiServiceProvider;
use Zoomyboy\LaravelNami\Tests\Stub\Member;
2020-06-28 00:25:41 +02:00
2020-06-27 23:45:49 +02:00
class TestCase extends \Orchestra\Testbench\TestCase
{
2020-06-28 00:25:41 +02:00
public $successJson = '{"servicePrefix":null,"methodCall":null,"response":null,"statusCode":0,"statusMessage":"","apiSessionName":"JSESSIONID","apiSessionToken":"ILBY--L4pZEjSKa39tCemens","minorNumber":2,"majorNumber":1}';
public $bruteJson = '{"servicePrefix":null,"methodCall":null,"response":null,"statusCode":3000,"statusMessage":"Die höchste Anzahl von Login-Versuchen wurde erreicht. Ihr Konto ist für 15 Minuten gesperrt worden. Nach Ablauf dieser Zeitspanne wird ihr Zugang wieder freigegeben.","apiSessionName":"JSESSIONID","apiSessionToken":"tGlSpMMij9ruHfeiUYjO7SD2","minorNumber":0,"majorNumber":0}';
public $wrongCredentialsJson = '{"servicePrefix":null,"methodCall":null,"response":null,"statusCode":3000,"statusMessage":"Benutzer nicht gefunden oder Passwort falsch.","apiSessionName":"JSESSIONID","apiSessionToken":"v7lrjgPBbXInJR57qJzVIJ05","minorNumber":0,"majorNumber":0}';
2021-06-21 22:37:23 +02:00
public function setUp(): void {
parent::setUp();
Cookie::swap(new FakeCookie());
}
2020-06-28 00:25:41 +02:00
protected function getPackageProviders($app)
{
return [ NamiServiceProvider::class ];
}
2021-06-18 23:36:22 +02:00
public function getAnnotations(): array {
return [];
}
2020-06-28 00:25:41 +02:00
protected function setCredentials() {
Config::set('nami.auth.mglnr', '11223');
Config::set('nami.auth.password', 'secret');
Config::set('nami.auth.groupid', '55555');
}
2020-06-29 00:30:57 +02:00
public function login() {
return [
'https://nami.dpsg.de/ica/pages/login.jsp' => Http::response('<html></html>', 200),
'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200)
];
}
2022-02-10 23:19:31 +01:00
public function fakeJson(string $file, array $data = []): string {
ob_start();
include(__DIR__.'/json/'.$file);
return ob_get_clean();
2020-06-29 00:30:57 +02:00
}
2020-06-29 23:12:16 +02:00
public function fakeGenders() {
return [
'https://nami.dpsg.de/ica/rest/baseadmin/geschlecht' => Http::response($this->fakeJson('genders.json'), 200)
];
}
2020-06-27 23:45:49 +02:00
}