Files
fotospiel-app/tests/Feature/EmotionResourceTest.php

39 lines
1.2 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Emotion;
use App\Services\EmotionImportService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class EmotionResourceTest extends TestCase
{
use RefreshDatabase;
public function test_import_emotions_csv()
{
$csvData = "name_de,name_en,icon,color,description_de,description_en,sort_order,is_active,event_types\nGlück,Joy,😊,#FFD700,Gefühl des Glücks,Feeling of joy,1,1,wedding|birthday";
$tempFile = tempnam(sys_get_temp_dir(), 'emotions_');
file_put_contents($tempFile, $csvData);
[$success, $failed] = app(EmotionImportService::class)->import($tempFile);
$this->assertSame(1, $success);
$this->assertSame(0, $failed);
$this->assertDatabaseHas('emotions', [
'name' => json_encode(['de' => 'Glück', 'en' => 'Joy']),
'icon' => '😊',
'color' => '#FFD700',
'description' => json_encode(['de' => 'Gefühl des Glücks', 'en' => 'Feeling of joy']),
'sort_order' => 1,
'is_active' => 1,
]);
$emotion = Emotion::where('name->de', 'Glück')->first();
$this->assertNotNull($emotion);
}
}