setRawAttributes(['sSlug' => $slug]); $ancestor = new Categories();$ancestor->setRawAttributes(['sSlug' => $parent]); $category->setRelation('oParent', $parent ? $ancestor : null); $article = new Articles();$article->setRawAttributes(['sContent' => $html]); $article->setRelation('oCategory', $category); return $article; } public function test_legacy_promotion_is_replaced_without_touching_subscription_or_account_content(): void { foreach (['freenode', 'shadowrocketids'] as $category) { $tail = '

免费资源:

复制订阅

account:example
'; $html = '

文章开头

机场推荐 - 福云:

* 七折,折后8元

👉 点击进入机场官网:福云。

'.$tail; $article = $this->article($category, $html); $prepared = ArticleRecommendations::prepare($article); $this->assertTrue($prepared['inline']); $this->assertSame('

文章开头

'.ArticleRecommendations::SLOT.$tail, $prepared['body']); $this->assertSame($html, $article->sContent); } } public function test_no_promotion_link_means_no_destructive_guess_and_a_single_append(): void { $html = '

机场推荐 - 福云:

用户另写的内容

订阅

保留

'; $result = ArticleRecommendations::prepare($this->article('freenode', $html)); $this->assertTrue($result['enabled']);$this->assertFalse($result['inline']); $this->assertSame($html, $result['body']); } public function test_all_intro_subcategories_append_and_advanced_articles_have_one_working_jump(): void { $html = '

先配置订阅。

连接线路。

'; foreach (['windows','andorid','ios','mac','linux'] as $category) { $result = ArticleRecommendations::prepare($this->article($category, $html, 'client')); $this->assertTrue($result['enabled']);$this->assertFalse($result['inline']);$this->assertSame($html, $result['body']); } $article = $this->article('advanced', $html); $first = ArticleRecommendations::prepare($article); $this->assertSame(1, substr_count($first['body'], 'href="#airport-recommendations"')); $again = ArticleRecommendations::prepare($this->article('advanced', $first['body'])); $this->assertSame($first['body'], $again['body']); } public function test_disable_and_unrelated_categories_leave_content_unchanged(): void { $this->assertFalse(ArticleRecommendations::prepare($this->article('news', '

正文

'))['enabled']); config(['airport_recommendations.enabled' => false]); $result = ArticleRecommendations::prepare($this->article('advanced', '

订阅

')); $this->assertFalse($result['enabled']);$this->assertSame('

订阅

', $result['body']); } public function test_shared_view_outputs_configured_prices_coupon_and_sponsored_links_without_javascript(): void { $html = view('components.airport-recommendations')->render(); foreach (['福云', 'DP-LINK.NET', 'hardnerd', '>18<', '>26<', '>28<'] as $text) $this->assertStringContainsString($text, $html); $this->assertSame(1, substr_count($html, '
assertSame(3, substr_count($html, 'rel="sponsored nofollow noopener noreferrer"')); $this->assertSame(3, substr_count($html, 'data-airport-coupon="clashfreenode.com"')); config(['airport_recommendations.providers.fuc.price' => '20', 'airport_recommendations.providers.dpl.enabled' => false]); $updated = view('components.airport-recommendations')->render(); $this->assertStringContainsString('>20<', $updated);$this->assertStringNotContainsString('DP-LINK.NET', $updated); } }