Publication initiale de RelaisSMS : documentation et sources nettoyees

This commit is contained in:
2026-10-21 09:29:39 +02:00
commit ac186b03b1
158 changed files with 24818 additions and 0 deletions
+114
View File
@@ -0,0 +1,114 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Env;
use Illuminate\Support\Facades\Hash;
use RuntimeException;
use Tests\TestCase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
public function test_home_redirects_to_recipient_selection(): void
{
$this->get('/')
->assertRedirect('/recipients');
}
public function test_guests_are_redirected_to_login(): void
{
$this->get('/recipients')
->assertRedirect('/login');
}
public function test_login_page_is_available(): void
{
$this->get('/login')
->assertOk()
->assertSee('Connexion');
}
public function test_authenticated_user_can_access_recipient_selection(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->get('/recipients')
->assertOk()
->assertSee('Composer')
->assertSee('Pour');
}
public function test_user_can_log_in_and_log_out(): void
{
User::factory()->create([
'email' => 'admin@relais-sms.test',
'password' => 'relais-sms',
]);
$this->post('/login', [
'email' => 'admin@relais-sms.test',
'password' => 'relais-sms',
])->assertRedirect('/recipients');
$this->assertAuthenticated();
$this->post('/logout')
->assertRedirect('/login');
$this->assertGuest();
}
public function test_default_app_settings_are_seeded(): void
{
config(['relais_sms.default_settings.max_sms_per_campaign' => 100]);
$this->seed();
$this->assertDatabaseHas('app_settings', [
'key' => 'max_sms_per_campaign',
'value' => '100',
'type' => 'integer',
]);
}
public function test_production_seeding_rejects_default_admin_password(): void
{
$this->app['env'] = 'production';
$repository = Env::getRepository();
$originalPassword = $repository->get('RELAIS_SMS_ADMIN_PASSWORD');
$repository->set('RELAIS_SMS_ADMIN_PASSWORD', 'relais-sms');
try {
$this->expectException(RuntimeException::class);
(new DatabaseSeeder)->run();
} finally {
$originalPassword === null
? $repository->clear('RELAIS_SMS_ADMIN_PASSWORD')
: $repository->set('RELAIS_SMS_ADMIN_PASSWORD', $originalPassword);
}
}
public function test_production_seeding_accepts_a_personal_admin_password(): void
{
$this->app['env'] = 'production';
$repository = Env::getRepository();
$originalPassword = $repository->get('RELAIS_SMS_ADMIN_PASSWORD');
$repository->set('RELAIS_SMS_ADMIN_PASSWORD', 'test-only-personal-password');
try {
(new DatabaseSeeder)->run();
$user = User::query()->sole();
$this->assertTrue(Hash::check('test-only-personal-password', $user->password));
} finally {
$originalPassword === null
? $repository->clear('RELAIS_SMS_ADMIN_PASSWORD')
: $repository->set('RELAIS_SMS_ADMIN_PASSWORD', $originalPassword);
}
}
}