66 lines
3.3 KiB
PHP
66 lines
3.3 KiB
PHP
<?php
|
||
|
||
namespace Tests\Unit\EcommerceFinance;
|
||
|
||
use Modules\EcommerceFinance\Services\PlantingCommissionPeople;
|
||
use Modules\EcommerceFinance\Services\PlantingReimbursementReferences;
|
||
use Tests\TestCase;
|
||
|
||
class PlantingCommissionPeopleTest extends TestCase
|
||
{
|
||
public function test_historical_name_only_list_can_still_be_exported(): void
|
||
{
|
||
\Illuminate\Support\Facades\Storage::fake('local');
|
||
\Illuminate\Support\Facades\Storage::disk('local')->put('planting-reimbursement-references/1/commission-people.json', json_encode([
|
||
'people' => [['name' => '甲', 'remark' => '历史', 'added_at' => null]], 'source' => 'history', 'updated_at' => null,
|
||
]));
|
||
$people = app(PlantingCommissionPeople::class);
|
||
$this->assertSame(['甲' => []], $people->platformMap(1));
|
||
$this->assertStringContainsString('"甲","","历史",""', $people->exportCsv(1));
|
||
}
|
||
|
||
public function test_platform_caps_preserve_spaces_width_and_uncapped_platforms(): void
|
||
{
|
||
$this->assertSame(['京东' => 1500, '天猫' => null, '拼多多' => 600], PlantingCommissionPeople::platformCaps('京东 15,天猫,拼多多 6 元/单'));
|
||
$this->assertSame(['阿里巴巴' => 550, '淘宝' => null, '京喜' => 0], PlantingCommissionPeople::platformCaps('1688 5.5元;淘宝C店;京喜0'));
|
||
$this->assertSame([], PlantingCommissionPeople::platformCaps('尚未登记'));
|
||
$this->assertSame(['京东' => null], PlantingCommissionPeople::platformCaps('京东15,京东'));
|
||
}
|
||
|
||
public function test_streamed_commission_csv_selects_right_hand_person_and_platform_columns(): void
|
||
{
|
||
$path = tempnam(sys_get_temp_dir(), 'commission-');
|
||
try {
|
||
file_put_contents($path, "\xEF\xBB\xBF平台,人员,佣金,人员,平台\n天猫,左侧,99,右侧,京东 15\n,,,另一个,拼多多5元\n");
|
||
$rows = app(PlantingReimbursementReferences::class)->parse('commission', $path, '名单.csv');
|
||
$this->assertSame([
|
||
['key' => '右侧', 'payload' => ['platform' => '京东 15']],
|
||
['key' => '另一个', 'payload' => ['platform' => '拼多多5元']],
|
||
], $rows);
|
||
} finally {
|
||
unlink($path);
|
||
}
|
||
}
|
||
|
||
public function test_xlsx_commission_import_preserves_platform_caps_for_a_full_roster(): void
|
||
{
|
||
$path = tempnam(sys_get_temp_dir(), 'commission-xlsx-');
|
||
$book = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
|
||
try {
|
||
$sheet = $book->getActiveSheet();
|
||
$sheet->fromArray([['平台', '人员', '佣金', '人员', '平台']]);
|
||
for ($i = 1; $i <= 93; $i++) {
|
||
$sheet->fromArray([['天猫', '左侧'.$i, '10元', '人员'.$i, '京东 15,拼多多5元']], null, 'A'.($i+1));
|
||
}
|
||
(new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($book))->save($path);
|
||
$rows = app(PlantingReimbursementReferences::class)->parse('commission', $path, '名单.xlsx');
|
||
$this->assertCount(93, $rows);
|
||
$this->assertSame('人员1', $rows[0]['key']);
|
||
$this->assertSame(['京东' => 1500, '拼多多' => 500], PlantingCommissionPeople::platformCaps($rows[92]['payload']['platform']));
|
||
} finally {
|
||
$book->disconnectWorksheets();
|
||
unlink($path);
|
||
}
|
||
}
|
||
}
|