| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- declare(strict_types=1);
- namespace Tests\Unit\Services\Export;
- use App\Models\CommonCatalogItem;
- use App\Models\File;
- use App\Models\User;
- use App\Services\Export\ExportCommonCatalogService;
- use Illuminate\Foundation\Testing\RefreshDatabase;
- use Illuminate\Http\UploadedFile;
- use Illuminate\Support\Facades\Storage;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use Tests\TestCase;
- class ExportCommonCatalogServiceTest extends TestCase
- {
- use RefreshDatabase;
- protected bool $seed = true;
- public function test_export_uses_approved_columns_and_preserves_article_as_string(): void
- {
- Storage::fake('public');
- $user = User::factory()->create();
- $uploadedImage = UploadedFile::fake()->image('0254.png', 100, 100);
- $imagePath = 'common_catalog/items/1/image/0254.png';
- Storage::disk('public')->put($imagePath, $uploadedImage->getContent());
- $image = File::query()->create([
- 'user_id' => $user->id,
- 'original_name' => '0254.png',
- 'mime_type' => 'image/png',
- 'path' => $imagePath,
- 'link' => '/storage/'.$imagePath,
- ]);
- CommonCatalogItem::factory()->create([
- 'article' => '0254',
- 'calculator_name' => 'Оборудование для благоустройства',
- 'image_file_id' => $image->id,
- ]);
- (new ExportCommonCatalogService)->handle($user->id);
- $file = File::query()->where('user_id', $user->id)->latest('id')->firstOrFail();
- Storage::disk('public')->assertExists($file->path);
- $sheet = IOFactory::load(Storage::disk('public')->path($file->path))->getActiveSheet();
- $this->assertSame(ExportCommonCatalogService::HEADERS, $sheet->rangeToArray('A1:S1')[0]);
- $this->assertSame('0254', $sheet->getCell('C2')->getValue());
- $this->assertSame('Оборудование для благоустройства', $sheet->getCell('D2')->getValue());
- $this->assertCount(1, $sheet->getDrawingCollection());
- }
- }
|