adrema/tests/Feature/Mailgateway/IndexTest.php

93 lines
2.9 KiB
PHP
Raw Normal View History

2023-06-01 15:02:35 +02:00
<?php
namespace Tests\Feature\Mailgateway;
use App\Mailgateway\Models\Mailgateway;
use App\Mailgateway\Types\LocalType;
2023-06-07 22:52:02 +02:00
use App\Mailgateway\Types\MailmanType;
2023-06-07 22:59:58 +02:00
use App\Mailman\Support\MailmanService;
2023-06-01 15:02:35 +02:00
use Illuminate\Foundation\Testing\DatabaseTransactions;
2023-06-07 22:59:58 +02:00
use Phake;
use Tests\RequestFactories\MailmanTypeRequest;
2023-06-01 15:02:35 +02:00
use Tests\TestCase;
class IndexTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
$this->login()->loginNami();
}
public function testItCanViewIndexPage(): void
{
$response = $this->get('/setting/mailgateway');
$response->assertOk();
}
2023-06-07 22:59:58 +02:00
public function testItDisplaysLocalGateways(): void
2023-06-01 15:02:35 +02:00
{
$this->withoutExceptionHandling();
2023-06-08 00:14:55 +02:00
$mailgateway = Mailgateway::factory()->type(LocalType::class, [])->name('Lore')->domain('example.com')->create();
2023-06-01 15:02:35 +02:00
$response = $this->get('/setting/mailgateway');
$this->assertInertiaHas('example.com', $response, 'data.data.0.domain');
$this->assertInertiaHas('Lore', $response, 'data.data.0.name');
$this->assertInertiaHas('Lokal', $response, 'data.data.0.type_human');
$this->assertInertiaHas(true, $response, 'data.data.0.works');
2023-06-08 00:14:55 +02:00
$this->assertInertiaHas($mailgateway->id, $response, 'data.data.0.id');
$this->assertInertiaHas(route('mailgateway.update', ['mailgateway' => $mailgateway->id]), $response, 'data.data.0.links.update');
2023-06-01 15:02:35 +02:00
}
2023-06-07 22:59:58 +02:00
public function testItDisplaysMailmanGateways(): void
{
$this->stubIo(MailmanService::class, function ($mock) {
Phake::when($mock)->setCredentials()->thenReturn($mock);
Phake::when($mock)->check()->thenReturn(true);
});
$this->withoutExceptionHandling();
Mailgateway::factory()->type(MailmanType::class, MailmanTypeRequest::new()->create())->create();
$this->get('/setting/mailgateway')->assertOk();
}
2023-06-01 15:02:35 +02:00
public function testItHasMeta(): void
{
$this->withoutExceptionHandling();
$response = $this->get('/setting/mailgateway');
2023-06-07 21:39:29 +02:00
$this->assertInertiaHas(route('mailgateway.store'), $response, 'data.meta.links.store');
$this->assertInertiaHas([
'id' => null,
'name' => '-- kein --',
], $response, 'data.meta.types.0');
2023-06-01 15:45:02 +02:00
$this->assertInertiaHas([
'id' => LocalType::class,
'name' => 'Lokal',
2023-06-07 21:39:29 +02:00
], $response, 'data.meta.types.1');
2023-06-07 22:52:02 +02:00
$this->assertInertiaHas([
'id' => MailmanType::class,
'fields' => [
[
'name' => 'url',
'is_required' => true,
],
],
], $response, 'data.meta.types.2');
2023-06-07 21:39:29 +02:00
$this->assertInertiaHas([
'domain' => '',
'name' => '',
'type' => [
'params' => [],
'cls' => null,
],
], $response, 'data.meta.default');
2023-06-01 15:02:35 +02:00
}
}