56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use Illuminate\Http\UploadedFile;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Modules\EcommerceFinance\Services\SupplierFreeShippingWorkbook;
|
|
use Tests\TestCase;
|
|
|
|
class SupplierFreeShippingWorkbookTest extends TestCase
|
|
{
|
|
public function test_csv_reads_package_shipping_value_and_blank_as_false(): void
|
|
{
|
|
$file = UploadedFile::fake()->createWithContent(
|
|
'supplier-free-shipping.csv',
|
|
"\xEF\xBB\xBF供应商代码,供应商名称,是否包邮厂家\nN901,一泰,包邮\nY411,七彩,\nS30,万都装饰,-\n",
|
|
);
|
|
|
|
$this->assertSame([
|
|
'N901' => true,
|
|
'Y411' => false,
|
|
'S30' => false,
|
|
], app(SupplierFreeShippingWorkbook::class)->read($file));
|
|
}
|
|
|
|
public function test_invalid_package_shipping_value_is_rejected_with_row_number(): void
|
|
{
|
|
$file = UploadedFile::fake()->createWithContent(
|
|
'supplier-free-shipping.csv',
|
|
"供应商代码,是否包邮厂家\nN901,待确认\n",
|
|
);
|
|
|
|
$this->expectException(ValidationException::class);
|
|
try {
|
|
app(SupplierFreeShippingWorkbook::class)->read($file);
|
|
} catch (ValidationException $exception) {
|
|
$this->assertSame(
|
|
['import' => ['第 2 行“是否包邮厂家”只能填写“包邮”,或留空表示否。']],
|
|
$exception->errors(),
|
|
);
|
|
throw $exception;
|
|
}
|
|
}
|
|
|
|
public function test_case_insensitive_duplicate_codes_are_rejected(): void
|
|
{
|
|
$file = UploadedFile::fake()->createWithContent(
|
|
'supplier-free-shipping.csv',
|
|
"供应商代码,是否包邮厂家\nN901,包邮\nn901,\n",
|
|
);
|
|
|
|
$this->expectException(ValidationException::class);
|
|
app(SupplierFreeShippingWorkbook::class)->read($file);
|
|
}
|
|
}
|