98 lines
3.6 KiB
PHP
98 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use App\Models\Auth\Permission;
|
|
use Illuminate\Support\Facades\DB;
|
|
use PhpOffice\PhpSpreadsheet\Cell\DataValidation;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class FinanceLedgerAccountTemplateTest extends FeatureTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->user->attachPermission(
|
|
Permission::where('name', 'read-admin-panel')->firstOrFail()
|
|
);
|
|
DB::connection('business_mirror')->table('fin_accounts')->insert([
|
|
'company_name' => '模板测试公司',
|
|
'account_short' => '模板测试账户',
|
|
'account_type' => '公户',
|
|
]);
|
|
}
|
|
|
|
public function test_account_master_template_is_blank_and_contains_page_columns_and_validations(): void
|
|
{
|
|
$response = $this->loginAs()->get(route('business.financial-ledger.accounts.template', [
|
|
'company_id' => $this->company->id,
|
|
]));
|
|
$response->assertOk();
|
|
$this->assertSame(
|
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
$response->headers->get('content-type'),
|
|
);
|
|
|
|
$path = tempnam(sys_get_temp_dir(), 'ledger-template-');
|
|
file_put_contents($path, $response->streamedContent());
|
|
|
|
try {
|
|
$spreadsheet = IOFactory::load($path);
|
|
$sheet = $spreadsheet->getSheetByName('账户总表');
|
|
$this->assertNotNull($sheet);
|
|
$this->assertSame([
|
|
'公司名称',
|
|
'账户简称',
|
|
'账户类型',
|
|
'账户状态',
|
|
'地区',
|
|
'账号',
|
|
'开户行',
|
|
'开户城市/网点',
|
|
'公司规划',
|
|
'账户是否保留',
|
|
'后4位',
|
|
'单笔限额',
|
|
'日限额',
|
|
'月限额',
|
|
'年限额',
|
|
'可用金额',
|
|
'不可用金额',
|
|
'每日可出',
|
|
'预计出清天数',
|
|
'提额目标',
|
|
'提额状态',
|
|
'提额动作',
|
|
'已做动作',
|
|
'下一步',
|
|
'备注',
|
|
'责任人',
|
|
], $sheet->rangeToArray('A1:Z1')[0]);
|
|
$this->assertNull($sheet->getCell('A2')->getValue());
|
|
$this->assertSame(DataValidation::TYPE_LIST, $sheet->getCell('C2')->getDataValidation()->getType());
|
|
$this->assertSame(DataValidation::TYPE_LIST, $sheet->getCell('D2')->getDataValidation()->getType());
|
|
$this->assertSame(DataValidation::TYPE_LIST, $sheet->getCell('J2')->getDataValidation()->getType());
|
|
$this->assertSame(Worksheet::SHEETSTATE_HIDDEN, $spreadsheet->getSheetByName('选项')->getSheetState());
|
|
$typeOptions = array_map(
|
|
static fn (array $row): string => (string) ($row[0] ?? ''),
|
|
$spreadsheet->getSheetByName('选项')->rangeToArray('B2:B20'),
|
|
);
|
|
$this->assertContains('网商银行', $typeOptions);
|
|
$this->assertSame(
|
|
['是', '否'],
|
|
array_map(
|
|
static fn (array $row): string => (string) ($row[0] ?? ''),
|
|
$spreadsheet->getSheetByName('选项')->rangeToArray('C2:C3'),
|
|
),
|
|
);
|
|
$this->assertNotNull($spreadsheet->getSheetByName('填写说明'));
|
|
$spreadsheet->disconnectWorksheets();
|
|
} finally {
|
|
@unlink($path);
|
|
}
|
|
}
|
|
}
|