$agentId] + $params); $request->user = (object) ['id' => 1]; $this->app->instance('request', $request); return (new AdminAgent())->domains($request, new AgentDomainService())->getData(true); } public function test_agent_binds_several_domains_per_type(): void { $agent = $this->agent(); $other = $this->agent(); $data = $this->bind($agent->id, ['pc' => ['https://a.com/#/reg', 'b.com', 'https://A.com/other'], 'h5' => 'https://m.a.com']); $this->assertSame(0, $data['code'], (string) $data['msg']); $this->assertSame(['https://a.com/#/reg', 'b.com'], $data['data']['pc_domains'], 'same host kept once, first one wins'); $this->assertSame(['https://m.a.com'], $data['data']['h5_domains']); $this->assertSame(['https://a.com/#/reg', 'https://a.com/#/reg', 'https://m.a.com'], [$data['data']['pc_domain'], $data['data']['pc_register_url'], $data['data']['h5_domain']], 'single fields keep the first domain'); $resolver = new AgentDomainService(); $this->assertSame($agent->id, $resolver->resolve(null, 'https://b.com/register')->id, 'every bound domain links the agent'); $taken = $this->bind($other->id, ['pc' => ['c.com', 'b.com']]); $this->assertSame('该域名已绑定其他代理:b.com', $taken['msg']); $this->assertSame([], $this->bind($other->id, ['h5' => []])['data']['pc_domains'], 'failed bind changed nothing'); $data = $this->bind($agent->id, ['pc' => ['b.com', 'd.com']]); $this->assertSame(['b.com', 'd.com'], $data['data']['pc_domains'], 'list replaced; a.com released'); $this->assertSame(['https://m.a.com'], $data['data']['h5_domains'], 'type not sent stays'); $this->assertSame(0, $this->bind($other->id, ['pc' => 'a.com'])['code'], 'released domain can be bound by another agent'); $this->assertSame([], $this->bind($agent->id, ['pc' => ''])['data']['pc_domains'], 'empty string clears'); } }