Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/Admin/UsersTest.php
<?php | <?php | ||||
namespace Tests\Feature\Controller\Admin; | namespace Tests\Feature\Controller\Admin; | ||||
use Illuminate\Support\Facades\Queue; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class UsersTest extends TestCase | class UsersTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
self::useAdminUrl(); | self::useAdminUrl(); | ||||
$this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$jack->setSetting('external_email', null); | $jack->setSetting('external_email', null); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | |||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$jack->setSetting('external_email', null); | $jack->setSetting('external_email', null); | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test users searching (/api/v4/users) | * Test users searching (/api/v4/users) | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | public function testIndex(): void | ||||
$json = $response->json(); | $json = $response->json(); | ||||
$this->assertSame(0, $json['count']); | $this->assertSame(0, $json['count']); | ||||
$this->assertCount(0, $json['list']); | $this->assertCount(0, $json['list']); | ||||
} | } | ||||
/** | /** | ||||
* Test user suspending (POST /api/v4/users/<user-id>/suspend) | |||||
*/ | |||||
public function testSuspend(): void | |||||
{ | |||||
Queue::fake(); // disable jobs | |||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
// Test unauthorized access to admin API | |||||
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/suspend", []); | |||||
$response->assertStatus(403); | |||||
$this->assertFalse($user->isSuspended()); | |||||
// Test suspending the user | |||||
$response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/suspend", []); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame("User suspended successfully.", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
$this->assertTrue($user->fresh()->isSuspended()); | |||||
} | |||||
/** | |||||
* Test user un-suspending (POST /api/v4/users/<user-id>/unsuspend) | |||||
*/ | |||||
public function testUnsuspend(): void | |||||
{ | |||||
Queue::fake(); // disable jobs | |||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | |||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | |||||
// Test unauthorized access to admin API | |||||
$response = $this->actingAs($user)->post("/api/v4/users/{$user->id}/unsuspend", []); | |||||
$response->assertStatus(403); | |||||
$this->assertFalse($user->isSuspended()); | |||||
$user->suspend(); | |||||
$this->assertTrue($user->isSuspended()); | |||||
// Test suspending the user | |||||
$response = $this->actingAs($admin)->post("/api/v4/users/{$user->id}/unsuspend", []); | |||||
$response->assertStatus(200); | |||||
$json = $response->json(); | |||||
$this->assertSame('success', $json['status']); | |||||
$this->assertSame("User unsuspended successfully.", $json['message']); | |||||
$this->assertCount(2, $json); | |||||
$this->assertFalse($user->fresh()->isSuspended()); | |||||
} | |||||
/** | |||||
* 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 | ||||
{ | { | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$admin = $this->getTestUser('jeroen@jeroen.jeroen'); | $admin = $this->getTestUser('jeroen@jeroen.jeroen'); | ||||
// Test unauthorized access to admin API | // Test unauthorized access to admin API | ||||
$response = $this->actingAs($user)->get("/api/v4/users/{$user->id}", []); | $response = $this->actingAs($user)->put("/api/v4/users/{$user->id}", []); | ||||
$response->assertStatus(403); | $response->assertStatus(403); | ||||
// Test updatig the user data (empty data) | // Test updatig the user data (empty data) | ||||
$response = $this->actingAs($admin)->put("/api/v4/users/{$user->id}", []); | $response = $this->actingAs($admin)->put("/api/v4/users/{$user->id}", []); | ||||
$response->assertStatus(200); | $response->assertStatus(200); | ||||
$json = $response->json(); | $json = $response->json(); | ||||
Show All 28 Lines |