Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 887 Lines • ▼ Show 20 Lines | public function testStore(): void | ||||
$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->assertFalse($user->isRestricted()); | |||||
/** @var \App\UserAlias[] $aliases */ | /** @var \App\UserAlias[] $aliases */ | ||||
$aliases = $user->aliases()->orderBy('alias')->get(); | $aliases = $user->aliases()->orderBy('alias')->get(); | ||||
$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']); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public function testStore(): void | ||||
$this->assertTrue($code->active); | $this->assertTrue($code->active); | ||||
$this->assertTrue(is_string($user->password) && strlen($user->password) >= 60); | $this->assertTrue(is_string($user->password) && strlen($user->password) >= 60); | ||||
// Test acting as account controller not owner, which is not yet supported | // Test acting as account controller not owner, which is not yet supported | ||||
$john->wallets->first()->addController($user); | $john->wallets->first()->addController($user); | ||||
$response = $this->actingAs($user)->post("/api/v4/users", []); | $response = $this->actingAs($user)->post("/api/v4/users", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Test that creating a user in a restricted account creates a restricted user | |||||
$package_domain = Package::withEnvTenantContext()->where('title', 'domain-hosting')->first(); | |||||
$owner = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | |||||
$domain = $this->getTestDomain( | |||||
'userscontroller.com', | |||||
['status' => Domain::STATUS_NEW, 'type' => Domain::TYPE_EXTERNAL] | |||||
); | |||||
$domain->assignPackage($package_domain, $owner); | |||||
$owner->restrict(); | |||||
$post = [ | |||||
'password' => 'simple123', | |||||
'password_confirmation' => 'simple123', | |||||
'email' => 'UsersControllerTest2@userscontroller.com', | |||||
'package' => $package_kolab->id, | |||||
]; | |||||
$response = $this->actingAs($owner)->post("/api/v4/users", $post); | |||||
$response->assertStatus(200); | |||||
$user = User::where('email', 'UsersControllerTest1@userscontroller.com')->first(); | |||||
$this->assertTrue($user->isRestricted()); | |||||
} | } | ||||
/** | /** | ||||
* 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 693 Lines • Show Last 20 Lines |