| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?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,
- 'dimension_length' => 'от 180',
- 'calculator_enabled' => true,
- 'builders_price' => 1418500,
- 'recommended_plus_10_price' => 1888023.50,
- ]);
- (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:AD1')[0]);
- $this->assertEquals(ExportCommonCatalogService::SUBHEADERS, $sheet->rangeToArray('A2:AD2')[0]);
- $this->assertSame('0254', $sheet->getCell('A3')->getValue());
- $this->assertSame('Оборудование для благоустройства', $sheet->getCell('B3')->getValue());
- $this->assertSame('от 180', $sheet->getCell('D3')->getValue());
- $this->assertSame('да', $sheet->getCell('V3')->getValue());
- $this->assertSame(1418500.0, $sheet->getCell('W3')->getValue());
- $this->assertSame(1888023.5, $sheet->getCell('AD3')->getValue());
- $this->assertCount(1, $sheet->getDrawingCollection());
- }
- }
|