Posta configurabile dall'app, contatti dei proclamatori, conferma email
- Server di posta in Impostazioni (password cifrata, email di prova): se compilato prende il posto del .env; non si esporta e l'import XML non lo cancella. MAIL_SCHEME=tls nel .env.example non era valido per Laravel 11. - Proclamatori con email e telefono facoltativi, cifrati, nell'XML e cancellati dall'anonimizzazione; il numero apre WhatsApp. - Dopo l'assegnazione un riquadro in evidenza con il link del PDF, "Invia su WhatsApp" con il messaggio pronto e la scelta "inviato / non ancora", che resta finché non si sceglie. - Conferma dell'email obbligatoria per tutti gli utenti, anche esistenti: email in italiano, link valido senza login, nuova conferma a ogni cambio di indirizzo, "Reinvia conferma" in Utenti. Senza conferma restano raggiungibili profilo, cambio password e, per l'admin, il server di posta; comando utenti:conferma-email per l'emergenza. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
149
tests/Feature/PostaElettronicaTest.php
Normal file
149
tests/Feature/PostaElettronicaTest.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Livewire\Settings\PostaElettronica;
|
||||
use App\Livewire\Settings\XmlExchange;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use App\Services\ConfigurazionePosta;
|
||||
use Database\Seeders\RolesAndPermissionsSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Il server di posta si configura dall'applicazione e prende il posto del .env.
|
||||
*/
|
||||
class PostaElettronicaTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private User $admin;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->withoutVite();
|
||||
$this->seed(RolesAndPermissionsSeeder::class);
|
||||
Setting::firstOrCreate([], ['congregazione_nome' => 'Congregazione di prova']);
|
||||
|
||||
$this->admin = User::create(['name' => 'Admin', 'email' => 'admin@example.test', 'password' => 'password-di-prova']);
|
||||
$this->admin->assignRole('amministratore');
|
||||
}
|
||||
|
||||
private function salva(array $valori = []): void
|
||||
{
|
||||
$componente = Livewire::actingAs($this->admin)->test(PostaElettronica::class);
|
||||
foreach ($valori + [
|
||||
'host' => 'smtp.esempio.it',
|
||||
'porta' => '587',
|
||||
'cifratura' => ConfigurazionePosta::CIFRATURA_AUTOMATICA,
|
||||
'utente' => 'territori@esempio.it',
|
||||
'password' => 'segreta-123',
|
||||
'mittente' => 'territori@esempio.it',
|
||||
'nomeMittente' => 'Territori',
|
||||
] as $campo => $valore) {
|
||||
$componente->set($campo, $valore);
|
||||
}
|
||||
$componente->call('salva')->assertHasNoErrors();
|
||||
}
|
||||
|
||||
public function test_la_pagina_e_dell_amministratore(): void
|
||||
{
|
||||
$operatore = User::create(['name' => 'Op', 'email' => 'op@example.test', 'password' => 'password-di-prova']);
|
||||
$operatore->assignRole('operatore');
|
||||
|
||||
$this->actingAs($operatore)->get(route('posta.edit'))->assertForbidden();
|
||||
$this->flushSession(); // due utenti nella stessa sessione: AuthenticateSession
|
||||
$this->actingAs($this->admin)->get(route('posta.edit'))->assertOk();
|
||||
}
|
||||
|
||||
public function test_la_configurazione_salvata_prende_il_posto_del_env(): void
|
||||
{
|
||||
config(['mail.default' => 'log']);
|
||||
|
||||
$this->salva();
|
||||
app(ConfigurazionePosta::class)->applica();
|
||||
|
||||
$this->assertSame('smtp', config('mail.default'));
|
||||
$this->assertSame('smtp.esempio.it', config('mail.mailers.smtp.host'));
|
||||
$this->assertSame(587, config('mail.mailers.smtp.port'));
|
||||
$this->assertSame('smtp', config('mail.mailers.smtp.scheme'));
|
||||
$this->assertSame('segreta-123', config('mail.mailers.smtp.password'));
|
||||
$this->assertSame('territori@esempio.it', config('mail.from.address'));
|
||||
}
|
||||
|
||||
public function test_ssl_usa_smtps_e_la_porta_465(): void
|
||||
{
|
||||
$this->salva(['cifratura' => ConfigurazionePosta::CIFRATURA_SSL, 'porta' => '']);
|
||||
app(ConfigurazionePosta::class)->applica();
|
||||
|
||||
$this->assertSame('smtps', config('mail.mailers.smtp.scheme'));
|
||||
$this->assertSame(465, config('mail.mailers.smtp.port'));
|
||||
}
|
||||
|
||||
public function test_la_password_e_cifrata_e_non_torna_al_browser(): void
|
||||
{
|
||||
$this->salva();
|
||||
|
||||
$grezza = DB::table('settings')->value('mail_password');
|
||||
$this->assertNotSame('segreta-123', $grezza);
|
||||
$this->assertStringNotContainsString('segreta', $grezza);
|
||||
|
||||
Livewire::actingAs($this->admin)->test(PostaElettronica::class)
|
||||
->assertSet('password', '')
|
||||
->assertDontSee('segreta-123');
|
||||
}
|
||||
|
||||
public function test_lasciare_vuota_la_password_tiene_quella_salvata(): void
|
||||
{
|
||||
$this->salva();
|
||||
$this->salva(['password' => '', 'host' => 'smtp.altro.it']);
|
||||
|
||||
Setting::flushCache();
|
||||
$this->assertSame('segreta-123', Setting::instance()->mail_password);
|
||||
$this->assertSame('smtp.altro.it', Setting::instance()->mail_host);
|
||||
}
|
||||
|
||||
public function test_l_email_di_prova_parte(): void
|
||||
{
|
||||
Mail::fake();
|
||||
$this->salva();
|
||||
|
||||
Livewire::actingAs($this->admin)->test(PostaElettronica::class)
|
||||
->call('inviaProva')
|
||||
->assertDispatched('avviso', tipo: 'ok');
|
||||
}
|
||||
|
||||
public function test_l_export_xml_non_contiene_la_posta_e_l_import_non_la_cancella(): void
|
||||
{
|
||||
$this->salva();
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$xml = (new XmlExchange())->currentXmlBackup();
|
||||
$this->assertStringNotContainsString('smtp.esempio.it', $xml);
|
||||
$this->assertStringNotContainsString('mail_host', $xml);
|
||||
$this->assertStringNotContainsString('segreta', $xml);
|
||||
|
||||
$esito = (new XmlExchange())->importXmlFromContent($xml);
|
||||
$this->assertArrayNotHasKey('error', $esito);
|
||||
|
||||
Setting::flushCache();
|
||||
$this->assertSame('smtp.esempio.it', Setting::instance()->mail_host);
|
||||
$this->assertSame('segreta-123', Setting::instance()->mail_password);
|
||||
}
|
||||
|
||||
public function test_rimuovere_torna_al_env(): void
|
||||
{
|
||||
$this->salva();
|
||||
|
||||
Livewire::actingAs($this->admin)->test(PostaElettronica::class)->call('rimuovi');
|
||||
|
||||
Setting::flushCache();
|
||||
$this->assertNull(Setting::instance()->mail_host);
|
||||
$this->assertFalse(app(ConfigurazionePosta::class)->configurataNellApp());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user