CaiWuXiTong/tests/Feature/Business/CourierPayableSummaryPagesTest.php

109 lines
4.3 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\CourierPayableSummaryStore;
use App\Models\Auth\Permission;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Tests\Feature\FeatureTestCase;
class CourierPayableSummaryPagesTest extends FeatureTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail()
);
Storage::fake('uploads');
}
public function test_final_workspace_places_both_summary_pages_after_courier_payables_report(): void
{
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'courier-payables-final',
]));
$response->assertOk()->assertSeeInOrder([
route('business.pages.show', ['section' => 'courier-payables', 'page' => 'courier-payables-report']),
route('business.pages.show', ['section' => 'courier-payables', 'page' => 'freight-difference']),
route('business.pages.show', ['section' => 'courier-payables', 'page' => 'other-surcharge-summary']),
], false);
}
public function test_summary_pages_render_import_and_export_buttons(): void
{
foreach (CourierPayableSummaryStore::PAGES as $page => $title) {
$this->loginAs()->get(route('business.pages.show', [
'section' => 'courier-payables',
'page' => $page,
]))
->assertOk()
->assertSee("data-courier-payable-summary=\"{$page}\"", false)
->assertSeeText($title)
->assertSeeText('导入')
->assertSeeText('导出')
->assertSeeText('暂无数据,请先点击“导入”上传汇总表。');
}
}
public function test_import_replaces_the_page_snapshot_and_export_returns_all_rows(): void
{
$file = UploadedFile::fake()->createWithContent(
'运费差.csv',
"快递公司,结算月份,运费差,备注\n测试快递,2026-08,-18.50,复核\n第二快递,2026-08,20,=待确认\n",
);
$this->loginAs()->post(route('business.courier-payable-summaries.import', [
'summaryPage' => 'freight-difference',
]), ['import' => $file])
->assertRedirect(route('business.pages.show', [
'section' => 'courier-payables',
'page' => 'freight-difference',
]))
->assertSessionHas('success', '导入完成:2 条数据,4 个字段。');
Storage::disk('uploads')->assertExists(
app(CourierPayableSummaryStore::class)->path((int) $this->company->id, 'freight-difference')
);
$this->loginAs()->get(route('business.pages.show', [
'section' => 'courier-payables',
'page' => 'freight-difference',
]))
->assertOk()
->assertSeeText('导入完成:2 条数据,4 个字段。')
->assertSeeText('测试快递')
->assertSeeText('-18.50')
->assertSeeText('第二快递');
$response = $this->loginAs()->get(route('business.courier-payable-summaries.export', [
'summaryPage' => 'freight-difference',
]));
$content = $response->streamedContent();
$response->assertOk()->assertHeader('content-type', 'text/csv; charset=UTF-8');
$this->assertStringContainsString('快递公司,结算月份,运费差,备注', $content);
$this->assertStringContainsString('测试快递,2026-08,-18.50,复核', $content);
$this->assertStringContainsString("\t=待确认", $content);
}
public function test_summary_actions_require_the_matching_page_permission(): void
{
$this->withExceptionHandling();
$this->user->roles()->sync([
\App\Models\Auth\Role::where('name', 'admin')->firstOrFail()->id,
]);
setting()->set('system.sidebar_permissions', [
'configured' => ['user_' . $this->user->id],
'subjects' => ['user_' . $this->user->id => ['courier-payables/courier-information']],
]);
$this->loginAs()->get(route('business.courier-payable-summaries.export', [
'summaryPage' => 'freight-difference',
]))->assertForbidden();
}
}