Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 351 Lines • ▼ Show 20 Lines | public function testStatusInfo(): void | ||||
$user->created_at = Carbon::now(); | $user->created_at = Carbon::now(); | ||||
$user->status = User::STATUS_NEW; | $user->status = User::STATUS_NEW; | ||||
$user->save(); | $user->save(); | ||||
$result = UsersController::statusInfo($user); | $result = UsersController::statusInfo($user); | ||||
$this->assertFalse($result['isReady']); | $this->assertFalse($result['isReady']); | ||||
$this->assertSame([], $result['betaSKUs']); | |||||
$this->assertCount(3, $result['process']); | $this->assertCount(3, $result['process']); | ||||
$this->assertSame('user-new', $result['process'][0]['label']); | $this->assertSame('user-new', $result['process'][0]['label']); | ||||
$this->assertSame(true, $result['process'][0]['state']); | $this->assertSame(true, $result['process'][0]['state']); | ||||
$this->assertSame('user-ldap-ready', $result['process'][1]['label']); | $this->assertSame('user-ldap-ready', $result['process'][1]['label']); | ||||
$this->assertSame(false, $result['process'][1]['state']); | $this->assertSame(false, $result['process'][1]['state']); | ||||
$this->assertSame('user-imap-ready', $result['process'][2]['label']); | $this->assertSame('user-imap-ready', $result['process'][2]['label']); | ||||
$this->assertSame(false, $result['process'][2]['state']); | $this->assertSame(false, $result['process'][2]['state']); | ||||
$this->assertSame('running', $result['processState']); | $this->assertSame('running', $result['processState']); | ||||
Show All 22 Lines | public function testStatusInfo(): void | ||||
$domain->status |= Domain::STATUS_VERIFIED; | $domain->status |= Domain::STATUS_VERIFIED; | ||||
$domain->type = Domain::TYPE_EXTERNAL; | $domain->type = Domain::TYPE_EXTERNAL; | ||||
$domain->save(); | $domain->save(); | ||||
$result = UsersController::statusInfo($user); | $result = UsersController::statusInfo($user); | ||||
$this->assertFalse($result['isReady']); | $this->assertFalse($result['isReady']); | ||||
$this->assertSame([], $result['betaSKUs']); | |||||
$this->assertCount(7, $result['process']); | $this->assertCount(7, $result['process']); | ||||
$this->assertSame('user-new', $result['process'][0]['label']); | $this->assertSame('user-new', $result['process'][0]['label']); | ||||
$this->assertSame(true, $result['process'][0]['state']); | $this->assertSame(true, $result['process'][0]['state']); | ||||
$this->assertSame('user-ldap-ready', $result['process'][1]['label']); | $this->assertSame('user-ldap-ready', $result['process'][1]['label']); | ||||
$this->assertSame(true, $result['process'][1]['state']); | $this->assertSame(true, $result['process'][1]['state']); | ||||
$this->assertSame('user-imap-ready', $result['process'][2]['label']); | $this->assertSame('user-imap-ready', $result['process'][2]['label']); | ||||
$this->assertSame(true, $result['process'][2]['state']); | $this->assertSame(true, $result['process'][2]['state']); | ||||
$this->assertSame('domain-new', $result['process'][3]['label']); | $this->assertSame('domain-new', $result['process'][3]['label']); | ||||
$this->assertSame(true, $result['process'][3]['state']); | $this->assertSame(true, $result['process'][3]['state']); | ||||
$this->assertSame('domain-ldap-ready', $result['process'][4]['label']); | $this->assertSame('domain-ldap-ready', $result['process'][4]['label']); | ||||
$this->assertSame(false, $result['process'][4]['state']); | $this->assertSame(false, $result['process'][4]['state']); | ||||
$this->assertSame('domain-verified', $result['process'][5]['label']); | $this->assertSame('domain-verified', $result['process'][5]['label']); | ||||
$this->assertSame(true, $result['process'][5]['state']); | $this->assertSame(true, $result['process'][5]['state']); | ||||
$this->assertSame('domain-confirmed', $result['process'][6]['label']); | $this->assertSame('domain-confirmed', $result['process'][6]['label']); | ||||
$this->assertSame(false, $result['process'][6]['state']); | $this->assertSame(false, $result['process'][6]['state']); | ||||
// Test betaSKUs property | |||||
$user->assignSku(Sku::where('title', 'beta')->first()); | |||||
$result = UsersController::statusInfo($user); | |||||
$this->assertSame([], $result['betaSKUs']); | |||||
$user->assignSku(Sku::where('title', 'meet')->first()); | |||||
$result = UsersController::statusInfo($user); | |||||
$this->assertSame(['meet'], $result['betaSKUs']); | |||||
$user->assignSku(Sku::where('title', 'meet')->first()); | |||||
$result = UsersController::statusInfo($user); | |||||
$this->assertSame(['meet'], $result['betaSKUs']); | |||||
} | } | ||||
/** | /** | ||||
* Test user creation (POST /api/v4/users) | * Test user creation (POST /api/v4/users) | ||||
*/ | */ | ||||
public function testStore(): void | public function testStore(): void | ||||
{ | { | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$deleted_priv = $this->getTestUser('deleted@kolab.org'); | $deleted_priv = $this->getTestUser('deleted@kolab.org'); | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | public function testUpdate(): void | ||||
// Test updating of self (empty request) | // Test updating of self (empty request) | ||||
$response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", []); | $response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", []); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame("User data updated successfully.", $json['message']); | $this->assertSame("User data updated successfully.", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertTrue(!empty($json['statusInfo'])); | ||||
$this->assertCount(3, $json); | |||||
// Test some invalid data | // Test some invalid data | ||||
$post = ['password' => '12345678', 'currency' => 'invalid']; | $post = ['password' => '12345678', 'currency' => 'invalid']; | ||||
$response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", $post); | $response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", $post); | ||||
$response->assertStatus(422); | $response->assertStatus(422); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
Show All 19 Lines | public function testUpdate(): void | ||||
$response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", $post); | $response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame("User data updated successfully.", $json['message']); | $this->assertSame("User data updated successfully.", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertTrue(!empty($json['statusInfo'])); | ||||
$this->assertCount(3, $json); | |||||
$this->assertTrue($userA->password != $userA->fresh()->password); | $this->assertTrue($userA->password != $userA->fresh()->password); | ||||
unset($post['password'], $post['password_confirmation'], $post['aliases']); | unset($post['password'], $post['password_confirmation'], $post['aliases']); | ||||
foreach ($post as $key => $value) { | foreach ($post as $key => $value) { | ||||
$this->assertSame($value, $userA->getSetting($key)); | $this->assertSame($value, $userA->getSetting($key)); | ||||
} | } | ||||
$aliases = $userA->aliases()->orderBy('alias')->get(); | $aliases = $userA->aliases()->orderBy('alias')->get(); | ||||
$this->assertCount(2, $aliases); | $this->assertCount(2, $aliases); | ||||
$this->assertSame('useralias1@' . \config('app.domain'), $aliases[0]->alias); | $this->assertSame('useralias1@' . \config('app.domain'), $aliases[0]->alias); | ||||
Show All 14 Lines | public function testUpdate(): void | ||||
$response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", $post); | $response = $this->actingAs($userA)->put("/api/v4/users/{$userA->id}", $post); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame("User data updated successfully.", $json['message']); | $this->assertSame("User data updated successfully.", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertTrue(!empty($json['statusInfo'])); | ||||
$this->assertCount(3, $json); | |||||
unset($post['aliases']); | unset($post['aliases']); | ||||
foreach ($post as $key => $value) { | foreach ($post as $key => $value) { | ||||
$this->assertNull($userA->getSetting($key)); | $this->assertNull($userA->getSetting($key)); | ||||
} | } | ||||
$aliases = $userA->aliases()->get(); | $aliases = $userA->aliases()->get(); | ||||
$this->assertCount(1, $aliases); | $this->assertCount(1, $aliases); | ||||
$this->assertSame('useralias2@' . \config('app.domain'), $aliases[0]->alias); | $this->assertSame('useralias2@' . \config('app.domain'), $aliases[0]->alias); | ||||
Show All 15 Lines | public function testUpdate(): void | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(2, $json['errors']); | $this->assertCount(2, $json['errors']); | ||||
$this->assertCount(2, $json['errors']['aliases']); | $this->assertCount(2, $json['errors']['aliases']); | ||||
$this->assertSame("The specified domain is not available.", $json['errors']['aliases'][1]); | $this->assertSame("The specified domain is not available.", $json['errors']['aliases'][1]); | ||||
$this->assertSame("The specified alias is invalid.", $json['errors']['aliases'][2]); | $this->assertSame("The specified alias is invalid.", $json['errors']['aliases'][2]); | ||||
$this->assertSame("The password confirmation does not match.", $json['errors']['password'][0]); | $this->assertSame("The password confirmation does not match.", $json['errors']['password'][0]); | ||||
// Test authorized update of other user | // Test authorized update of other user | ||||
$response = $this->actingAs($ned)->get("/api/v4/users/{$jack->id}", []); | $response = $this->actingAs($ned)->put("/api/v4/users/{$jack->id}", []); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | |||||
$this->assertTrue(empty($json['statusInfo'])); | |||||
// TODO: Test error on aliases with invalid/non-existing/other-user's domain | // TODO: Test error on aliases with invalid/non-existing/other-user's domain | ||||
// Create entitlements and additional user for following tests | // Create entitlements and additional user for following tests | ||||
$owner = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $owner = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$user = $this->getTestUser('UsersControllerTest2@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest2@userscontroller.com'); | ||||
$package_domain = Package::where('title', 'domain-hosting')->first(); | $package_domain = Package::where('title', 'domain-hosting')->first(); | ||||
$package_kolab = Package::where('title', 'kolab')->first(); | $package_kolab = Package::where('title', 'kolab')->first(); | ||||
$package_lite = Package::where('title', 'lite')->first(); | $package_lite = Package::where('title', 'lite')->first(); | ||||
Show All 25 Lines | public function testUpdate(): void | ||||
$sku_storage->id => 3, | $sku_storage->id => 3, | ||||
$sku_groupware->id => 1, | $sku_groupware->id => 1, | ||||
], | ], | ||||
]; | ]; | ||||
$response = $this->actingAs($owner)->put("/api/v4/users/{$user->id}", $post); | $response = $this->actingAs($owner)->put("/api/v4/users/{$user->id}", $post); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | |||||
$storage_cost = $user->entitlements() | $storage_cost = $user->entitlements() | ||||
->where('sku_id', $sku_storage->id) | ->where('sku_id', $sku_storage->id) | ||||
->orderBy('cost') | ->orderBy('cost') | ||||
->pluck('cost')->all(); | ->pluck('cost')->all(); | ||||
$this->assertUserEntitlements( | $this->assertUserEntitlements( | ||||
$user, | $user, | ||||
['groupware', 'mailbox', 'storage', 'storage', 'storage'] | ['groupware', 'mailbox', 'storage', 'storage', 'storage'] | ||||
); | ); | ||||
$this->assertSame([0, 0, 25], $storage_cost); | $this->assertSame([0, 0, 25], $storage_cost); | ||||
$this->assertTrue(empty($json['statusInfo'])); | |||||
} | } | ||||
/** | /** | ||||
* Test UsersController::updateEntitlements() | * Test UsersController::updateEntitlements() | ||||
*/ | */ | ||||
public function testUpdateEntitlements(): void | public function testUpdateEntitlements(): void | ||||
{ | { | ||||
$jane = $this->getTestUser('jane@kolabnow.com'); | $jane = $this->getTestUser('jane@kolabnow.com'); | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | public function testUserResponse(): void | ||||
$this->assertCount(0, $result['accounts']); | $this->assertCount(0, $result['accounts']); | ||||
$this->assertCount(1, $result['wallets']); | $this->assertCount(1, $result['wallets']); | ||||
$this->assertSame($wallet->id, $result['wallet']['id']); | $this->assertSame($wallet->id, $result['wallet']['id']); | ||||
$this->assertArrayNotHasKey('discount', $result['wallet']); | $this->assertArrayNotHasKey('discount', $result['wallet']); | ||||
$this->assertTrue($result['statusInfo']['enableDomains']); | $this->assertTrue($result['statusInfo']['enableDomains']); | ||||
$this->assertTrue($result['statusInfo']['enableWallets']); | $this->assertTrue($result['statusInfo']['enableWallets']); | ||||
$this->assertTrue($result['statusInfo']['enableUsers']); | $this->assertTrue($result['statusInfo']['enableUsers']); | ||||
$this->assertSame([], $result['statusInfo']['betaSKUs']); | |||||
// Ned is John's wallet controller | // Ned is John's wallet controller | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
$ned_wallet = $ned->wallets()->first(); | $ned_wallet = $ned->wallets()->first(); | ||||
$result = $this->invokeMethod(new UsersController(), 'userResponse', [$ned]); | $result = $this->invokeMethod(new UsersController(), 'userResponse', [$ned]); | ||||
$this->assertEquals($ned->id, $result['id']); | $this->assertEquals($ned->id, $result['id']); | ||||
$this->assertEquals($ned->email, $result['email']); | $this->assertEquals($ned->email, $result['email']); | ||||
$this->assertTrue(is_array($result['accounts'])); | $this->assertTrue(is_array($result['accounts'])); | ||||
$this->assertTrue(is_array($result['wallets'])); | $this->assertTrue(is_array($result['wallets'])); | ||||
$this->assertCount(1, $result['accounts']); | $this->assertCount(1, $result['accounts']); | ||||
$this->assertCount(1, $result['wallets']); | $this->assertCount(1, $result['wallets']); | ||||
$this->assertSame($wallet->id, $result['wallet']['id']); | $this->assertSame($wallet->id, $result['wallet']['id']); | ||||
$this->assertSame($wallet->id, $result['accounts'][0]['id']); | $this->assertSame($wallet->id, $result['accounts'][0]['id']); | ||||
$this->assertSame($ned_wallet->id, $result['wallets'][0]['id']); | $this->assertSame($ned_wallet->id, $result['wallets'][0]['id']); | ||||
$this->assertSame($provider, $result['wallet']['provider']); | $this->assertSame($provider, $result['wallet']['provider']); | ||||
$this->assertSame($provider, $result['wallets'][0]['provider']); | $this->assertSame($provider, $result['wallets'][0]['provider']); | ||||
$this->assertTrue($result['statusInfo']['enableDomains']); | $this->assertTrue($result['statusInfo']['enableDomains']); | ||||
$this->assertTrue($result['statusInfo']['enableWallets']); | $this->assertTrue($result['statusInfo']['enableWallets']); | ||||
$this->assertTrue($result['statusInfo']['enableUsers']); | $this->assertTrue($result['statusInfo']['enableUsers']); | ||||
$this->assertSame([], $result['statusInfo']['betaSKUs']); | |||||
// Test discount in a response | // Test discount in a response | ||||
$discount = Discount::where('code', 'TEST')->first(); | $discount = Discount::where('code', 'TEST')->first(); | ||||
$wallet->discount()->associate($discount); | $wallet->discount()->associate($discount); | ||||
$wallet->save(); | $wallet->save(); | ||||
$mod_provider = $provider == 'mollie' ? 'stripe' : 'mollie'; | $mod_provider = $provider == 'mollie' ? 'stripe' : 'mollie'; | ||||
$wallet->setSetting($mod_provider . '_id', 123); | $wallet->setSetting($mod_provider . '_id', 123); | ||||
$user->refresh(); | $user->refresh(); | ||||
Show All 12 Lines | public function testUserResponse(): void | ||||
// Jack is not a John's wallet controller | // Jack is not a John's wallet controller | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$result = $this->invokeMethod(new UsersController(), 'userResponse', [$jack]); | $result = $this->invokeMethod(new UsersController(), 'userResponse', [$jack]); | ||||
$this->assertFalse($result['statusInfo']['enableDomains']); | $this->assertFalse($result['statusInfo']['enableDomains']); | ||||
$this->assertFalse($result['statusInfo']['enableWallets']); | $this->assertFalse($result['statusInfo']['enableWallets']); | ||||
$this->assertFalse($result['statusInfo']['enableUsers']); | $this->assertFalse($result['statusInfo']['enableUsers']); | ||||
$this->assertSame([], $result['statusInfo']['betaSKUs']); | |||||
} | } | ||||
/** | /** | ||||
* List of alias validation cases for testValidateEmail() | * List of alias validation cases for testValidateEmail() | ||||
* | * | ||||
* @return array Arguments for testValidateEmail() | * @return array Arguments for testValidateEmail() | ||||
*/ | */ | ||||
public function dataValidateEmail(): array | public function dataValidateEmail(): array | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |