82 lines
2.9 KiB
PHP
82 lines
2.9 KiB
PHP
<?php // tests/Feature/Mail/GuestMailConfigTest.php
|
|
|
|
use App\Models\Instance;
|
|
use App\Models\Mailbox;
|
|
use App\Services\Mail\GuestMailConfig;
|
|
use App\Support\Settings;
|
|
|
|
function versandbereit(): void
|
|
{
|
|
Settings::set('mail.host', 'mail.clupilot.cloud');
|
|
Settings::set('mail.port', 587);
|
|
Settings::set('mail.encryption', 'tls');
|
|
|
|
Mailbox::factory()->create([
|
|
'key' => 'instance-relay',
|
|
'address' => 'noreply@clupilot.cloud',
|
|
'username' => 'noreply@clupilot.cloud',
|
|
'password' => 'geheim',
|
|
'active' => true,
|
|
'authenticates' => true,
|
|
]);
|
|
}
|
|
|
|
it('baut die Werte aus Server UND Postfach zusammen', function () {
|
|
versandbereit();
|
|
// Instance kennt kein 'name'-Feld (siehe Migration) — GuestMailConfig
|
|
// liest ohnehin nur das Postfach, nicht die Instanz selbst.
|
|
$instance = Instance::factory()->create();
|
|
|
|
$config = GuestMailConfig::for($instance);
|
|
|
|
expect($config->available())->toBeTrue()
|
|
->and($config->values())->toMatchArray([
|
|
'mail_smtpmode' => 'smtp',
|
|
'mail_smtphost' => 'mail.clupilot.cloud',
|
|
'mail_smtpport' => '587',
|
|
'mail_smtpsecure' => 'tls',
|
|
'mail_smtpauth' => 'true',
|
|
'mail_smtpname' => 'noreply@clupilot.cloud',
|
|
'mail_from_address' => 'noreply',
|
|
'mail_domain' => 'clupilot.cloud',
|
|
])
|
|
->and($config->password())->toBe('geheim');
|
|
});
|
|
|
|
it('traegt das Passwort NICHT unter values()', function () {
|
|
// values() wandert in Befehle. Das Passwort geht einen eigenen Weg, damit
|
|
// niemand es versehentlich mit den uebrigen Werten mitschleift.
|
|
versandbereit();
|
|
|
|
expect(GuestMailConfig::for(Instance::factory()->create())->values())
|
|
->not->toHaveKey('mail_smtppassword');
|
|
});
|
|
|
|
it('sagt ohne Mailserver, dass nichts geschrieben werden darf', function () {
|
|
Mailbox::factory()->create(['key' => 'instance-relay', 'address' => 'noreply@clupilot.cloud', 'password' => 'geheim', 'active' => true]);
|
|
Settings::set('mail.host', '');
|
|
|
|
$config = GuestMailConfig::for(Instance::factory()->create());
|
|
|
|
expect($config->available())->toBeFalse()
|
|
->and($config->problem())->toBe('no_server');
|
|
});
|
|
|
|
it('sagt ohne Absenderpostfach, dass nichts geschrieben werden darf', function () {
|
|
Settings::set('mail.host', 'mail.clupilot.cloud');
|
|
Settings::set('mail.port', 587);
|
|
|
|
$config = GuestMailConfig::for(Instance::factory()->create());
|
|
|
|
expect($config->available())->toBeFalse()
|
|
->and($config->problem())->toBe('no_mailbox');
|
|
});
|
|
|
|
it('weist ein Postfach ohne Zugangsdaten ab', function () {
|
|
Settings::set('mail.host', 'mail.clupilot.cloud');
|
|
Settings::set('mail.port', 587);
|
|
Mailbox::factory()->create(['key' => 'instance-relay', 'address' => 'noreply@clupilot.cloud', 'password' => null, 'active' => true, 'authenticates' => true]);
|
|
|
|
expect(GuestMailConfig::for(Instance::factory()->create())->problem())->toBe('no_mailbox');
|
|
});
|