Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions web/tests/integration/BanDrawerDemoDownloadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Sbpp\Tests\Integration;

use PHPUnit\Framework\TestCase;

/**
* sbpp/sourcebans-pp#1554 — the player drawer's Overview pane must
* surface a getdemo.php download link when the ban has an uploaded
* demo (`bans.detail` carries `demo_count`). SourceBans 1.x rendered a
* "Review Demo" affordance on the sliding ban panel; the 2.0 drawer
* dropped it.
*/
final class BanDrawerDemoDownloadTest extends TestCase
{
private static function panelRoot(): string
{
return dirname(__DIR__, 2);
}

public function testDrawerOverviewBuildsDemoDownloadLink(): void
{
$src = (string) file_get_contents(self::panelRoot() . '/themes/default/js/theme.js');
$this->assertStringContainsString('data.demo_count', $src);
$this->assertStringContainsString('getdemo.php?type=B&id=', $src);
$this->assertStringContainsString('data-testid="drawer-demo-download"', $src);
}

public function testBansDetailApiExposesDemoCount(): void
{
$src = (string) file_get_contents(self::panelRoot() . '/api/handlers/bans.php');
$this->assertStringContainsString("'demo_count'", $src);
}
}
18 changes: 17 additions & 1 deletion web/themes/default/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,22 @@
).join('')
+ '</dl>';

// #1554 — surface the demo download affordance the way SB 1.x's
// sliding ban panel did. `bans.detail` carries `demo_count`; when a
// ban has an uploaded demo the file is served by `getdemo.php?type=B`
// (see web/getdemo.php). Comm-blocks have no demo column, so this is
// ban-focal only.
let demoHtml = '';
if (!isComm && Number((data && data.demo_count) || 0) > 0) {
const demoUrl = 'getdemo.php?type=B&id=' + encodeURIComponent(String(data.bid));
demoHtml = '<section data-testid="drawer-demo" style="margin-top:0.5rem">'
+ '<h3 class="text-xs text-faint" style="text-transform:uppercase;letter-spacing:0.06em;margin:0 0 0.5rem">Demo</h3>'
+ '<a class="btn btn--secondary btn--sm" data-testid="drawer-demo-download" href="' + escapeHtml(demoUrl) + '">'
+ '<i data-lucide="download" style="width:14px;height:14px"></i> Download demo'
+ '</a>'
+ '</section>';
}

let commentsHtml = '';
if (commentsVisible) {
commentsHtml = '<section data-testid="drawer-comments" style="margin-top:0.5rem">'
Expand All @@ -798,7 +814,7 @@
+ '</section>';
}

return idHtml + focalHtml + commentsHtml;
return idHtml + focalHtml + demoHtml + commentsHtml;
}

/**
Expand Down
Loading