导出
This commit is contained in:
@@ -14,8 +14,8 @@ use App\Models\UserModel;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
/**
|
||||
* 采购单导出:xlsx Content-Type / 蔬果分类过滤 / PDF / format 非法拒绝 / 权限拦截 /
|
||||
* 中文文件名 RFC 5987 编码
|
||||
* 采购单导出(仅 Excel 表格):xlsx Content-Type / 蔬果分类过滤 / type 非法拒绝 /
|
||||
* 权限拦截 / 中文文件名 RFC 5987 编码
|
||||
*/
|
||||
class ExportTest extends ProcurementTestCase
|
||||
{
|
||||
@@ -56,7 +56,7 @@ class ExportTest extends ProcurementTestCase
|
||||
$purchase = $this->buildPurchaseWithItems();
|
||||
$this->actingAsSysUser();
|
||||
|
||||
$response = $this->get("/purchase/order/{$purchase->id}/export?type=all&format=xlsx");
|
||||
$response = $this->get("/purchase/order/{$purchase->id}/export");
|
||||
$response->assertOk();
|
||||
|
||||
$this->assertStringContainsString(
|
||||
@@ -78,7 +78,7 @@ class ExportTest extends ProcurementTestCase
|
||||
$this->actingAsSysUser();
|
||||
|
||||
Excel::fake();
|
||||
$this->get("/purchase/order/{$purchase->id}/export?type=category&format=xlsx")->assertOk();
|
||||
$this->get("/purchase/order/{$purchase->id}/export?type=category")->assertOk();
|
||||
|
||||
Excel::assertDownloaded(
|
||||
$purchase->purchase_no . '_采购单.xlsx',
|
||||
@@ -90,25 +90,22 @@ class ExportTest extends ProcurementTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/** PDF 导出:application/pdf */
|
||||
public function test_export_pdf(): void
|
||||
/** type 参数非法 → 拒绝 */
|
||||
public function test_export_invalid_type_rejected(): void
|
||||
{
|
||||
$purchase = $this->buildPurchaseWithItems();
|
||||
$this->actingAsSysUser();
|
||||
|
||||
$response = $this->get("/purchase/order/{$purchase->id}/export?format=pdf");
|
||||
$response->assertOk();
|
||||
$this->assertStringContainsString('application/pdf', (string) $response->headers->get('Content-Type'));
|
||||
$this->assertStringStartsWith('%PDF', (string) $response->getContent());
|
||||
$this->get("/purchase/order/{$purchase->id}/export?type=doc")
|
||||
->assertJsonPath('success', false);
|
||||
}
|
||||
|
||||
/** format 参数非法 → 拒绝 */
|
||||
public function test_export_invalid_format_rejected(): void
|
||||
/** 采购单不存在 → 拒绝 */
|
||||
public function test_export_missing_purchase_rejected(): void
|
||||
{
|
||||
$purchase = $this->buildPurchaseWithItems();
|
||||
$this->actingAsSysUser();
|
||||
|
||||
$this->get("/purchase/order/{$purchase->id}/export?format=doc")
|
||||
$this->get('/purchase/order/99999/export')
|
||||
->assertJsonPath('success', false);
|
||||
}
|
||||
|
||||
@@ -119,7 +116,7 @@ class ExportTest extends ProcurementTestCase
|
||||
// 仅持有查询权限的用户
|
||||
$this->actingAsSysUser(['purchase.order.query']);
|
||||
|
||||
$response = $this->get("/purchase/order/{$purchase->id}/export?format=xlsx");
|
||||
$response = $this->get("/purchase/order/{$purchase->id}/export");
|
||||
$this->assertFalse($response->json('success'), '缺少权限点应被拦截');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user