|
@@ -0,0 +1,140 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace Tests\Integration;
|
|
|
|
|
+
|
|
|
|
|
+use App\Http\Controllers\admin\PaymentConfiguration;
|
|
|
|
|
+use App\Http\Controllers\admin\RechargeChannel;
|
|
|
|
|
+use App\Services\PaymentChannelLinkService;
|
|
|
|
|
+use Illuminate\Config\Repository;
|
|
|
|
|
+use Illuminate\Database\Capsule\Manager;
|
|
|
|
|
+use Illuminate\Database\Schema\Blueprint;
|
|
|
|
|
+use Illuminate\Foundation\Application;
|
|
|
|
|
+use Illuminate\Http\JsonResponse;
|
|
|
|
|
+use Illuminate\Http\Request;
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
+use Illuminate\Support\Facades\Facade;
|
|
|
|
|
+use Illuminate\Translation\ArrayLoader;
|
|
|
|
|
+use Illuminate\Translation\Translator;
|
|
|
|
|
+use Illuminate\Validation\Factory;
|
|
|
|
|
+use PHPUnit\Framework\TestCase;
|
|
|
|
|
+
|
|
|
|
|
+class PaymentChannelOptionsTest extends TestCase
|
|
|
|
|
+{
|
|
|
|
|
+ private Application $app;
|
|
|
|
|
+
|
|
|
|
|
+ protected function setUp(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ Facade::clearResolvedInstances();
|
|
|
|
|
+ $this->app = new Application(dirname(__DIR__, 2));
|
|
|
|
|
+ $this->app->instance('config', new Repository(['app' => ['locale' => 'zh']]));
|
|
|
|
|
+ Facade::setFacadeApplication($this->app);
|
|
|
|
|
+ $db = new Manager($this->app);
|
|
|
|
|
+ $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'bot_']);
|
|
|
|
|
+ $db->setAsGlobal();
|
|
|
|
|
+ $db->bootEloquent();
|
|
|
|
|
+ $this->app->instance('db', $db->getDatabaseManager());
|
|
|
|
|
+ $translator = new Translator(new ArrayLoader(), 'zh');
|
|
|
|
|
+ $this->app->instance('translator', $translator);
|
|
|
|
|
+ $this->app->instance('validator', new Factory($translator, $this->app));
|
|
|
|
|
+ $this->app->instance(\Illuminate\Contracts\Routing\ResponseFactory::class, new class {
|
|
|
|
|
+ public function json($data, $status = 200, $headers = [], $options = 0) {
|
|
|
|
|
+ return new JsonResponse($data, $status, $headers, $options);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ Request::macro('validate', function (array $rules) {
|
|
|
|
|
+ return app('validator')->make($this->all(), $rules)->validate();
|
|
|
|
|
+ });
|
|
|
|
|
+ $db->schema()->create('recharge_channel', function (Blueprint $t) {
|
|
|
|
|
+ $t->id(); $t->integer('from'); $t->integer('data_type'); $t->string('key');
|
|
|
|
|
+ $t->string('name'); $t->string('type'); $t->decimal('rate', 8, 4);
|
|
|
|
|
+ $t->decimal('min')->nullable(); $t->decimal('max')->nullable(); $t->string('fixed')->nullable();
|
|
|
|
|
+ $t->integer('status'); $t->integer('sort'); $t->timestamps();
|
|
|
|
|
+ });
|
|
|
|
|
+ $db->schema()->create('recharge_channel_group', function (Blueprint $t) {
|
|
|
|
|
+ $t->id(); $t->string('name'); $t->text('recharge_type')->nullable();
|
|
|
|
|
+ $t->text('withdraw_type')->nullable(); $t->text('activity_type')->nullable(); $t->timestamps();
|
|
|
|
|
+ });
|
|
|
|
|
+ $fixture = require dirname(__DIR__) . '/fixtures/payment_provider_channels.php';
|
|
|
|
|
+ DB::table('recharge_channel')->insert($fixture['channels']);
|
|
|
|
|
+ DB::table('recharge_channel_group')->insert($fixture['groups']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected function tearDown(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::disconnect();
|
|
|
|
|
+ Facade::clearResolvedInstances();
|
|
|
|
|
+ parent::tearDown();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function request(string $path, array $params): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->app->instance('request', Request::create($path, 'GET', $params));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function channelList(array $params): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->request('/admin/rechargeChannel/list', $params);
|
|
|
|
|
+ $response = (new RechargeChannel())->list()->getData(true);
|
|
|
|
|
+ $this->assertSame(0, $response['code']);
|
|
|
|
|
+ return $response['data'];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_company_options_use_all_rows_not_first_page(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $page1 = $this->channelList(['data_type' => '1']);
|
|
|
|
|
+ $this->assertSame(19, $page1['total']);
|
|
|
|
|
+ $this->assertCount(15, $page1['data']);
|
|
|
|
|
+ $this->assertNotContains('jd', array_column($page1['data'], 'payment_company'));
|
|
|
|
|
+ $page2 = $this->channelList(['data_type' => '1', 'page' => 2]);
|
|
|
|
|
+ $this->assertSame(['zimu', 'no', 'no', 'jd'], array_column($page2['data'], 'payment_company'));
|
|
|
|
|
+ $this->request('/admin/paymentConfig/options', ['kind' => 'deposit']);
|
|
|
|
|
+ $data = (new PaymentConfiguration(new PaymentChannelLinkService()))->options()->getData(true);
|
|
|
|
|
+ $this->assertSame(0, $data['code']);
|
|
|
|
|
+ $this->assertSame([false, false, false, false], array_column($data['data']['payment_companies'], 'disabled'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_channel_list_displays_provider_separately_from_channel_name(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $data = $this->channelList(['data_type' => '1', 'payment_company' => 'jd']);
|
|
|
|
|
+ $this->assertSame(1, $data['total']);
|
|
|
|
|
+ $this->assertSame('JD钱包', $data['data'][0]['name']);
|
|
|
|
|
+ $this->assertSame('JD支付', $data['data'][0]['payment_company_label']);
|
|
|
|
|
+ $this->assertSame(1, $data['data'][0]['from']);
|
|
|
|
|
+ $this->assertSame(24, $data['data'][0]['id']);
|
|
|
|
|
+ $withdraw = $this->channelList(['data_type' => '2', 'payment_company' => 'jd']);
|
|
|
|
|
+ $this->assertSame(25, $withdraw['data'][0]['id']);
|
|
|
|
|
+ $this->assertSame(0, $this->channelList(['data_type' => '2', 'payment_company' => 'sanjin'])['total']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_missing_group_returns_reason_without_enabling_or_rewriting_config(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::table('recharge_channel_group')->update(['recharge_type' => 'wxsm,zfbsm']);
|
|
|
|
|
+ $this->request('/admin/paymentConfig/options', ['kind' => 'deposit']);
|
|
|
|
|
+ $data = (new PaymentConfiguration(new PaymentChannelLinkService()))->options()->getData(true)['data'];
|
|
|
|
|
+ $this->assertSame([false, true, true, true], array_column($data['payment_companies'], 'disabled'));
|
|
|
|
|
+ $this->assertSame(['', 'group_missing', 'group_missing', 'group_missing'], array_column($data['payment_companies'], 'disabled_reason_code'));
|
|
|
|
|
+ $this->assertSame('wxsm,zfbsm', DB::table('recharge_channel_group')->value('recharge_type'));
|
|
|
|
|
+ $this->assertSame(0, DB::table('recharge_channel')->where('id', 31)->value('status'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public function test_group_editor_options_include_new_types_even_before_any_group_uses_them(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ DB::table('recharge_channel_group')->update(['recharge_type' => 'wxsm', 'withdraw_type' => 'DF001']);
|
|
|
|
|
+ $this->request('/admin/rechargeChannel/getChannel', ['data_type' => 1]);
|
|
|
|
|
+ $response = (new RechargeChannel())->getChannel()->getData(true);
|
|
|
|
|
+ $this->assertSame(0, $response['code']);
|
|
|
|
|
+ $names = array_column($response['data']['data'], 'name', 'type');
|
|
|
|
|
+ $this->assertSame('JD钱包', $names['JDpay']);
|
|
|
|
|
+ $this->assertSame('NO快捷充值-扫码支付', $names['NOpay12']);
|
|
|
|
|
+ $this->assertSame('NO快捷充值-余额支付', $names['NOpay13']);
|
|
|
|
|
+ $this->assertSame('808充值', $names['ZIMUpay']);
|
|
|
|
|
+ $this->assertSame(13, $response['data']['total']);
|
|
|
|
|
+ $this->request('/admin/rechargeChannel/getChannel', ['data_type' => 2]);
|
|
|
|
|
+ $names = array_column((new RechargeChannel())->getChannel()->getData(true)['data']['data'], 'name', 'type');
|
|
|
|
|
+ $this->assertSame('JD钱包', $names['JDpay']);
|
|
|
|
|
+ $this->assertSame('NO快捷提现', $names['NOwithdraw']);
|
|
|
|
|
+ $this->assertSame('808账户提现', $names['ZIMUwithdraw']);
|
|
|
|
|
+ $this->assertArrayNotHasKey('ZIMUcash', $names);
|
|
|
|
|
+ $this->assertSame('wxsm', DB::table('recharge_channel_group')->value('recharge_type'));
|
|
|
|
|
+ }
|
|
|
|
|
+}
|