2023-04-20 21:59:55 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Users;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class UpdateUserTest extends TestCase
|
|
|
|
{
|
2023-08-30 11:13:38 -07:00
|
|
|
public function testUsersCanBeActivatedWithNumber()
|
2023-04-20 21:59:55 -07:00
|
|
|
{
|
2023-04-25 11:53:47 -07:00
|
|
|
$admin = User::factory()->superuser()->create();
|
2023-08-30 11:13:38 -07:00
|
|
|
$user = User::factory()->create(['activated' => 0]);
|
2023-04-20 21:59:55 -07:00
|
|
|
|
|
|
|
$this->actingAs($admin)
|
|
|
|
->put(route('users.update', $user), [
|
|
|
|
'first_name' => $user->first_name,
|
|
|
|
'username' => $user->username,
|
|
|
|
'activated' => 1,
|
|
|
|
]);
|
|
|
|
|
2023-08-30 09:42:53 -07:00
|
|
|
$this->assertEquals(1, $user->refresh()->activated);
|
2023-04-20 21:59:55 -07:00
|
|
|
}
|
|
|
|
|
2023-08-30 11:13:38 -07:00
|
|
|
public function testUsersCanBeActivatedWithBooleanTrue()
|
|
|
|
{
|
|
|
|
$admin = User::factory()->superuser()->create();
|
|
|
|
$user = User::factory()->create(['activated' => false]);
|
|
|
|
|
|
|
|
$this->actingAs($admin)
|
|
|
|
->put(route('users.update', $user), [
|
|
|
|
'first_name' => $user->first_name,
|
|
|
|
'username' => $user->username,
|
|
|
|
'activated' => true,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(1, $user->refresh()->activated);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUsersCanBeDeactivatedWithNumber()
|
|
|
|
{
|
|
|
|
$admin = User::factory()->superuser()->create();
|
|
|
|
$user = User::factory()->create(['activated' => true]);
|
|
|
|
|
|
|
|
$this->actingAs($admin)
|
|
|
|
->put(route('users.update', $user), [
|
|
|
|
'first_name' => $user->first_name,
|
|
|
|
'username' => $user->username,
|
|
|
|
'activated' => 0,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(0, $user->refresh()->activated);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testUsersCanBeDeactivatedWithBooleanFalse()
|
2023-04-20 21:59:55 -07:00
|
|
|
{
|
2023-04-25 11:53:47 -07:00
|
|
|
$admin = User::factory()->superuser()->create();
|
2023-04-20 21:59:55 -07:00
|
|
|
$user = User::factory()->create(['activated' => true]);
|
|
|
|
|
|
|
|
$this->actingAs($admin)
|
|
|
|
->put(route('users.update', $user), [
|
|
|
|
'first_name' => $user->first_name,
|
|
|
|
'username' => $user->username,
|
2023-08-30 11:13:38 -07:00
|
|
|
'activated' => false,
|
2023-04-20 21:59:55 -07:00
|
|
|
]);
|
|
|
|
|
2023-08-30 09:42:53 -07:00
|
|
|
$this->assertEquals(0, $user->refresh()->activated);
|
2023-04-20 21:59:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testUsersUpdatingThemselvesDoNotDeactivateTheirAccount()
|
|
|
|
{
|
2023-04-25 11:53:47 -07:00
|
|
|
$admin = User::factory()->superuser()->create(['activated' => true]);
|
2023-04-20 21:59:55 -07:00
|
|
|
|
|
|
|
$this->actingAs($admin)
|
|
|
|
->put(route('users.update', $admin), [
|
|
|
|
'first_name' => $admin->first_name,
|
|
|
|
'username' => $admin->username,
|
|
|
|
]);
|
|
|
|
|
2023-08-30 09:42:53 -07:00
|
|
|
$this->assertEquals(1, $admin->refresh()->activated);
|
2023-04-20 21:59:55 -07:00
|
|
|
}
|
|
|
|
}
|