Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 698 Lines • ▼ Show 20 Lines | public function testStore(): void | ||||
$this->assertCount(2, $aliases); | $this->assertCount(2, $aliases); | ||||
$this->assertSame('deleted@kolab.org', $aliases[0]->alias); | $this->assertSame('deleted@kolab.org', $aliases[0]->alias); | ||||
$this->assertSame('useralias1@kolab.org', $aliases[1]->alias); | $this->assertSame('useralias1@kolab.org', $aliases[1]->alias); | ||||
// Assert the new user entitlements | // Assert the new user entitlements | ||||
$this->assertEntitlements($user, ['groupware', 'mailbox', | $this->assertEntitlements($user, ['groupware', 'mailbox', | ||||
'storage', 'storage', 'storage', 'storage', 'storage']); | 'storage', 'storage', 'storage', 'storage', 'storage']); | ||||
// Assert the wallet to which the new user should be assigned to | // Assert the wallet to which the new user should be assigned to | ||||
$wallet = $user->wallet(); | $wallet = $user->wallet(); | ||||
$this->assertSame($john->wallets()->first()->id, $wallet->id); | $this->assertSame($john->wallets->first()->id, $wallet->id); | ||||
// Attempt to create a user previously deleted | // Attempt to create a user previously deleted | ||||
$user->delete(); | $user->delete(); | ||||
$post['package'] = $package_kolab->id; | $post['package'] = $package_kolab->id; | ||||
$post['aliases'] = []; | $post['aliases'] = []; | ||||
$response = $this->actingAs($john)->post("/api/v4/users", $post); | $response = $this->actingAs($john)->post("/api/v4/users", $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 created successfully.", $json['message']); | $this->assertSame("User created successfully.", $json['message']); | ||||
$this->assertCount(2, $json); | $this->assertCount(2, $json); | ||||
$user = User::where('email', 'john2.doe2@kolab.org')->first(); | $user = User::where('email', 'john2.doe2@kolab.org')->first(); | ||||
$this->assertInstanceOf(User::class, $user); | $this->assertInstanceOf(User::class, $user); | ||||
$this->assertSame('John2', $user->getSetting('first_name')); | $this->assertSame('John2', $user->getSetting('first_name')); | ||||
$this->assertSame('Doe2', $user->getSetting('last_name')); | $this->assertSame('Doe2', $user->getSetting('last_name')); | ||||
$this->assertSame('TestOrg', $user->getSetting('organization')); | $this->assertSame('TestOrg', $user->getSetting('organization')); | ||||
$this->assertCount(0, $user->aliases()->get()); | $this->assertCount(0, $user->aliases()->get()); | ||||
$this->assertEntitlements($user, ['groupware', 'mailbox', | $this->assertEntitlements($user, ['groupware', 'mailbox', | ||||
'storage', 'storage', 'storage', 'storage', 'storage']); | 'storage', 'storage', 'storage', 'storage', 'storage']); | ||||
// Test acting as account controller (not owner) | // Test password reset link "mode" | ||||
$code = new \App\VerificationCode(['mode' => 'password-reset', 'active' => false]); | |||||
$john->verificationcodes()->save($code); | |||||
$this->markTestIncomplete(); | $post = [ | ||||
'first_name' => 'John2', | |||||
'last_name' => 'Doe2', | |||||
'email' => 'deleted@kolab.org', | |||||
'organization' => '', | |||||
'aliases' => [], | |||||
'passwordLinkCode' => $code->short_code . '-' . $code->code, | |||||
'package' => $package_kolab->id, | |||||
]; | |||||
$response = $this->actingAs($john)->post("/api/v4/users", $post); | |||||
$json = $response->json(); | |||||
$response->assertStatus(200); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame("User created successfully.", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
$user = $this->getTestUser('deleted@kolab.org'); | |||||
$code->refresh(); | |||||
$this->assertSame($user->id, $code->user_id); | |||||
$this->assertTrue($code->active); | |||||
$this->assertTrue(is_string($user->password) && strlen($user->password) >= 60); | |||||
// Test acting as account controller not owner, which is not yet supported | |||||
$john->wallets->first()->addController($user); | |||||
$response = $this->actingAs($user)->post("/api/v4/users", []); | |||||
$response->assertStatus(403); | |||||
} | } | ||||
/** | /** | ||||
* Test user update (PUT /api/v4/users/<user-id>) | * Test user update (PUT /api/v4/users/<user-id>) | ||||
*/ | */ | ||||
public function testUpdate(): void | public function testUpdate(): void | ||||
{ | { | ||||
$userA = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $userA = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | public function testUpdate(): void | ||||
$this->assertEntitlements( | $this->assertEntitlements( | ||||
$user, | $user, | ||||
['groupware', 'mailbox', 'storage', 'storage', 'storage', 'storage', 'storage', 'storage'] | ['groupware', 'mailbox', 'storage', 'storage', 'storage', 'storage', 'storage', 'storage'] | ||||
); | ); | ||||
$this->assertSame([0, 0, 0, 0, 0, 25], $storage_cost); | $this->assertSame([0, 0, 0, 0, 0, 25], $storage_cost); | ||||
$this->assertTrue(empty($json['statusInfo'])); | $this->assertTrue(empty($json['statusInfo'])); | ||||
// Test password reset link "mode" | |||||
$code = new \App\VerificationCode(['mode' => 'password-reset', 'active' => false]); | |||||
$owner->verificationcodes()->save($code); | |||||
$post = ['passwordLinkCode' => $code->short_code . '-' . $code->code]; | |||||
$response = $this->actingAs($owner)->put("/api/v4/users/{$user->id}", $post); | |||||
$json = $response->json(); | |||||
$response->assertStatus(200); | |||||
$code->refresh(); | |||||
$this->assertSame($user->id, $code->user_id); | |||||
$this->assertTrue($code->active); | |||||
$this->assertSame($user->password, $user->fresh()->password); | |||||
} | } | ||||
/** | /** | ||||
* 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 464 Lines • Show Last 20 Lines |