CaiWuXiTong/tests/Feature/Business/SupplierPayablePagesTest.php
renshen 433c8ab762 修复供应商赔偿明细数据来源 (#11)
接手 sumu 本地任务,复用既有只读 Repository 契约,将赔偿明细切换到 dbo.fys_supplierPaymentSummary,并按附件保留五列表头。
2026-08-06 16:26:51 +08:00

185 lines
6.7 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Modules\EcommerceFinance\Services\JianSunQueryCache;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Tests\Feature\FeatureTestCase;
class SupplierPayablePagesTest extends FeatureTestCase
{
protected function grantAdminPermission(): void
{
$this->user->attachPermission(
Permission::where('name', 'read-admin-panel')->firstOrFail()
);
}
public function testDeliveryUnpricedPageUsesItsOwnTwentyColumnTable()
{
$this->grantAdminPermission();
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'supplier-payables',
'page' => 'delivery-unpriced',
]));
$response
->assertOk()
->assertSee('id="delivery-unpriced-app"', false)
->assertSee('来源单号')
->assertSee('单据编号(采购单号)')
->assertSee('负责人')
->assertSee('public/js/ecommerce-finance/delivery-unpriced.min.js', false)
->assertDontSee('class="business-blank-page"', false);
$this->assertSame(20, substr_count($response->getContent(), '<el-table-column'));
}
public function testReturnUnpricedPageUsesItsOwnTwentyColumnTable()
{
$this->grantAdminPermission();
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'supplier-payables',
'page' => 'return-unpriced',
]));
$response
->assertOk()
->assertSee('id="return-unpriced-app"', false)
->assertSee('明细供应商')
->assertSee('供应商条码')
->assertSee('对账人')
->assertSee('public/js/ecommerce-finance/return-unpriced.min.js', false)
->assertDontSee('class="business-blank-page"', false);
$this->assertSame(20, substr_count($response->getContent(), '<el-table-column'));
}
public function testBoardDeductionsPageUsesItsOwnSeventeenColumnTable()
{
$this->grantAdminPermission();
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'supplier-payables',
'page' => 'board-deductions',
]));
$response
->assertOk()
->assertSee('class="supplier-board-table"', false)
->assertSee('入库日期')
->assertSee('出库备注')
->assertSee('送货单号')
->assertDontSee('class="business-blank-page"', false);
preg_match_all('/<th(?:\s|>)/', $response->getContent(), $headers);
$this->assertCount(17, $headers[0]);
}
public function testSupplierPayablesReportPageUsesItsOwnThirtyFourColumnGroupedTable()
{
$this->grantAdminPermission();
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'supplier-payables',
'page' => 'supplier-payables-report',
]));
$response
->assertOk()
->assertSee('class="supplier-payables-report-table"', false)
->assertSee('已销账供应商')
->assertSee('本月采购金额')
->assertSee('<th class="group-addition">加</th>', false)
->assertSee('<th colspan="6" class="group-payment">单位:元</th>', false)
->assertSee('<th class="group-payment">供应商余额</th>', false)
->assertSee('最晚出账单时间(新执行标准)')
->assertDontSee('class="business-blank-page"', false);
preg_match_all('/<col(?:\s|>)/', $response->getContent(), $columns);
$this->assertCount(34, $columns[0]);
}
public function testCompensationPageUsesTheFiveColumnsFromTheReferenceSheet(): void
{
$this->grantAdminPermission();
$response = $this->loginAs()->get(route('business.pages.show', [
'section' => 'supplier-payables',
'page' => 'compensation-details',
]));
$response
->assertOk()
->assertSee('id="compensation-detail-app"', false)
->assertSee('赔付原因')
->assertSee('备注')
->assertSee('public/js/ecommerce-finance/compensation-details.min.js', false);
$this->assertSame(5, substr_count($response->getContent(), '<el-table-column'));
}
public function testDataBackedSupplierPayableListRoutesAreAvailableToWorkspaceAjaxRequests()
{
$this->grantAdminPermission();
$cache = \Mockery::mock(JianSunQueryCache::class);
$cache->shouldReceive('remember')->times(10)->andReturnUsing(
static fn (string $scope): array => [
'data' => [['scope' => $scope]],
'total' => 1,
],
);
$cache->shouldReceive('responseHeaders')->times(10)->andReturn([]);
$this->app->instance(JianSunQueryCache::class, $cache);
$routes = [
'workspace-data.supplier-payables.payment-reconciliation.index',
'workspace-data.supplier-payables.return-reconciliation.index',
'workspace-data.supplier-payables.invoice-deductions.index',
'workspace-data.supplier-payables.compensation-details.index',
'workspace-data.supplier-payables.advance-details.index',
'workspace-data.supplier-payables.delivery-unpriced.index',
'workspace-data.supplier-payables.return-unpriced.index',
'workspace-data.supplier-payables.sample-deductions.index',
'workspace-data.supplier-payables.other-adjustments.index',
'workspace-data.supplier-payables.dropshipping-express.index',
];
foreach ($routes as $routeName) {
$this->loginAs()
->withHeader('X-Requested-With', 'XMLHttpRequest')
->get(route($routeName))
->assertOk()
->assertJsonPath('total', 1);
}
}
public function testSupplierPayableDataRouteRejectsUsersWithoutTheMatchingSidebarPage(): void
{
$subject = 'user_' . $this->user->id;
setting()->set('system.sidebar_permissions', json_encode([
'configured' => [$subject],
'subjects' => [
$subject => ['supplier-payables/invoice-deductions'],
],
], JSON_UNESCAPED_UNICODE));
try {
$this->loginAs()
->withHeader('X-Requested-With', 'XMLHttpRequest')
->get(route('workspace-data.supplier-payables.payment-reconciliation.index'));
$this->fail('缺少页面权限的用户不应读取货款对账数据。');
} catch (HttpException $exception) {
$this->assertSame(403, $exception->getStatusCode());
}
}
}