Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 643 Lines • ▼ Show 20 Lines | public function testUpdate(): void | ||||
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); | ||||
// Test error on setting an alias to other user's domain | // Test error on some invalid aliases missing password confirmation | ||||
// and missing password confirmation | |||||
$post = [ | $post = [ | ||||
'password' => 'simple123', | 'password' => 'simple123', | ||||
'aliases' => ['useralias2@' . \config('app.domain'), 'useralias1@kolab.org'] | 'aliases' => [ | ||||
'useralias2@' . \config('app.domain'), | |||||
'useralias1@kolab.org', | |||||
'@kolab.org', | |||||
] | |||||
]; | ]; | ||||
$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(422); | $response->assertStatus(422); | ||||
$this->assertSame('error', $json['status']); | $this->assertSame('error', $json['status']); | ||||
$this->assertCount(2, $json['errors']); | $this->assertCount(2, $json['errors']); | ||||
$this->assertCount(1, $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 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)->get("/api/v4/users/{$jack->id}", []); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
// 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 | ||||
▲ Show 20 Lines • Show All 332 Lines • Show Last 20 Lines |