Files
fn_b/tests/Feature/AirportDomainsTest.php
T

41 lines
3.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Services\{AirportDomains,ArticleRecommendations};
use App\Models\{Articles,Categories};
use Tests\TestCase;
final class AirportDomainsTest extends TestCase
{
private string $path;
protected function setUp(): void { parent::setUp();$this->path=tempnam(sys_get_temp_dir(),'domainhub-test-');config(['app.key'=>'base64:'.base64_encode(str_repeat('t',32)),'domainhub.enabled'=>true,'domainhub.state_path'=>$this->path,'domainhub.environment'=>'production','site_mode.state_path'=>null,'site_mode.quiet'=>false,'advertising.fuc.enabled'=>true]);$this->snapshot(); }
protected function tearDown(): void { @unlink($this->path);@unlink($this->path.'.watermark');parent::tearDown(); }
private function snapshot(?array $selected=['url'=>'https://fu-nav3.com/','eligible'=>true,'access'=>'available','reason'=>null],int $age=0): void
{
file_put_contents($this->path,json_encode(['digest'=>str_repeat('a',64),'checked_at'=>time()-$age,'manifest'=>['schema'=>'domainhub.public.v1','project'=>'fna_v3','environment'=>'production','instance'=>'advertising','version'=>8,'providers'=>['fuc'=>['selected'=>$selected],'hn'=>['selected'=>null],'dpl'=>['selected'=>null]]]]));
file_put_contents($this->path.'.watermark',json_encode(['version'=>8,'digest'=>str_repeat('a',64)]));
}
public function test_single_resolver_and_click_revocation_without_render_or_remote_requests(): void
{
$this->assertSame('/go/airport/fuc/recommendation',ArticleRecommendations::providers()['fuc']['url']);
$this->assertSame('/go/airport/fuc/banner',AirportDomains::link('fuc','banner'));
$this->get('/go/airport/fuc/recommendation')->assertStatus(302)->assertHeader('Location','https://fu-nav3.com/')->assertHeader('X-Robots-Tag','noindex, nofollow');
$this->snapshot(null);
$this->assertSame([],ArticleRecommendations::providers());
$this->get('/go/airport/fuc/recommendation')->assertStatus(410)->assertHeader('Cache-Control','no-store, private');
}
public function test_expiry_quiet_and_independent_switches(): void
{
config(['advertising.fuc.enabled'=>false]);$this->assertNull(AirportDomains::link('fuc','banner'));
$this->assertNotNull(AirportDomains::link('fuc','recommendation'));
config(['site_mode.quiet'=>true]);$this->get('/go/airport/fuc/recommendation')->assertStatus(410);
config(['site_mode.quiet'=>false]);$this->snapshot(age:86401);$this->assertNull(AirportDomains::target('fuc'));
file_put_contents($this->path,'broken');$this->assertNull(AirportDomains::target('fuc'));
}
public function test_empty_pool_strips_legacy_promo_without_touching_subscription_payload(): void
{
$this->snapshot(null);$category=new Categories();$category->setRawAttributes(['sSlug'=>'freenode']);$category->setRelation('oParent',null);
$tail='<h2>免费资源</h2><pre>vmess://keep-exact</pre>';
$a=new Articles();$a->setRelation('oCategory',$category);$html='<h2>机场推荐 - 福云:</h2><p><a href="https://fuuu.cloud">机场官网:福云</a></p>'.$tail;$a->setRawAttributes(['sContent'=>$html]);
$r=ArticleRecommendations::prepare($a);$this->assertFalse($r['enabled']);$this->assertSame($tail,$r['body']);$this->assertSame($html,$a->sContent);
}
}