2020-06-29 00:30:57 +02:00
< ? php
2022-11-29 16:53:59 +01:00
namespace Zoomyboy\LaravelNami\Tests\Unit\Member ;
2020-06-29 00:30:57 +02:00
2022-02-10 20:31:02 +01:00
use Illuminate\Support\Facades\Http ;
2022-02-19 22:11:46 +01:00
use Zoomyboy\LaravelNami\Fakes\MemberFake ;
use Zoomyboy\LaravelNami\NamiException ;
2022-11-29 17:14:31 +01:00
use Zoomyboy\LaravelNami\Tests\Factories\MemberRequestFactory ;
2022-02-10 20:31:02 +01:00
use Zoomyboy\LaravelNami\Tests\TestCase ;
2020-06-29 00:30:57 +02:00
2022-11-29 16:53:59 +01:00
class PullTest extends TestCase
2020-06-29 00:30:57 +02:00
{
2022-02-10 20:31:02 +01:00
public string $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}' ;
public string $unauthorizedResponse = '{"success":false,"data":null,"responseType":"EXCEPTION","message":"Access denied - no right for requested operation","title":"Exception"}' ;
2020-06-29 00:30:57 +02:00
2022-03-11 20:20:00 +01:00
public function dataProvider () : array
{
2020-06-29 00:30:57 +02:00
return [
2022-03-11 20:20:00 +01:00
'firstname' => [[ 'vorname' => 'Max' ], [ 'firstname' => 'Max' ]],
'lastname' => [[ 'nachname' => 'Nach' ], [ 'lastname' => 'Nach' ]],
'nickname' => [[ 'spitzname' => 'spitz1' ], [ 'nickname' => 'spitz1' ]],
'nicknameEmpty' => [[ 'spitzname' => null ], [ 'nickname' => null ]],
'other_country' => [[ 'staatsangehoerigkeitText' => 'deutsch' ], [ 'other_country' => 'deutsch' ]],
'other_countryEmpty' => [[ 'staatsangehoerigkeitText' => '' ], [ 'other_country' => null ]],
'address' => [[ 'strasse' => 'Straße 1' ], [ 'address' => 'Straße 1' ]],
'further_address' => [[ 'nameZusatz' => 'addrz' ], [ 'further_address' => 'addrz' ]],
'further_addressEmpty' => [[ 'nameZusatz' => '' ], [ 'further_address' => null ]],
'zip' => [[ 'plz' => '12345' ], [ 'zip' => '12345' ]],
'location' => [[ 'ort' => 'Köln' ], [ 'location' => 'Köln' ]],
'main_phone' => [[ 'telefon1' => '+49888' ], [ 'main_phone' => '+49888' ]],
'mobile_phone' => [[ 'telefon2' => '+49176' ], [ 'mobile_phone' => '+49176' ]],
'work_phone' => [[ 'telefon3' => '+49177' ], [ 'work_phone' => '+49177' ]],
'fax' => [[ 'telefax' => '+55111' ], [ 'fax' => '+55111' ]],
'email' => [[ 'email' => 'a@b.de' ], [ 'email' => 'a@b.de' ]],
'email_parents' => [[ 'emailVertretungsberechtigter' => 'v@b.de' ], [ 'email_parents' => 'v@b.de' ]],
'gender_id' => [[ 'geschlechtId' => 19 ], [ 'gender_id' => 19 ]],
'gender_idEmpty' => [[ 'geschlechtId' => 23 ], [ 'gender_id' => null ]],
'nationality_id' => [[ 'staatsangehoerigkeitId' => 1054 ], [ 'nationality_id' => 1054 ]],
'nationality_idEmpty' => [[ 'staatsangehoerigkeitId' => null ], [ 'nationality_id' => null ]],
'confession_id' => [[ 'konfessionId' => 1 ], [ 'confession_id' => 1 ]],
'confession_idEmpty' => [[ 'konfessionId' => null ], [ 'confession_id' => null ]],
'birthday' => [[ 'geburtsDatum' => '1991-06-20 00:00:00' ], [ 'birthday' => '1991-06-20' ]],
'joined_at' => [[ 'eintrittsdatum' => '2005-05-01 00:00:00' ], [ 'joined_at' => '2005-05-01' ]],
'group_id' => [[ 'gruppierungId' => 103 ], [ 'group_id' => 103 ]],
'mitgliedsnr' => [[ 'mitgliedsNummer' => 12345 ], [ 'mitgliedsnr' => 12345 ]],
'mitgliedsnrEmpty' => [[ 'mitgliedsNummer' => null ], [ 'mitgliedsnr' => null ]],
'updated_at' => [[ 'lastUpdated' => '2020-06-28 02:15:24' ], [ 'updated_at' => '2020-06-28 02:15:24' ]],
'send_newspaper' => [[ 'zeitschriftenversand' => true ], [ 'send_newspaper' => true ]],
'region_id' => [[ 'regionId' => 10 ], [ 'region_id' => 10 ]],
'region_idEmpty' => [[ 'regionId' => null ], [ 'region_id' => null ]],
'country_id' => [[ 'landId' => 100 ], [ 'country_id' => 100 ]],
'fee_id' => [[ 'beitragsartId' => 1 ], [ 'fee_id' => 1 ]],
2020-06-29 00:30:57 +02:00
];
}
2022-03-11 20:20:00 +01:00
public function overviewDataProvider () : array
{
2020-07-04 00:38:09 +02:00
return [
'firstname' => [ 'firstname' , [ 'Max' , 'Jane' ]],
'lastname' => [ 'lastname' , [ 'Nach1' , 'Nach2' ]],
'nickname' => [ 'nickname' , [ 'spitz1' , null ]],
'other_country' => [ 'other_country' , [ 'deutsch' , null ]],
'main_phone' => [ 'main_phone' , [ '+49888' , '+49668' ]],
'mobile_phone' => [ 'mobile_phone' , [ '+49176' , '+49172' ]],
'work_phone' => [ 'work_phone' , [ '+11111' , '+22222' ]],
'fax' => [ 'fax' , [ '+55111' , '+55222' ]],
'email' => [ 'email' , [ 'test@example.com' , 'test2@example.com' ]],
'email_parents' => [ 'email_parents' , [ 'testp@example.com' , 'test2p@example.com' ]],
'gender_id' => [ 'gender_id' , [ 19 , null ]],
'birthday' => [ 'birthday' , [ '1991-06-20' , '1984-01-17' ]],
2020-07-04 01:08:26 +02:00
'joined_at' => [ 'joined_at' , [ '2005-05-01' , null ]],
2020-07-04 13:07:58 +02:00
'group_id' => [ 'group_id' , [ 103 , 103 ]],
2020-09-15 22:02:28 +02:00
'mitgliedsnr' => [ 'mitgliedsnr' , [ 12345 , null ]],
2022-03-11 20:20:00 +01:00
'updated_at' => [ 'updated_at' , [ '2020-06-28 02:15:24' , '2015-02-03 15:20:07' ]],
2020-07-04 00:38:09 +02:00
];
}
2022-03-11 20:20:00 +01:00
public function relationProvider () : array
{
2020-06-29 23:12:16 +02:00
return [
'firstname' => [ 'firstname' , [ 'Max' , 'Jane' ]],
];
}
2022-11-29 17:14:31 +01:00
public function testGetASingleMember () : void
2022-02-10 20:31:02 +01:00
{
2022-02-18 18:29:02 +01:00
Http :: fake ([
2022-11-29 17:14:31 +01:00
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => MemberRequestFactory :: new () -> state ([
'vorname' => 'Max' ,
'nachname' => 'Nach' ,
'spitzname' => 'spitz1' ,
]) -> toSingleHttp (),
2022-02-18 18:29:02 +01:00
]);
2020-06-29 00:30:57 +02:00
2022-11-29 16:53:59 +01:00
$member = $this -> login () -> member ( 103 , 16 );
2020-06-29 00:30:57 +02:00
2022-11-29 16:53:59 +01:00
$this -> assertEquals ( 'Max' , $member -> firstname );
2022-11-29 17:14:31 +01:00
$this -> assertEquals ( 'Nach' , $member -> lastname );
$this -> assertEquals ( 'spitz1' , $member -> nickname );
}
public function testGetASingleMemberWithEmptyNames () : void
{
Http :: fake ([
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => MemberRequestFactory :: new () -> withEmptyNames () -> toSingleHttp (),
]);
$member = $this -> login () -> member ( 103 , 16 );
2020-06-29 00:30:57 +02:00
2022-11-29 17:14:31 +01:00
$this -> assertNull ( $member -> firstname );
$this -> assertNull ( $member -> lastname );
$this -> assertNull ( $member -> nickname );
2020-06-29 00:30:57 +02:00
}
/**
* @ dataProvider dataProvider
*/
2022-03-11 20:20:00 +01:00
public function testGetAttributeOfMemberCollection ( array $input , array $check ) : void
2022-02-10 20:31:02 +01:00
{
2022-02-18 18:29:02 +01:00
Http :: fake ([
2020-06-29 00:30:57 +02:00
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http :: response ( $this -> groupsResponse , 200 ),
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http :: response ( $this -> fakeJson ( 'member_overview.json' ), 200 ),
2022-02-10 23:19:31 +01:00
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http :: response ( $this -> fakeJson ( 'member-16.json' , [ 'data' => $input ]), 200 ),
2022-02-18 18:29:02 +01:00
]);
2020-06-29 00:30:57 +02:00
2022-02-18 18:29:02 +01:00
$member = $this -> login () -> group ( 103 ) -> members () -> first ();
2020-06-29 00:30:57 +02:00
2022-02-10 23:19:31 +01:00
foreach ( $check as $key => $value ) {
$this -> assertSame ( $value , $member -> toArray ()[ $key ]);
}
2022-02-18 18:29:02 +01:00
Http :: assertSentCount ( 3 );
2020-06-29 00:30:57 +02:00
}
2020-08-15 02:03:11 +02:00
/**
* @ dataProvider overviewDataProvider
*/
2022-03-11 20:20:00 +01:00
public function testGetAttributeOfMemberOverview ( string $key , array $values ) : void
2022-02-10 20:31:02 +01:00
{
2022-02-18 18:29:02 +01:00
Http :: fake ([
2020-08-15 02:03:11 +02:00
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http :: response ( $this -> groupsResponse , 200 ),
2022-03-11 20:20:00 +01:00
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http :: response ( $this -> fakeJson ( 'member_overview.json' ), 200 ),
2022-02-18 18:29:02 +01:00
]);
2020-08-15 02:03:11 +02:00
2022-02-18 18:29:02 +01:00
$members = $this -> login () -> group ( 103 ) -> memberOverview ();
2020-08-15 02:03:11 +02:00
foreach ( $members as $i => $m ) {
$this -> assertSame ( $values [ $i ], $m -> toArray ()[ $key ]);
}
2022-02-18 18:29:02 +01:00
Http :: assertSentCount ( 2 );
2020-08-15 02:03:11 +02:00
}
2020-06-29 23:12:16 +02:00
/**
* @ dataProvider relationProvider
*/
2022-03-11 20:20:00 +01:00
public function testSetRelations ( string $key , array $values ) : void
2022-02-10 20:31:02 +01:00
{
2022-02-18 18:29:02 +01:00
Http :: fake ([
2020-06-29 23:12:16 +02:00
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http :: response ( $this -> groupsResponse , 200 ),
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http :: response ( $this -> fakeJson ( 'member_overview.json' ), 200 ),
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http :: response ( $this -> fakeJson ( 'member-16.json' ), 200 ),
2022-03-11 20:20:00 +01:00
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/17' => Http :: response ( $this -> fakeJson ( 'member-17.json' ), 200 ),
2022-02-18 18:29:02 +01:00
]);
2020-06-29 23:12:16 +02:00
2022-02-18 18:29:02 +01:00
$members = $this -> login () -> group ( 103 ) -> members ();
2020-06-29 23:12:16 +02:00
2020-07-04 01:08:26 +02:00
$this -> assertSame ([
2020-06-29 23:12:16 +02:00
16 => $values [ 0 ],
2022-03-11 20:20:00 +01:00
17 => $values [ 1 ],
2022-02-18 18:29:02 +01:00
], $members -> pluck ( $key , 'id' ) -> toArray ());
2020-06-29 23:12:16 +02:00
2022-02-18 18:29:02 +01:00
Http :: assertSentCount ( 4 );
2020-06-29 23:12:16 +02:00
}
2020-07-04 00:38:09 +02:00
/**
* @ dataProvider overviewDataProvider
*/
2022-03-11 20:20:00 +01:00
public function testGetAMemberFromOverviewWithNoRights ( string $key , array $values ) : void
2022-02-10 20:31:02 +01:00
{
2022-02-18 18:29:02 +01:00
Http :: fake ([
2020-07-04 00:38:09 +02:00
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http :: response ( $this -> groupsResponse , 200 ),
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http :: response ( $this -> unauthorizedResponse , 200 ),
2022-03-11 20:20:00 +01:00
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http :: response ( $this -> fakeJson ( 'member_overview.json' ), 200 ),
2022-02-18 18:29:02 +01:00
]);
2020-07-04 00:38:09 +02:00
2022-02-18 18:29:02 +01:00
$member = $this -> login () -> group ( 103 ) -> member ( 16 );
2020-07-04 00:38:09 +02:00
2022-02-18 18:29:02 +01:00
$this -> assertSame ( $values [ 0 ], $member -> toArray ()[ $key ]);
2020-07-04 00:38:09 +02:00
2022-02-18 18:29:02 +01:00
Http :: assertSentCount ( 3 );
2020-07-04 00:38:09 +02:00
}
2022-03-11 20:20:00 +01:00
public function testMemberFetchCanFail () : void
2022-02-19 22:11:46 +01:00
{
$this -> expectException ( NamiException :: class );
app ( MemberFake :: class ) -> fetchFails ( 103 , 16 );
$this -> login () -> member ( 103 , 16 );
}
2020-06-29 00:30:57 +02:00
}