diff --git a/tests/TestCase.php b/tests/TestCase.php index 073779b..32ae056 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,9 +2,28 @@ namespace Zoomyboy\LaravelNami\Tests; +use Illuminate\Support\Facades\Config; +use Zoomyboy\LaravelNami\NamiServiceProvider; + class TestCase extends \Orchestra\Testbench\TestCase { + 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}'; + public function test_aaa() { $this->assertTrue(true); } + + protected function getPackageProviders($app) + { + return [ NamiServiceProvider::class ]; + } + + protected function setCredentials() { + Config::set('nami.auth.mglnr', '11223'); + Config::set('nami.auth.password', 'secret'); + Config::set('nami.auth.groupid', '55555'); + } + } diff --git a/tests/Unit/GetGroupsTest.php b/tests/Unit/GetGroupsTest.php index e1ef00b..e7377d8 100644 --- a/tests/Unit/GetGroupsTest.php +++ b/tests/Unit/GetGroupsTest.php @@ -12,35 +12,23 @@ use Zoomyboy\LaravelNami\LoginException; class GetGroupsTest extends TestCase { - 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}'; - public $groups = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":100}],"responseType":"OK"}'; - public $expiredJson = '{"servicePrefix":null,"methodCall":null,"response":null,"statusCode":3000,"statusMessage":"expired","apiSessionName":"JSESSIONID","apiSessionToken":"tGlSpMMij9ruHfeiUYjO7SD2","minorNumber":0,"majorNumber":0}'; - - protected function getPackageProviders($app) - { - return [ NamiServiceProvider::class ]; - } + public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":100}],"responseType":"OK"}'; public function test_get_all_groups() { Http::fake([ '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), - 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groups, 200), + 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200), ]); - Config::set('nami.auth.mglnr', '11223'); - Config::set('nami.auth.password', 'secret'); - Config::set('nami.auth.groupid', '55555'); + $this->setCredentials(); Nami::login(); $this->assertEquals([ (object) ['id' => 100, 'name' => 'Group'] ], Nami::groups()->toArray()); - Http::assertSent(function($request) { return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root'; }); @@ -52,12 +40,10 @@ class GetGroupsTest extends TestCase Http::fake([ '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), - 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groups, 200), + 'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200), ]); - Config::set('nami.auth.mglnr', '11223'); - Config::set('nami.auth.password', 'secret'); - Config::set('nami.auth.groupid', '55555'); + $this->setCredentials(); Nami::login(); $this->assertTrue(Nami::hasGroup(100)); diff --git a/tests/Unit/LoginTest.php b/tests/Unit/LoginTest.php index 639ad24..994914e 100644 --- a/tests/Unit/LoginTest.php +++ b/tests/Unit/LoginTest.php @@ -5,22 +5,11 @@ namespace Zoomyboy\LaravelNami\Tests\Unit; use Zoomyboy\LaravelNami\Nami; use Zoomyboy\LaravelNami\Tests\TestCase; use Illuminate\Support\Facades\Http; -use Illuminate\Support\Facades\Config; -use Zoomyboy\LaravelNami\NamiServiceProvider; use Zoomyboy\LaravelNami\LoginException; class Login extends TestCase { - 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}'; - - protected function getPackageProviders($app) - { - return [ NamiServiceProvider::class ]; - } - /** * A basic unit test example. * @@ -33,9 +22,7 @@ class Login extends TestCase 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200) ]); - Config::set('nami.auth.mglnr', '11223'); - Config::set('nami.auth.password', 'secret'); - Config::set('nami.auth.groupid', '55555'); + $this->setCredentials(); Nami::login(); @@ -56,9 +43,7 @@ class Login extends TestCase 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->bruteJson, 200) ]); - Config::set('nami.auth.mglnr', '11223'); - Config::set('nami.auth.password', 'secret'); - Config::set('nami.auth.groupid', '55555'); + $this->setCredentials(); try { Nami::login(); @@ -74,9 +59,7 @@ class Login extends TestCase 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::response($this->successJson, 200) ]); - Config::set('nami.auth.mglnr', '11223'); - Config::set('nami.auth.password', 'secret'); - Config::set('nami.auth.groupid', '55555'); + $this->setCredentials(); Nami::login(); Nami::login(); @@ -98,9 +81,7 @@ class Login extends TestCase 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' => Http::sequence()->push($this->wrongCredentialsJson, 200) ]); - Config::set('nami.auth.mglnr', '11223'); - Config::set('nami.auth.password', 'secret'); - Config::set('nami.auth.groupid', '55555'); + $this->setCredentials(); try { Nami::login(); @@ -110,35 +91,4 @@ class Login extends TestCase Http::assertSentCount(2); } - - /* - public function test_login_again_if_login_has_expired() - { - Http::fake([ - 'https://nami.dpsg.de/*' => Http::sequence() - ->push('<html></html>') - ->push($this->successJson, 200) - ->push($this->expiredJson, 200) - ->push('<html></html>') - ->push($this->successJson, 200) - ->push('me', 200) - ]); - - Config::set('nami.auth.mglnr', '11223'); - Config::set('nami.auth.password', 'secret'); - Config::set('nami.auth.groupid', '55555'); - - Nami::login(); - Nami::me(); - - Http::assertSent(function($request) { - return $request->url() == 'https://nami.dpsg.de/ica/pages/login.jsp'; - }); - Http::assertSent(function($request) { - return $request->url() == 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup' - && $request['username'] == '11223' && $request['password'] == 'secret' && $request['redirectTo'] == './app.jsp' && $request['Login'] == 'API'; - }); - Http::assertSentCount(6); - } - */ }