CaiWuXiTong/tests/Feature/Business/SongyuQuotePdfTest.php

48 lines
3.6 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\Models\Business\CourierQuoteVersion;
use App\Support\CourierQuotePdf;
use Tests\TestCase;
class SongyuQuotePdfTest extends TestCase
{
public function test_route_quote_keeps_delivery_and_pickup_terms_with_prices_on_one_page(): void
{
$values = [['常州松宇货运返货报价'], ['出发仓','出发省份','到达地','到达省份','吨价(元/吨)','方价(元/方)','来源','备注','派送费门槛(方)','门槛含等于','派送费(元/票)','提货费门槛(方)','提货费门槛含等于','提货费(元/票)']];
foreach (['江苏','河北','江西','湖北','山东','广东','广西','福建','浙江','安徽','河南'] as $province) {
$values[] = ['江苏常州','江苏',$province,$province,560,110,'报价单','价格含开票;运费月结。',10,'是',50];
}
$values[] = ['山东','山东','菏泽/河南兰考','山东',390,70,'报价单',null,10,'是',80];
$values[] = ['山东','山东','青岛/临沂','山东',500,110,'报价单',null,10,'是',80,5,'是',100];
$values[1] = [...$values[1], '执行日期', '截止日期'];
foreach ($values as $index => $row) {
if ($index < 2) continue;
$values[$index] = [...array_pad($row, 14, null), $row[0] === '山东' ? '2026-11-01' : '2026-08-01', null];
}
$values[] = ['山东','山东','山东/河南兰考','山东',390,70,'报价单',null,10,'是',50,null,null,null,'2026-08-01','2026-10-31'];
$values[] = ['山东','山东','青岛/临沂','山东',500,110,'报价单',null,10,'是',50,null,null,null,'2026-08-01','2026-10-31'];
$version = new CourierQuoteVersion([
'company_id'=>1,'version_code'=>'RL-005-TEST','carrier_name'=>'常州松宇货运','company_name'=>'常州松宇货运',
'quote_type'=>'返货线路报价','effective_date'=>'2026-08-01','status'=>'approved',
'billing_rules'=>'常州线路自2026-08-01执行;山东两条新报价自2026-11-01执行,之前沿用表内截止2026-10-31的原报价。按吨价与方价分别计算并四舍五入到分,取较大值;体积10方及以下(含10方),江苏常州出发每票送货费50元,山东新报价每票送货费80元;山东到青岛/临沂体积5方及以下(含5方)每票另加提货费100元,与送货费叠加;山东新报价390元/吨、70元/方线路仅限菏泽/河南兰考,不覆盖其他山东地区;价格含开票;运费月结。',
'values_json'=>json_encode($values,JSON_UNESCAPED_UNICODE|JSON_THROW_ON_ERROR),'formulas_json'=>'[]',
]);
$version->setRelation('change',null);
$frames = [];
$pdf = app('dompdf.wrapper');
$pdf->getDomPDF()->setCallbacks([['event'=>'end_frame','f'=>static function ($frame) use (&$frames): void {
if ($frame instanceof \Dompdf\FrameDecorator\Text) $frames[] = $frame->get_text();
}]]);
app()->instance('dompdf.wrapper',$pdf);
$result = app(CourierQuotePdf::class)->renderForSigning($version,'2026-12-02','测试甲方','常州松宇货运有限公司');
$text = implode('',$frames);
foreach (['菏泽/河南兰考','青岛/临沂','80.00','100.00','5 方及以下','价格含开票;运费月结。','2026-11-01','2026-10-31','2026-08-01'] as $expected) {
$this->assertStringContainsString($expected,$text);
}
$this->assertSame(2,$pdf->getDomPDF()->getCanvas()->get_page_count());
$this->assertSame(2,(int)$result['signing_positions'][0]['positionPage']);
}
}