Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show First 20 Lines • Show All 222 Lines • ▼ Show 20 Lines | public function testIndex(): void | ||||
$this->assertSame($john->email, $json['list'][2]['email']); | $this->assertSame($john->email, $json['list'][2]['email']); | ||||
$this->assertSame($ned->email, $json['list'][3]['email']); | $this->assertSame($ned->email, $json['list'][3]['email']); | ||||
// Values below are tested by Unit tests | // Values below are tested by Unit tests | ||||
$this->assertArrayHasKey('isDeleted', $json['list'][0]); | $this->assertArrayHasKey('isDeleted', $json['list'][0]); | ||||
$this->assertArrayHasKey('isDegraded', $json['list'][0]); | $this->assertArrayHasKey('isDegraded', $json['list'][0]); | ||||
$this->assertArrayHasKey('isAccountDegraded', $json['list'][0]); | $this->assertArrayHasKey('isAccountDegraded', $json['list'][0]); | ||||
$this->assertArrayHasKey('isSuspended', $json['list'][0]); | $this->assertArrayHasKey('isSuspended', $json['list'][0]); | ||||
$this->assertArrayHasKey('isActive', $json['list'][0]); | $this->assertArrayHasKey('isActive', $json['list'][0]); | ||||
$this->assertArrayHasKey('isReady', $json['list'][0]); | |||||
if (\config('app.with_ldap')) { | |||||
$this->assertArrayHasKey('isLdapReady', $json['list'][0]); | $this->assertArrayHasKey('isLdapReady', $json['list'][0]); | ||||
} | |||||
if (\config('app.with_imap')) { | |||||
$this->assertArrayHasKey('isImapReady', $json['list'][0]); | $this->assertArrayHasKey('isImapReady', $json['list'][0]); | ||||
} | |||||
$response = $this->actingAs($ned)->get("/api/v4/users"); | $response = $this->actingAs($ned)->get("/api/v4/users"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(false, $json['hasMore']); | $this->assertSame(false, $json['hasMore']); | ||||
$this->assertSame(4, $json['count']); | $this->assertSame(4, $json['count']); | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | public function testShow(): void | ||||
$this->assertSame([], $json['skus']); | $this->assertSame([], $json['skus']); | ||||
$this->assertSame([], $json['aliases']); | $this->assertSame([], $json['aliases']); | ||||
// Values below are tested by Unit tests | // Values below are tested by Unit tests | ||||
$this->assertArrayHasKey('isDeleted', $json); | $this->assertArrayHasKey('isDeleted', $json); | ||||
$this->assertArrayHasKey('isDegraded', $json); | $this->assertArrayHasKey('isDegraded', $json); | ||||
$this->assertArrayHasKey('isAccountDegraded', $json); | $this->assertArrayHasKey('isAccountDegraded', $json); | ||||
$this->assertArrayHasKey('isSuspended', $json); | $this->assertArrayHasKey('isSuspended', $json); | ||||
$this->assertArrayHasKey('isActive', $json); | $this->assertArrayHasKey('isActive', $json); | ||||
$this->assertArrayHasKey('isReady', $json); | |||||
if (\config('app.with_ldap')) { | |||||
$this->assertArrayHasKey('isLdapReady', $json); | $this->assertArrayHasKey('isLdapReady', $json); | ||||
} | |||||
if (\config('app.with_imap')) { | |||||
$this->assertArrayHasKey('isImapReady', $json); | $this->assertArrayHasKey('isImapReady', $json); | ||||
} | |||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$ned = $this->getTestUser('ned@kolab.org'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
// Test unauthorized access to a profile of other user | // Test unauthorized access to a profile of other user | ||||
$response = $this->actingAs($jack)->get("/api/v4/users/{$userA->id}"); | $response = $this->actingAs($jack)->get("/api/v4/users/{$userA->id}"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | public function testStatus(): void | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
// Test unauthorized access | // Test unauthorized access | ||||
$response = $this->actingAs($jack)->get("/api/v4/users/{$john->id}/status"); | $response = $this->actingAs($jack)->get("/api/v4/users/{$john->id}/status"); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
if ($john->isImapReady()) { | $john->status &= ~User::STATUS_IMAP_READY; | ||||
$john->status ^= User::STATUS_IMAP_READY; | $john->status &= ~User::STATUS_LDAP_READY; | ||||
$john->save(); | $john->save(); | ||||
} | |||||
// Get user status | // Get user status | ||||
$response = $this->actingAs($john)->get("/api/v4/users/{$john->id}/status"); | $response = $this->actingAs($john)->get("/api/v4/users/{$john->id}/status"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertFalse($json['isImapReady']); | |||||
$this->assertFalse($json['isReady']); | $this->assertFalse($json['isReady']); | ||||
if (\config('app.with_ldap')) { | |||||
$this->assertFalse($json['isLdapReady']); | |||||
} else { | |||||
$this->assertArrayNotHasKey('isLdapReady', $json); | |||||
} | |||||
if (\config('app.with_imap')) { | if (\config('app.with_imap')) { | ||||
$this->assertCount(6, $json['process']); | $this->assertFalse($json['isImapReady']); | ||||
$this->assertSame('user-imap-ready', $json['process'][2]['label']); | $this->assertSame('user-imap-ready', $json['process'][2]['label']); | ||||
$this->assertSame(false, $json['process'][2]['state']); | $this->assertFalse($json['process'][2]['state']); | ||||
} else { | } else { | ||||
$this->assertCount(7, $json['process']); | $this->assertArrayNotHasKey('isImapReady', $json); | ||||
} | } | ||||
$this->assertTrue(empty($json['status'])); | $this->assertTrue(empty($json['status'])); | ||||
$this->assertTrue(empty($json['message'])); | $this->assertTrue(empty($json['message'])); | ||||
// Make sure the domain is confirmed (other test might unset that status) | // Make sure the domain is confirmed (other test might unset that status) | ||||
$domain = $this->getTestDomain('kolab.org'); | $domain = $this->getTestDomain('kolab.org'); | ||||
$domain->status |= Domain::STATUS_CONFIRMED; | $domain->status |= Domain::STATUS_CONFIRMED; | ||||
$domain->save(); | $domain->save(); | ||||
// Now "reboot" the process | // Now "reboot" the process | ||||
Queue::fake(); | Queue::fake(); | ||||
$response = $this->actingAs($john)->get("/api/v4/users/{$john->id}/status?refresh=1"); | $response = $this->actingAs($john)->get("/api/v4/users/{$john->id}/status?refresh=1"); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertFalse($json['isImapReady']); | $this->assertFalse($json['isImapReady']); | ||||
$this->assertFalse($json['isLdapReady']); | |||||
$this->assertFalse($json['isReady']); | $this->assertFalse($json['isReady']); | ||||
if (\config('app.with_imap')) { | if (\config('app.with_imap')) { | ||||
$this->assertCount(7, $json['process']); | |||||
$this->assertSame('user-imap-ready', $json['process'][2]['label']); | $this->assertSame('user-imap-ready', $json['process'][2]['label']); | ||||
$this->assertSame(false, $json['process'][2]['state']); | $this->assertSame(false, $json['process'][2]['state']); | ||||
} else { | |||||
$this->assertCount(6, $json['process']); | |||||
} | } | ||||
$this->assertSame('success', $json['status']); | $this->assertSame('success', $json['status']); | ||||
$this->assertSame('Setup process has been pushed. Please wait.', $json['message']); | $this->assertSame('Setup process has been pushed. Please wait.', $json['message']); | ||||
Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | Queue::assertPushed(\App\Jobs\User\CreateJob::class, 1); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 1,132 Lines • Show Last 20 Lines |