CaiWuXiTong/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php

138 lines
5.1 KiB
PHP

<?php
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use Mockery;
use Modules\EcommerceFinance\Repositories\PlatformPromotionAccountRepository;
use Tests\Feature\FeatureTestCase;
class MarketingPlatformPromotionBillsTest extends FeatureTestCase
{
public function test_promotion_platform_is_a_tab_inside_marketing_account_bills(): void
{
$this->allowMarketingAccountBillsPage();
$repository = Mockery::mock(PlatformPromotionAccountRepository::class);
$repository->shouldReceive('latestMonth')->once()->andReturn('2026-08');
$repository->shouldReceive('dashboard')->once()->with([
'month' => '2026-08',
'shop_name' => '',
'account' => '',
], 5000, 'jd')->andReturn($this->dashboardData());
$this->app->instance(PlatformPromotionAccountRepository::class, $repository);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'marketing-account-bills',
'tab' => 'jd-promotion',
]))
->assertOk()
->assertSeeText('京东京准通')
->assertSee('aria-label="京东京准通推广账户筛选"', false)
->assertSeeText('测试店铺')
->assertSeeText('导出 CSV')
->assertSee('class="my-6 business-page--marketing-account-bills"', false)
->assertSee(route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'marketing-account-bills',
'tab' => 'taobao-alipay',
]), false)
->assertDontSeeText('平台推广账户流水');
}
public function test_promotion_platform_export_uses_merged_marketing_account_bills_route(): void
{
$this->allowMarketingAccountBillsPage();
$repository = Mockery::mock(PlatformPromotionAccountRepository::class);
$repository->shouldReceive('latestMonth')->never();
$repository->shouldReceive('dashboard')->once()->with([
'month' => '2026-08',
'shop_name' => '测试',
'account' => 'account-01',
], 5000, 'jd')->andReturn($this->dashboardData());
$this->app->instance(PlatformPromotionAccountRepository::class, $repository);
$response = $this->loginAs()->get(route('business.pages.export', [
'section' => 'billing-transactions',
'page' => 'marketing-account-bills',
'tab' => 'jd-promotion',
'month' => '2026-08',
'shop_name' => '测试',
'account' => 'account-01',
]));
$filename = '店铺营销账户账单_jd_2026-08.csv';
$response->assertOk()
->assertHeader('Content-Type', 'text/csv; charset=UTF-8')
->assertDownload('_jd_2026-08.csv');
$this->assertStringContainsString(
"filename*=utf-8''" . rawurlencode($filename),
(string) $response->headers->get('Content-Disposition'),
);
$this->assertStringContainsString('测试店铺', $response->streamedContent());
}
public function test_removed_platform_promotion_directory_returns_to_the_current_page_with_feedback(): void
{
$this->allowMarketingAccountBillsPage();
$this->withExceptionHandling();
$this->loginAs();
$currentPage = route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'marketing-account-bills',
'tab' => 'jd-promotion',
]);
$this->from($currentPage)
->get(route('business.pages.show', [
'section' => 'billing-transactions',
'page' => 'platform-promotion-accounts',
'tab' => 'jd',
]))
->assertRedirect($currentPage)
->assertSessionHas('errors');
}
private function dashboardData(): array
{
return [
'jd' => [[
'shop_name' => '测试店铺',
'account' => 'account-01',
'show_date' => '2026-08-01',
'trade_type_name' => '充值',
'amount' => 100,
'balance_amount' => 100,
'remark' => '测试记录',
]],
'jdSummary' => ['income' => 100, 'expense' => 0, 'record_count' => 1],
'dy' => [],
'dySummary' => [],
'dyStatus' => [],
'dw' => [],
'dwSummary' => [],
'vipSales' => [],
'vipTax' => [],
'vipMarketing' => [],
'vipSummary' => [],
];
}
private function allowMarketingAccountBillsPage(): void
{
$this->user->update(['locale' => 'zh-CN']);
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
$subject = 'user_' . $this->user->id;
setting()->set('system.sidebar_permissions', json_encode([
'configured' => [$subject],
'subjects' => [
$subject => ['billing-transactions/marketing-account-bills'],
],
], JSON_UNESCAPED_UNICODE));
}
}