adrema/tests/Feature/Prevention/SettingTest.php

41 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature\Prevention;
use App\Prevention\PreventionSettings;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\RequestFactories\EditorRequestFactory;
use Tests\TestCase;
class SettingTest extends TestCase
{
use DatabaseTransactions;
public function testItOpensSettingsPage(): void
{
$this->login()->loginNami();
$text = EditorRequestFactory::new()->text(50, 'lorem ipsum')->toData();
app(PreventionSettings::class)->fill(['formmail' => $text])->save();
$this->get(route('setting.view', ['settingGroup' => 'prevention']))
->assertOk()
->assertComponent('setting/Prevention')
->assertInertiaPath('data.formmail.blocks.0.data.text', 'lorem ipsum')
->assertInertiaPath('store_url', route('setting.store', ['settingGroup' => 'prevention']));
}
public function testItStoresSettings(): void
{
$this->login()->loginNami();
$route = route('setting.store', ['settingGroup' => 'prevention']);
$this
->from($route)
->post($route, ['formmail' => EditorRequestFactory::new()->text(50, 'new lorem')->create()])
->assertRedirect($route);
$this->assertTrue(app(PreventionSettings::class)->formmail->hasAll(['new lorem']));
}
}