Monatsspruch der ÖAB als Startseiten-Kachel für Inhaus (ab 0.12.0): automatischer Abruf von oeab.de, eigene Angaben je Monat, Admin-Seite, Packskript für das installierbare ZIP, Tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
100 lines
3.8 KiB
PHP
100 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Plugins\Monatsspruch;
|
|
|
|
use App\Models\User;
|
|
use App\Support\Settings;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Inhaus\Plugins\Monatsspruch\OeabParser;
|
|
use Inhaus\Plugins\Monatsspruch\Verses;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Läuft innerhalb einer Inhaus-Installation, in der das Plugin unter plugins/monatsspruch liegt:
|
|
* vendor-dev/bin/phpunit plugins/monatsspruch/tests
|
|
*/
|
|
class MonatsspruchTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private ?string $previousState = null;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Plugin für diesen Test aktivieren (Kunden-Plugins sind nach der Installation aus).
|
|
$file = storage_path('app/plugins.json');
|
|
$this->previousState = is_file($file) ? file_get_contents($file) : null;
|
|
$state = json_decode($this->previousState ?? '{}', true) ?: [];
|
|
$state['monatsspruch'] = ['enabled' => true];
|
|
file_put_contents($file, json_encode($state));
|
|
$this->refreshApplication();
|
|
$this->setUpTraits();
|
|
|
|
Carbon::setTestNow('2026-10-07 09:00');
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
$file = storage_path('app/plugins.json');
|
|
$this->previousState === null ? @unlink($file) : file_put_contents($file, $this->previousState);
|
|
Carbon::setTestNow();
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
private function fixture(): string
|
|
{
|
|
return (string) file_get_contents(__DIR__.'/fixtures/oeab-2026.html');
|
|
}
|
|
|
|
public function test_parser_reads_all_months_with_reference_and_translation(): void
|
|
{
|
|
$verses = OeabParser::parse($this->fixture());
|
|
|
|
$this->assertCount(12, $verses);
|
|
$this->assertSame('Galater 5,1', $verses[10]['reference']);
|
|
$this->assertSame('Lutherbibel 2017', $verses[10]['translation']);
|
|
$this->assertStringStartsWith('Zur Freiheit hat uns Christus befreit!', $verses[10]['text']);
|
|
$this->assertSame('Einheitsübersetzung 2016', $verses[1]['translation']);
|
|
}
|
|
|
|
public function test_verses_are_fetched_and_shown_as_dashboard_tile(): void
|
|
{
|
|
Http::fake(['www.oeab.de/monatssprueche/2026' => Http::response($this->fixture())]);
|
|
app(Verses::class)->refreshIfNeeded();
|
|
|
|
$this->actingAs(User::factory()->create())->get('/')->assertInertia(fn (Assert $page) => $page->where(
|
|
'widgets',
|
|
fn ($widgets) => ($tile = collect($widgets)->firstWhere('key', 'monatsspruch.current'))
|
|
&& $tile['component'] === 'core::Quote'
|
|
&& $tile['props']['title'] === 'Monatsspruch Oktober'
|
|
&& $tile['props']['source'] === 'Galater 5,1'
|
|
));
|
|
|
|
// Weiterer Aufruf innerhalb von 30 Tagen lädt nicht erneut.
|
|
app(Verses::class)->refreshIfNeeded();
|
|
Http::assertSentCount(1);
|
|
}
|
|
|
|
public function test_failures_keep_the_last_verse_and_overrides_win(): void
|
|
{
|
|
Http::fake(['*' => Http::response('<html>Wartung</html>')]);
|
|
$this->assertSame(0, app(Verses::class)->fetch(2026));
|
|
$this->assertNull(app(Verses::class)->current(), 'Ohne Spruch keine Kachel');
|
|
$this->assertStringContainsString('keine Monatssprüche', app(Settings::class)->get(Verses::STATUS)['error']);
|
|
|
|
app(Settings::class)->set(Verses::OVERRIDES, ['2026-10' => ['text' => 'Eigener Spruch', 'reference' => 'Psalm 1,1', 'translation' => null]]);
|
|
$this->assertSame('Eigener Spruch', app(Verses::class)->current()['text']);
|
|
$this->assertTrue(app(Verses::class)->current()['custom']);
|
|
}
|
|
|
|
public function test_admin_page(): void
|
|
{
|
|
$this->actingAs(User::factory()->admin()->create())->get('/admin/monatsspruch')->assertOk()->assertSee('Monatsspruch');
|
|
}
|
|
}
|