39 lines
1.2 KiB
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(): void
|
|
{
|
|
$csvData = "name_de,name_en,icon,color,description_de,description_en,sort_order,is_active,event_types\nGlueck,Joy,smile,#FFD700,Gefuehl des Gluecks,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' => 'Glueck', 'en' => 'Joy']),
|
|
'icon' => 'smile',
|
|
'color' => '#FFD700',
|
|
'description' => json_encode(['de' => 'Gefuehl des Gluecks', 'en' => 'Feeling of joy']),
|
|
'sort_order' => 1,
|
|
'is_active' => 1,
|
|
]);
|
|
|
|
$emotion = Emotion::where('name->de', 'Glueck')->first();
|
|
$this->assertNotNull($emotion);
|
|
}
|
|
}
|