create(['role' => Role::ADMIN]); Setting::set(Setting::KEY_TECHNICAL_DESCRIPTION_PRICE_FIELD, 'project_price'); $item = CommonCatalogItem::factory()->create([ 'article' => 'S1102', 'print_name' => 'Игровой комплекс Сибирь', 'product_group' => 'Игровое оборудование', 'characteristics' => 'Высота 2 метра', 'technical_description_short' => 'Краткое описание', 'project_price' => 1234.50, 'retail_price' => 9999, ]); $file = app(ExportTechnicalDescriptionsService::class)->handle( [$item->id], TechnicalDescriptionService::MODE_CHARACTERISTICS_SHORT, false, $user->id, ); Storage::disk('local')->assertExists($file->path); $xml = $this->documentXml(Storage::disk('local')->path($file->path)); $this->assertStringContainsString('1 234.50', $xml); $this->assertStringNotContainsString('9 999.00', $xml); $this->assertStringContainsString('Краткое описание', $xml); $this->assertTrue($file->is_generated); } public function test_separate_export_creates_zip_with_docx_per_item(): void { Storage::fake('local'); Storage::fake('public'); $user = User::factory()->create(['role' => Role::ADMIN]); $items = CommonCatalogItem::factory()->count(2)->create(); $file = app(ExportTechnicalDescriptionsService::class)->handle( $items->modelKeys(), TechnicalDescriptionService::MODE_FULL, true, $user->id, ); Storage::disk('local')->assertExists($file->path); $zip = new ZipArchive; $this->assertTrue($zip->open(Storage::disk('local')->path($file->path)) === true); $this->assertSame(2, $zip->numFiles); $this->assertStringEndsWith('.docx', (string) $zip->getNameIndex(0)); $zip->close(); } private function documentXml(string $path): string { $zip = new ZipArchive; $this->assertTrue($zip->open($path) === true); $xml = $zip->getFromName('word/document.xml'); $zip->close(); $this->assertIsString($xml); return $xml; } }