CaiWuXiTong/tests/Feature/Business/ActualTaxPageTest.php
2026-11-19 17:28:52 +08:00

117 lines
4.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature\Business;
use App\Business\ActualTax\ActualTaxWorkbookImporter;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Tests\Feature\FeatureTestCase;
class ActualTaxPageTest extends FeatureTestCase
{
public function testPageShowsActualTaxRowsFiltersAndSummary(): void
{
$connection = DB::connection('business_mirror');
$connection->table(ActualTaxWorkbookImporter::TABLE)->insert([
$this->record([
'source_key' => hash('sha256', '202610|常规|常州示例家居有限公司'),
'period' => '202610',
'company_name' => '常州示例家居有限公司',
'accounting_company' => '示例财税',
'contact_person' => '蕙兰',
'total_revenue' => 1000000,
'total_tax_paid' => 18000,
'tax_burden_rate' => 0.018,
'tax_declaration_status' => '是',
'notes' => '示例备注',
]),
$this->record([
'source_key' => hash('sha256', '202609|常规|另一家示例有限公司'),
'period' => '202609',
'company_name' => '另一家示例有限公司',
'accounting_company' => '其他财税',
'contact_person' => '林冲',
'total_revenue' => 500000,
'total_tax_paid' => 5000,
'tax_burden_rate' => 0.01,
]),
]);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'company-management',
'page' => 'actual-tax',
]))
->assertOk()
->assertSeeText('实际税金表')
->assertSeeText('2026年代办对接表-税务')
->assertSeeText('常州示例家居有限公司')
->assertSeeText('另一家示例有限公司')
->assertSeeText('1,500,000.00')
->assertSeeText('23,000.00')
->assertSeeText('1.53%')
->assertSeeText('导入并更新')
->assertSeeText('综合税负')
->assertSee('data-tone="success"', false);
}
public function testImportReplacesMirrorAndPreservesTextAndRatioValues(): void
{
$path = tempnam(sys_get_temp_dir(), 'actual-tax-');
$this->assertNotFalse($path);
file_put_contents($path, implode("\n", [
'period,type,company_name,real_revenue_incl_tax,total_revenue,total_tax_paid,tax_burden_rate,notes',
'202610,常规,常州导入示例有限公司,-2146826246,"1,000,000.00",50000,5.00%,导入备注',
]));
try {
$file = new UploadedFile($path, 'actual-tax.csv', 'text/csv', null, true);
$this->loginAs()
->post(route('business.pages.import', [
'section' => 'company-management',
'page' => 'actual-tax',
]), ['import' => $file])
->assertRedirect();
$this->assertSessionHas('success', '实际税金表导入完成:1 条,跳过 0 条空行。');
$row = DB::connection('business_mirror')
->table(ActualTaxWorkbookImporter::TABLE)
->where('company_name', '常州导入示例有限公司')
->first();
$this->assertNotNull($row);
$this->assertEqualsWithDelta(1000000, (float) $row->total_revenue, 0.001);
$this->assertEqualsWithDelta(50000, (float) $row->total_tax_paid, 0.001);
$this->assertEqualsWithDelta(0.05, (float) $row->tax_burden_rate, 0.00000001);
$this->assertNull($row->real_revenue_incl_tax);
$this->assertSame('导入备注', $row->notes);
$this->assertSame(1, DB::connection('business_mirror')->table(ActualTaxWorkbookImporter::TABLE)->count());
} finally {
@unlink($path);
}
}
/**
* @param array<string,mixed> $overrides
* @return array<string,mixed>
*/
private function record(array $overrides): array
{
return array_merge([
'source_row' => 4,
'sort_order' => 1,
'period' => '202610',
'type' => '常规',
'region' => '本地',
'taxpayer_type' => '一般纳税人',
'company_name' => '示例公司',
'source_file' => 'actual-tax.csv',
'imported_at' => now(),
'created_at' => now(),
'updated_at' => now(),
], $overrides);
}
}