Fix views inconsistencies

This commit is contained in:
DariusIII
2026-08-09 14:37:39 +02:00
parent 73e5294132
commit f1912e5e74
117 changed files with 3587 additions and 3384 deletions
@@ -423,7 +423,11 @@ class AdminReleaseReportControllerTest extends TestCase
$this->assertFileExists($browseServicePath);
$detailsController = file_get_contents($detailsControllerPath);
// The details view is split into partials under details/partials/; assert against the combined source.
$detailsView = file_get_contents($detailsViewPath);
foreach (glob(resource_path('views/details/partials/*.blade.php')) ?: [] as $detailsPartial) {
$detailsView .= file_get_contents($detailsPartial);
}
$releaseResultsComponent = file_get_contents($releaseResultsComponentPath);
$browseService = file_get_contents($browseServicePath);
@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Extensions;
use Tests\TestCase;
class MakeFieldLinksTest extends TestCase
{
public function test_returns_empty_string_when_field_missing(): void
{
$this->assertSame('', makeFieldLinks(['title' => 'Test'], 'genre', 'movies'));
}
public function test_returns_empty_string_when_field_empty(): void
{
$this->assertSame('', makeFieldLinks(['genre' => ''], 'genre', 'movies'));
}
public function test_builds_links_for_comma_separated_values(): void
{
$result = makeFieldLinks(['genre' => 'Action, Drama'], 'genre', 'movies');
$this->assertStringContainsString('?genre=Action', $result);
$this->assertStringContainsString('>Action</a>', $result);
$this->assertStringContainsString('?genre=Drama', $result);
$this->assertStringContainsString('>Drama</a>', $result);
}
public function test_escapes_html_in_link_text_and_title(): void
{
$malicious = '"><script>alert(1)</script>';
$result = makeFieldLinks(['actors' => $malicious], 'actors', 'movies');
$this->assertStringNotContainsString('<script>', $result);
$this->assertStringContainsString(e($malicious), $result);
// The raw quote must not break out of the title attribute
$this->assertStringNotContainsString('title="'.$malicious.'"', $result);
}
public function test_escapes_ampersands_in_names(): void
{
$result = makeFieldLinks(['actors' => 'Tom & Jerry'], 'actors', 'movies');
$this->assertStringContainsString('>Tom &amp; Jerry</a>', $result);
$this->assertStringContainsString('title="Tom &amp; Jerry"', $result);
}
public function test_limits_number_of_links(): void
{
$values = implode(', ', ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']);
$result = makeFieldLinks(['genre' => $values], 'genre', 'movies');
$this->assertStringNotContainsString('>I</a>', $result);
$this->assertStringNotContainsString('>J</a>', $result);
}
}
+57
View File
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Models;
use App\Models\Content;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class ContentTest extends TestCase
{
#[Test]
public function it_resolves_absolute_urls_as_is(): void
{
$content = new Content(['url' => 'https://example.com/page']);
$this->assertSame('https://example.com/page', $content->resolved_url);
$this->assertTrue($content->is_external_url);
}
#[Test]
public function it_resolves_http_urls_as_is(): void
{
$content = new Content(['url' => 'http://example.com']);
$this->assertSame('http://example.com', $content->resolved_url);
$this->assertTrue($content->is_external_url);
}
#[Test]
public function it_prepends_https_to_bare_domains(): void
{
$content = new Content(['url' => 'chatgpt.ai']);
$this->assertSame('https://chatgpt.ai', $content->resolved_url);
$this->assertTrue($content->is_external_url);
}
#[Test]
public function it_resolves_internal_paths_against_the_site_url(): void
{
$content = new Content(['url' => '/forum']);
$this->assertSame(url('/forum'), $content->resolved_url);
$this->assertFalse($content->is_external_url);
}
#[Test]
public function it_returns_null_url_when_url_is_empty(): void
{
$content = new Content(['url' => null]);
$this->assertNull($content->resolved_url);
$this->assertFalse($content->is_external_url);
}
}