|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace UnitTestFiles\Test; |
| 4 | + |
| 5 | +use Route4Me\Constants; |
| 6 | +use Route4Me\Route4Me; |
| 7 | +use Route4Me\Members\Member; |
| 8 | +use Route4Me\V5\TeamManagement\Option; |
| 9 | +use Route4Me\V5\TeamManagement\Permission; |
| 10 | +use Route4Me\V5\TeamManagement\ResponseTeam; |
| 11 | +use Route4Me\V5\TeamManagement\TeamManagement; |
| 12 | + |
| 13 | +final class TeamManagementUnitTests extends \PHPUnit\Framework\TestCase |
| 14 | +{ |
| 15 | + public static ?int $member_id = null; |
| 16 | + public static ?int $owner_member_id = null; |
| 17 | + |
| 18 | + public static function setUpBeforeClass() : void |
| 19 | + { |
| 20 | + Route4Me::setApiKey(Constants::API_KEY); |
| 21 | + } |
| 22 | + |
| 23 | + public function testOwnerMemberMustExists() : void |
| 24 | + { |
| 25 | + $member = new Member(); |
| 26 | + $res_members = $member->getUsers(); |
| 27 | + |
| 28 | + if (is_array($res_members) && isset($res_members['results'])) { |
| 29 | + foreach ($res_members['results'] as $key => $value) { |
| 30 | + if ($value['OWNER_MEMBER_ID'] == 0) { |
| 31 | + self::$owner_member_id = $value['member_id']; |
| 32 | + break; |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + $this->assertNotNull(self::$owner_member_id); |
| 37 | + } |
| 38 | + |
| 39 | + public function testOptionCanBeCreateEmpty() : void |
| 40 | + { |
| 41 | + $this->assertInstanceOf(Option::class, new Option()); |
| 42 | + } |
| 43 | + |
| 44 | + public function testOptionCanBeCreateFromArray() : void |
| 45 | + { |
| 46 | + $this->assertInstanceOf(Option::class, new Option([ |
| 47 | + 'value' => '1', |
| 48 | + 'title' => '2' |
| 49 | + ])); |
| 50 | + } |
| 51 | + |
| 52 | + public function testPermissionCanBeCreateEmpty() : void |
| 53 | + { |
| 54 | + $this->assertInstanceOf(Permission::class, new Permission()); |
| 55 | + } |
| 56 | + |
| 57 | + public function testPermissionCanBeCreateFromArray() : void |
| 58 | + { |
| 59 | + $this->assertInstanceOf(Permission::class, new Permission([ |
| 60 | + 'id' => '1', |
| 61 | + 'options' => [ |
| 62 | + [ |
| 63 | + 'value' => '2', |
| 64 | + 'title' => '3' |
| 65 | + ], [ |
| 66 | + 'value' => '4', |
| 67 | + 'title' => '5' |
| 68 | + ] |
| 69 | + ] |
| 70 | + ])); |
| 71 | + } |
| 72 | + |
| 73 | + public function testResponseTeamCanBeCreateEmpty() : void |
| 74 | + { |
| 75 | + $this->assertInstanceOf(ResponseTeam::class, new ResponseTeam()); |
| 76 | + } |
| 77 | + |
| 78 | + public function testResponseTeamCanBeCreateFromArray() : void |
| 79 | + { |
| 80 | + $this->assertInstanceOf(ResponseTeam::class, new ResponseTeam([ |
| 81 | + 'member_id' => '1', |
| 82 | + 'member_first_name' => '2' |
| 83 | + ])); |
| 84 | + } |
| 85 | + |
| 86 | + public function testTeamManagementCanBeCreateEmpty() : void |
| 87 | + { |
| 88 | + $this->assertInstanceOf(TeamManagement::class, new TeamManagement()); |
| 89 | + } |
| 90 | + |
| 91 | + public function testCreateMustReturnResponseTeam() : void |
| 92 | + { |
| 93 | + $team_mng = new TeamManagement(); |
| 94 | + $res_team = $team_mng->create([ |
| 95 | + 'new_password' => '12345&Qwerty', |
| 96 | + 'member_first_name' => 'Tusha I', |
| 97 | + 'member_last_name' => 'Pupkindzes', |
| 98 | + 'member_email' => '[email protected]', |
| 99 | + 'member_type' => 'SUB_ACCOUNT_DRIVER', |
| 100 | + 'OWNER_MEMBER_ID' => self::$owner_member_id |
| 101 | + ]); |
| 102 | + |
| 103 | + $this->assertInstanceOf(ResponseTeam::class, $res_team); |
| 104 | + $this->assertNotNull($res_team->member_id); |
| 105 | + $this->assertEquals($res_team->member_first_name, 'Tusha I'); |
| 106 | + |
| 107 | + self::$member_id = $res_team->member_id; |
| 108 | + } |
| 109 | + |
| 110 | + public function testGetUserMustReturnResponseTeam() : void |
| 111 | + { |
| 112 | + $team_mng = new TeamManagement(); |
| 113 | + $res_team = $team_mng->getUser(self::$member_id); |
| 114 | + |
| 115 | + $this->assertInstanceOf(ResponseTeam::class, $res_team); |
| 116 | + $this->assertNotNull($res_team->member_id); |
| 117 | + $this->assertEquals($res_team->member_first_name, 'Tusha I'); |
| 118 | + } |
| 119 | + |
| 120 | + public function testGetUsersMustReturnArrayOfResponseTeam() : void |
| 121 | + { |
| 122 | + $team_mng = new TeamManagement(); |
| 123 | + $result = $team_mng->getUsers(); |
| 124 | + |
| 125 | + $this->assertIsArray($result); |
| 126 | + if (count($result) > 0) { |
| 127 | + $this->assertInstanceOf(ResponseTeam::class, $result[0]); |
| 128 | + } |
| 129 | + } |
| 130 | + |
| 131 | + public function testUpdateMustReturnUpdatedResponseTeam() : void |
| 132 | + { |
| 133 | + $team_mng = new TeamManagement(); |
| 134 | + $res_team = $team_mng->update(self::$member_id, [ |
| 135 | + 'HIDE_ROUTED_ADDRESSES' => true, |
| 136 | + 'member_type' => 'SUB_ACCOUNT_DISPATCHER' |
| 137 | + ]); |
| 138 | + |
| 139 | + $this->assertInstanceOf(ResponseTeam::class, $res_team); |
| 140 | + $this->assertEquals($res_team->HIDE_ROUTED_ADDRESSES, 1); |
| 141 | + $this->assertEquals($res_team->member_type, 'SUB_ACCOUNT_DISPATCHER'); |
| 142 | + } |
| 143 | + |
| 144 | + public function testDeleteMustReturnDeletedResponseTeam() : void |
| 145 | + { |
| 146 | + $team_mng = new TeamManagement(); |
| 147 | + $res_team = $team_mng->delete(self::$member_id); |
| 148 | + |
| 149 | + $this->assertInstanceOf(ResponseTeam::class, $res_team); |
| 150 | + $this->assertNotNull($res_team->member_id); |
| 151 | + $this->assertEquals($res_team->member_first_name, 'Tusha I'); |
| 152 | + } |
| 153 | + |
| 154 | + public function testBulkInsertMustAddNewMembers() : void |
| 155 | + { |
| 156 | + $team_mng = new TeamManagement(); |
| 157 | + $result = $team_mng->bulkInsert([ |
| 158 | + [ |
| 159 | + 'new_password' => '12345&Qwerty', |
| 160 | + 'member_first_name' => 'Tusha I', |
| 161 | + 'member_last_name' => 'Pupkindzes', |
| 162 | + 'member_email' => '[email protected]', |
| 163 | + 'member_type' => 'SUB_ACCOUNT_DRIVER', |
| 164 | + 'OWNER_MEMBER_ID' => self::$owner_member_id |
| 165 | + ], [ |
| 166 | + 'new_password' => '12345&Qwerty', |
| 167 | + 'member_first_name' => 'Tusha II', |
| 168 | + 'member_last_name' => 'Pupkindzes', |
| 169 | + 'member_email' => '[email protected]', |
| 170 | + 'member_type' => 'SUB_ACCOUNT_DRIVER', |
| 171 | + 'OWNER_MEMBER_ID' => self::$owner_member_id |
| 172 | + ] |
| 173 | + ], [ |
| 174 | + 'conflicts' => 'overwrite' |
| 175 | + ]); |
| 176 | + |
| 177 | + $this->assertIsArray($result); |
| 178 | + } |
| 179 | + |
| 180 | + public static function tearDownAfterClass() : void |
| 181 | + { |
| 182 | + sleep(5); |
| 183 | + |
| 184 | + $team_mng = new TeamManagement(); |
| 185 | + $result = $team_mng->getUsers(); |
| 186 | + |
| 187 | + if (is_array($result)) { |
| 188 | + foreach ($result as $key => $member) { |
| 189 | + if ($member->member_last_name == 'Pupkindzes') { |
| 190 | + $team_mng->delete($member->member_id); |
| 191 | + } |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | +} |
0 commit comments