5 Commits

Author SHA1 Message Date
f167e64d00 make the cli update executable
All checks were successful
CI/CD Pipeline / test (push) Successful in 2s
CI/CD Pipeline / deploy (push) Successful in 18s
2026-02-10 19:58:09 +01:00
95ebc7778d Update ACP system navigation
All checks were successful
CI/CD Pipeline / test (push) Successful in 2s
CI/CD Pipeline / deploy (push) Successful in 19s
2026-02-10 19:52:24 +01:00
c67a3ec6d0 Add pre-commit hook to verify DB
All checks were successful
CI/CD Pipeline / test (push) Successful in 3s
CI/CD Pipeline / deploy (push) Successful in 19s
2026-02-10 18:46:43 +01:00
bf278667bc Add git_update.sh and adjust update/test hooks
All checks were successful
CI/CD Pipeline / test (push) Successful in 3s
CI/CD Pipeline / deploy (push) Successful in 23s
2026-02-10 18:38:51 +01:00
30a06e18f0 Bump version
All checks were successful
CI/CD Pipeline / test (push) Successful in 2s
CI/CD Pipeline / deploy (push) Successful in 19s
2026-02-08 19:16:21 +01:00
10 changed files with 534 additions and 420 deletions

View File

@@ -1,9 +1,14 @@
# Changelog # Changelog
## 2026-02-10
- Reshaped ACP System tab with left navigation and dedicated views (Overview, Live Update, CLI, CI/CD).
- Moved system requirements table into the CI/CD view with refresh controls.
## 2026-02-08 ## 2026-02-08
- Achieved 100% test coverage across the backend. - Achieved 100% test coverage across the backend.
- Added comprehensive Feature and Unit tests for controllers, models, services, and console commands. - Added comprehensive Feature and Unit tests for controllers, models, services, and console commands.
- Added extensive edge-case and error-path coverage (system update/status, versioning, attachments, forums, roles, ranks, settings, portal, etc.). - Added extensive edge-case and error-path coverage (system update/status, versioning, attachments, forums, roles, ranks, settings, portal, etc.).
- Added `git_update.sh` for CLI-based updates (stable branch, deps, build, migrations, version sync).
## 2026-01-12 ## 2026-01-12
- Switched main SPA layouts to fluid containers to reduce wasted space. - Switched main SPA layouts to fluid containers to reduce wasted space.

View File

@@ -1,7 +1,12 @@
TODO: Remove remaining IIFEs in ACP UI; prefer plain components/helpers. TODO: Remove remaining IIFEs in ACP UI; prefer plain components/helpers.
Add git_update.sh script to update the forum and core.
Tag the release as latest
For update, make three tabs: insite, cli, ci/di and add explanation
Progress (last 2 days): Progress (last 2 days):
- Reached 100% test coverage across the codebase. - Reached 100% test coverage across the codebase.
- Added extensive Feature and Unit tests for controllers, models, services, and console commands. - Added extensive Feature and Unit tests for controllers, models, services, and console commands.
- Added coverage scripts and cleanup (tests for update/version flows, system update/status, attachments, forums, roles, ranks, settings, portal, etc.). - Added coverage scripts and cleanup (tests for update/version flows, system update/status, attachments, forums, roles, ranks, settings, portal, etc.).
- Hardened tests with fakes/mocks to cover error paths and edge cases. - Hardened tests with fakes/mocks to cover error paths and edge cases.
TODO: Make PHP binary path configurable for updates if default PHP is outdated (ACP -> System).

View File

@@ -30,6 +30,10 @@ class BbcodeFormatter
private static function build(): array private static function build(): array
{ {
if (app()->environment('testing') && env('BBCODE_FORCE_FAIL')) {
throw new \RuntimeException('Unable to initialize BBCode formatter.');
}
$configurator = new Configurator(); $configurator = new Configurator();
$bbcodes = $configurator->plugins->load('BBCodes'); $bbcodes = $configurator->plugins->load('BBCodes');
$bbcodes->addFromRepository('B'); $bbcodes->addFromRepository('B');

View File

@@ -169,7 +169,7 @@ class SystemUpdateController extends Controller
], 500); ], 500);
} }
$phpBinary = PHP_BINARY ?: 'php'; $phpBinary = env('SYSTEM_UPDATE_PHP_BINARY') ?: (PHP_BINARY ?: 'php');
$append("Running migrations (using {$phpBinary})..."); $append("Running migrations (using {$phpBinary})...");
$migrate = new Process([$phpBinary, 'artisan', 'migrate', '--force'], base_path()); $migrate = new Process([$phpBinary, 'artisan', 'migrate', '--force'], base_path());
$migrate->setTimeout(600); $migrate->setTimeout(600);

View File

@@ -97,5 +97,6 @@
}, },
"minimum-stability": "stable", "minimum-stability": "stable",
"prefer-stable": true, "prefer-stable": true,
"version": "26.0.1" "version": "26.0.2",
"build": "45"
} }

47
git_update.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
if [[ -n "$(git status --porcelain)" ]]; then
echo "Working tree is dirty. Please commit or stash changes before updating."
exit 1
fi
echo "Fetching latest refs..."
git fetch --prune --tags
echo "Checking out stable branch..."
git checkout stable
echo "Pulling latest stable..."
git pull --ff-only
echo "Installing PHP dependencies..."
composer install --no-dev --optimize-autoloader
echo "Installing JS dependencies..."
npm install
echo "Building assets..."
npm run build
PHP_BIN="${PHP_BIN:-php}"
echo "Running migrations..."
$PHP_BIN artisan migrate --force
echo "Syncing version/build to settings..."
VERSION="$($PHP_BIN -r '$c=json_decode(file_get_contents("composer.json"), true); echo $c["version"] ?? "";')"
BUILD="$($PHP_BIN -r '$c=json_decode(file_get_contents("composer.json"), true); echo $c["build"] ?? "";')"
if [[ -n "$VERSION" ]]; then
$PHP_BIN artisan tinker --execute="\\App\\Models\\Setting::updateOrCreate(['key'=>'version'], ['value'=>'$VERSION']);"
fi
if [[ -n "$BUILD" ]]; then
$PHP_BIN artisan tinker --execute="\\App\\Models\\Setting::updateOrCreate(['key'=>'build'], ['value'=>'$BUILD']);"
fi
echo "Update complete."

View File

@@ -96,6 +96,7 @@ function Acp({ isAdmin }) {
const [systemStatus, setSystemStatus] = useState(null) const [systemStatus, setSystemStatus] = useState(null)
const [systemLoading, setSystemLoading] = useState(false) const [systemLoading, setSystemLoading] = useState(false)
const [systemError, setSystemError] = useState('') const [systemError, setSystemError] = useState('')
const [systemSection, setSystemSection] = useState('info')
const [usersPage, setUsersPage] = useState(1) const [usersPage, setUsersPage] = useState(1)
const [usersPerPage, setUsersPerPage] = useState(10) const [usersPerPage, setUsersPerPage] = useState(10)
const [userSort, setUserSort] = useState({ columnId: 'name', direction: 'asc' }) const [userSort, setUserSort] = useState({ columnId: 'name', direction: 'asc' })
@@ -3507,254 +3508,352 @@ function Acp({ isAdmin }) {
<Tab eventKey="system" title={t('acp.system')}> <Tab eventKey="system" title={t('acp.system')}>
{systemError && <p className="text-danger">{systemError}</p>} {systemError && <p className="text-danger">{systemError}</p>}
{systemLoading && <p className="bb-muted">{t('acp.loading')}</p>} {systemLoading && <p className="bb-muted">{t('acp.loading')}</p>}
{!systemLoading && systemStatus && ( {!systemLoading && (
<div className="bb-acp-panel"> <Row className="g-4">
<div className="bb-acp-panel-header"> <Col lg={3} xl={2}>
<div className="d-flex align-items-center justify-content-between"> <div className="bb-acp-sidebar">
<h5 className="mb-0">{t('system.requirements')}</h5> <div className="bb-acp-sidebar-section">
<Button <div className="bb-acp-sidebar-title">{t('acp.system')}</div>
type="button" <div className="list-group">
size="sm" <button
variant="dark" type="button"
onClick={loadSystemStatus} className={`list-group-item list-group-item-action ${
disabled={systemLoading} systemSection === 'info' ? 'is-active' : ''
> }`}
{t('acp.refresh')} onClick={() => setSystemSection('info')}
</Button> >
Overview
</button>
<button
type="button"
className={`list-group-item list-group-item-action ${
systemSection === 'insite' ? 'is-active' : ''
}`}
onClick={() => setSystemSection('insite')}
>
Live Update
</button>
<button
type="button"
className={`list-group-item list-group-item-action ${
systemSection === 'cli' ? 'is-active' : ''
}`}
onClick={() => setSystemSection('cli')}
>
CLI
</button>
<button
type="button"
className={`list-group-item list-group-item-action ${
systemSection === 'ci' ? 'is-active' : ''
}`}
onClick={() => setSystemSection('ci')}
>
CI/CD
</button>
</div>
</div>
</div> </div>
</div> </Col>
<div className="bb-acp-panel-body"> <Col lg={9} xl={10}>
<table className="bb-acp-stats-table"> {systemSection === 'info' && (
<thead> <div className="bb-acp-panel">
<tr> <div className="bb-acp-panel-header">
<th>{t('system.check')}</th> <h5 className="mb-0">System overview</h5>
<th>{t('system.path')}</th> </div>
<th>{t('system.min_version')}</th> <div className="bb-acp-panel-body">
<th>{t('system.current_version')}</th> <p className="bb-muted mb-0">
<th>{t('system.status')}</th> Placeholder: summary, upgrade guidance, and environment health notes will
<th>{t('system.recheck')}</th> live here.
</tr> </p>
</thead> </div>
<tbody> </div>
<tr> )}
<td>PHP</td> {systemSection === 'insite' && (
<td className="bb-acp-stats-value">{systemStatus.php_selected_path || '—'}</td> <div className="bb-acp-panel">
<td className="bb-acp-stats-value"> <div className="bb-acp-panel-header">
{systemStatus.min_versions?.php || '—'} <h5 className="mb-0">Live Update</h5>
</td> </div>
<td className="bb-acp-stats-value"> <div className="bb-acp-panel-body">
{systemStatus.php_selected_version || '—'} <p className="bb-muted mb-0">
</td> Placeholder: run a live update from inside the forum, with safety checks
<td className="bb-acp-stats-value"> and status details.
<StatusIcon </p>
status={systemStatus.php_selected_ok ? 'ok' : 'bad'} </div>
/> </div>
</td> )}
<td className="bb-acp-stats-value"> {systemSection === 'cli' && (
<div className="bb-acp-panel">
<div className="bb-acp-panel-header">
<h5 className="mb-0">CLI</h5>
</div>
<div className="bb-acp-panel-body">
<p className="bb-muted mb-0">
Placeholder: CLI upgrade commands and automation helpers will live here.
</p>
</div>
</div>
)}
{systemSection === 'ci' && (
<div className="bb-acp-panel">
<div className="bb-acp-panel-header">
<div className="d-flex align-items-center justify-content-between">
<h5 className="mb-0">{t('system.requirements')}</h5>
<Button <Button
type="button"
size="sm" size="sm"
variant="dark" variant="dark"
onClick={loadSystemStatus} onClick={loadSystemStatus}
disabled={systemLoading} disabled={systemLoading}
> >
{t('system.recheck')} {t('acp.refresh')}
</Button> </Button>
</td> </div>
</tr> </div>
<tr> <div className="bb-acp-panel-body">
<td>Composer</td> {!systemStatus && (
<td className="bb-acp-stats-value"> <p className="bb-muted mb-0">
{systemStatus.composer || t('system.not_found')} {t('system.not_found')}
</td> </p>
<td className="bb-acp-stats-value"> )}
{systemStatus.min_versions?.composer || '—'} {systemStatus && (
</td> <table className="bb-acp-stats-table">
<td className="bb-acp-stats-value"> <thead>
{systemStatus.composer_version || '—'} <tr>
</td> <th>{t('system.check')}</th>
<td className="bb-acp-stats-value"> <th>{t('system.path')}</th>
<StatusIcon status={systemStatus.composer ? 'ok' : 'bad'} /> <th>{t('system.min_version')}</th>
</td> <th>{t('system.current_version')}</th>
<td className="bb-acp-stats-value"> <th>{t('system.status')}</th>
<Button <th>{t('system.recheck')}</th>
size="sm" </tr>
variant="dark" </thead>
onClick={loadSystemStatus} <tbody>
disabled={systemLoading} <tr>
> <td>PHP</td>
{t('system.recheck')} <td className="bb-acp-stats-value">
</Button> {systemStatus.php_selected_path || '—'}
</td> </td>
</tr> <td className="bb-acp-stats-value">
<tr> {systemStatus.min_versions?.php || '—'}
<td>Node</td> </td>
<td className="bb-acp-stats-value"> <td className="bb-acp-stats-value">
{systemStatus.node || t('system.not_found')} {systemStatus.php_selected_version || '—'}
</td> </td>
<td className="bb-acp-stats-value"> <td className="bb-acp-stats-value">
{systemStatus.min_versions?.node || '—'} <StatusIcon
</td> status={systemStatus.php_selected_ok ? 'ok' : 'bad'}
<td className="bb-acp-stats-value"> />
{systemStatus.node_version || '—'} </td>
</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> <Button
<StatusIcon status={systemStatus.node ? 'ok' : 'bad'} /> size="sm"
</td> variant="dark"
<td className="bb-acp-stats-value"> onClick={loadSystemStatus}
<Button disabled={systemLoading}
size="sm" >
variant="dark" {t('system.recheck')}
onClick={loadSystemStatus} </Button>
disabled={systemLoading} </td>
> </tr>
{t('system.recheck')} <tr>
</Button> <td>Composer</td>
</td> <td className="bb-acp-stats-value">
</tr> {systemStatus.composer || t('system.not_found')}
<tr> </td>
<td>npm</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> {systemStatus.min_versions?.composer || '—'}
{systemStatus.npm || t('system.not_found')} </td>
</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> {systemStatus.composer_version || '—'}
{systemStatus.min_versions?.npm || '—'} </td>
</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> <StatusIcon status={systemStatus.composer ? 'ok' : 'bad'} />
{systemStatus.npm_version || '—'} </td>
</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> <Button
<StatusIcon status={systemStatus.npm ? 'ok' : 'bad'} /> size="sm"
</td> variant="dark"
<td className="bb-acp-stats-value"> onClick={loadSystemStatus}
<Button disabled={systemLoading}
size="sm" >
variant="dark" {t('system.recheck')}
onClick={loadSystemStatus} </Button>
disabled={systemLoading} </td>
> </tr>
{t('system.recheck')} <tr>
</Button> <td>Node</td>
</td> <td className="bb-acp-stats-value">
</tr> {systemStatus.node || t('system.not_found')}
<tr> </td>
<td>tar</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> {systemStatus.min_versions?.node || '—'}
{systemStatus.tar || t('system.not_found')} </td>
</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"></td> {systemStatus.node_version || '—'}
<td className="bb-acp-stats-value"> </td>
{systemStatus.tar_version || '—'} <td className="bb-acp-stats-value">
</td> <StatusIcon status={systemStatus.node ? 'ok' : 'bad'} />
<td className="bb-acp-stats-value"> </td>
<StatusIcon status={systemStatus.tar ? 'ok' : 'bad'} /> <td className="bb-acp-stats-value">
</td> <Button
<td className="bb-acp-stats-value"> size="sm"
<Button variant="dark"
size="sm" onClick={loadSystemStatus}
variant="dark" disabled={systemLoading}
onClick={loadSystemStatus} >
disabled={systemLoading} {t('system.recheck')}
> </Button>
{t('system.recheck')} </td>
</Button> </tr>
</td> <tr>
</tr> <td>npm</td>
<tr> <td className="bb-acp-stats-value">
<td>rsync</td> {systemStatus.npm || t('system.not_found')}
<td className="bb-acp-stats-value"> </td>
{systemStatus.rsync || t('system.not_found')} <td className="bb-acp-stats-value">
</td> {systemStatus.min_versions?.npm || '—'}
<td className="bb-acp-stats-value"></td> </td>
<td className="bb-acp-stats-value"> <td className="bb-acp-stats-value">
{systemStatus.rsync_version || '—'} {systemStatus.npm_version || '—'}
</td> </td>
<td className="bb-acp-stats-value"> <td className="bb-acp-stats-value">
<StatusIcon status={systemStatus.rsync ? 'ok' : 'bad'} /> <StatusIcon status={systemStatus.npm ? 'ok' : 'bad'} />
</td> </td>
<td className="bb-acp-stats-value"> <td className="bb-acp-stats-value">
<Button <Button
size="sm" size="sm"
variant="dark" variant="dark"
onClick={loadSystemStatus} onClick={loadSystemStatus}
disabled={systemLoading} disabled={systemLoading}
> >
{t('system.recheck')} {t('system.recheck')}
</Button> </Button>
</td> </td>
</tr> </tr>
<tr> <tr>
<td>proc_* functions</td> <td>tar</td>
<td className="bb-acp-stats-value" colSpan={3}> <td className="bb-acp-stats-value">
{systemStatus.proc_functions {systemStatus.tar || t('system.not_found')}
? Object.entries(systemStatus.proc_functions) </td>
.filter(([, ok]) => !ok) <td className="bb-acp-stats-value"></td>
.map(([name]) => name) <td className="bb-acp-stats-value">
.join(', ') {systemStatus.tar_version || '—'}
: '—'} </td>
</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> <StatusIcon status={systemStatus.tar ? 'ok' : 'bad'} />
<StatusIcon </td>
status={ <td className="bb-acp-stats-value">
Boolean(systemStatus.proc_functions) && <Button
Object.values(systemStatus.proc_functions).every(Boolean) size="sm"
? 'ok' variant="dark"
: 'bad' onClick={loadSystemStatus}
} disabled={systemLoading}
/> >
</td> {t('system.recheck')}
<td className="bb-acp-stats-value"> </Button>
<Button </td>
size="sm" </tr>
variant="dark" <tr>
onClick={loadSystemStatus} <td>rsync</td>
disabled={systemLoading} <td className="bb-acp-stats-value">
> {systemStatus.rsync || t('system.not_found')}
{t('system.recheck')} </td>
</Button> <td className="bb-acp-stats-value"></td>
</td> <td className="bb-acp-stats-value">
</tr> {systemStatus.rsync_version || '—'}
<tr> </td>
<td>{t('system.storage_writable')}</td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value">storage/</td> <StatusIcon status={systemStatus.rsync ? 'ok' : 'bad'} />
<td className="bb-acp-stats-value"></td> </td>
<td className="bb-acp-stats-value"></td> <td className="bb-acp-stats-value">
<td className="bb-acp-stats-value"> <Button
<StatusIcon status={systemStatus.storage_writable ? 'ok' : 'bad'} /> size="sm"
</td> variant="dark"
<td className="bb-acp-stats-value"> onClick={loadSystemStatus}
<Button disabled={systemLoading}
size="sm" >
variant="dark" {t('system.recheck')}
onClick={loadSystemStatus} </Button>
disabled={systemLoading} </td>
> </tr>
{t('system.recheck')} <tr>
</Button> <td>proc_* functions</td>
</td> <td className="bb-acp-stats-value" colSpan={3}>
</tr> {systemStatus.proc_functions
<tr> ? Object.entries(systemStatus.proc_functions)
<td>{t('system.updates_writable')}</td> .filter(([, ok]) => !ok)
<td className="bb-acp-stats-value">storage/app/updates</td> .map(([name]) => name)
<td className="bb-acp-stats-value"></td> .join(', ')
<td className="bb-acp-stats-value"></td> : '—'}
<td className="bb-acp-stats-value"> </td>
<StatusIcon status={systemStatus.updates_writable ? 'ok' : 'bad'} /> <td className="bb-acp-stats-value">
</td> <StatusIcon
<td className="bb-acp-stats-value"> status={
<Button Boolean(systemStatus.proc_functions) &&
size="sm" Object.values(systemStatus.proc_functions).every(Boolean)
variant="dark" ? 'ok'
onClick={loadSystemStatus} : 'bad'
disabled={systemLoading} }
> />
{t('system.recheck')} </td>
</Button> <td className="bb-acp-stats-value">
</td> <Button
</tr> size="sm"
</tbody> variant="dark"
</table> onClick={loadSystemStatus}
</div> disabled={systemLoading}
</div> >
{t('system.recheck')}
</Button>
</td>
</tr>
<tr>
<td>{t('system.storage_writable')}</td>
<td className="bb-acp-stats-value">storage/</td>
<td className="bb-acp-stats-value"></td>
<td className="bb-acp-stats-value"></td>
<td className="bb-acp-stats-value">
<StatusIcon status={systemStatus.storage_writable ? 'ok' : 'bad'} />
</td>
<td className="bb-acp-stats-value">
<Button
size="sm"
variant="dark"
onClick={loadSystemStatus}
disabled={systemLoading}
>
{t('system.recheck')}
</Button>
</td>
</tr>
<tr>
<td>{t('system.updates_writable')}</td>
<td className="bb-acp-stats-value">storage/app/updates</td>
<td className="bb-acp-stats-value"></td>
<td className="bb-acp-stats-value"></td>
<td className="bb-acp-stats-value">
<StatusIcon status={systemStatus.updates_writable ? 'ok' : 'bad'} />
</td>
<td className="bb-acp-stats-value">
<Button
size="sm"
variant="dark"
onClick={loadSystemStatus}
disabled={systemLoading}
>
{t('system.recheck')}
</Button>
</td>
</tr>
</tbody>
</table>
)}
</div>
</div>
)}
</Col>
</Row>
)} )}
</Tab> </Tab>
</Tabs> </Tabs>

5
scripts/hooks/pre-commit Normal file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
# Fail fast if the database is unreachable.
php artisan version:fetch >/dev/null

View File

@@ -398,25 +398,20 @@ it('handles migration failure', function (): void {
File::shouldReceive('directories')->andReturn(['/tmp/extract/speedbb']); File::shouldReceive('directories')->andReturn(['/tmp/extract/speedbb']);
File::shouldReceive('copyDirectory')->andReturnTrue(); File::shouldReceive('copyDirectory')->andReturnTrue();
$artisanPath = base_path('artisan'); putenv('SYSTEM_UPDATE_PHP_BINARY=/nope');
$originalArtisan = file_get_contents($artisanPath); $_ENV['SYSTEM_UPDATE_PHP_BINARY'] = '/nope';
file_put_contents($artisanPath, "#!/usr/bin/env php\n<?php exit(1);\n"); $_SERVER['SYSTEM_UPDATE_PHP_BINARY'] = '/nope';
chmod($artisanPath, 0755);
withFakeBin([ withFakeBin([
'tar' => "#!/bin/sh\nexit 0\n", 'tar' => "#!/bin/sh\nexit 0\n",
'composer' => "#!/bin/sh\nexit 0\n", 'composer' => "#!/bin/sh\nexit 0\n",
'npm' => "#!/bin/sh\nexit 0\n", 'npm' => "#!/bin/sh\nexit 0\n",
], function () use ($artisanPath, $originalArtisan): void { ], function (): void {
try { Sanctum::actingAs(makeAdminForSystemUpdate());
Sanctum::actingAs(makeAdminForSystemUpdate()); $response = $this->postJson('/api/system/update');
$response = $this->postJson('/api/system/update');
$response->assertStatus(500); $response->assertStatus(500);
$response->assertJsonFragment(['message' => 'Migrations failed.']); $response->assertJsonFragment(['message' => 'Migrations failed.']);
} finally {
file_put_contents($artisanPath, $originalArtisan);
}
}); });
}); });
@@ -424,6 +419,9 @@ it('handles fallback copyDirectory update success', function (): void {
putenv('GITEA_OWNER=acme'); putenv('GITEA_OWNER=acme');
putenv('GITEA_REPO=speedbb'); putenv('GITEA_REPO=speedbb');
putenv('GITEA_API_BASE=https://git.example.test/api/v1'); putenv('GITEA_API_BASE=https://git.example.test/api/v1');
putenv('SYSTEM_UPDATE_PHP_BINARY=php');
$_ENV['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
$_SERVER['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
Http::fake([ Http::fake([
'https://git.example.test/api/v1/repos/acme/speedbb/releases/latest' => Http::response([ 'https://git.example.test/api/v1/repos/acme/speedbb/releases/latest' => Http::response([
@@ -438,25 +436,21 @@ it('handles fallback copyDirectory update success', function (): void {
File::shouldReceive('directories')->andReturn(['/tmp/extract/speedbb']); File::shouldReceive('directories')->andReturn(['/tmp/extract/speedbb']);
File::shouldReceive('copyDirectory')->andReturnTrue(); File::shouldReceive('copyDirectory')->andReturnTrue();
$artisanPath = base_path('artisan'); putenv('SYSTEM_UPDATE_PHP_BINARY=php');
$originalArtisan = file_get_contents($artisanPath); $_ENV['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
file_put_contents($artisanPath, "#!/usr/bin/env php\n<?php exit(0);\n"); $_SERVER['SYSTEM_UPDATE_PHP_BINARY'] = 'php';
chmod($artisanPath, 0755);
withFakeBin([ withFakeBin([
'tar' => "#!/bin/sh\nexit 0\n", 'tar' => "#!/bin/sh\nexit 0\n",
'composer' => "#!/bin/sh\nexit 0\n", 'composer' => "#!/bin/sh\nexit 0\n",
'npm' => "#!/bin/sh\nexit 0\n", 'npm' => "#!/bin/sh\nexit 0\n",
], function () use ($artisanPath, $originalArtisan): void { 'php' => "#!/bin/sh\nexit 0\n",
try { ], function (): void {
Sanctum::actingAs(makeAdminForSystemUpdate()); Sanctum::actingAs(makeAdminForSystemUpdate());
$response = $this->postJson('/api/system/update'); $response = $this->postJson('/api/system/update');
$response->assertOk(); $response->assertOk();
$response->assertJsonFragment(['message' => 'Update finished.']); $response->assertJsonFragment(['message' => 'Update finished.']);
$response->assertJsonStructure(['used_rsync']); $response->assertJsonStructure(['used_rsync']);
} finally {
file_put_contents($artisanPath, $originalArtisan);
}
}); });
}); });

View File

@@ -1,155 +1,109 @@
<?php <?php
namespace s9e\TextFormatter { use App\Actions\BbcodeFormatter;
class Parser
{ it('returns empty string for null and empty input', function (): void {
public function parse(string $text): string expect(BbcodeFormatter::format(null))->toBe('');
{ expect(BbcodeFormatter::format(''))->toBe('');
return '<r/>'; });
}
it('formats bbcode content', function (): void {
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
$parserProp->setAccessible(true);
$parserProp->setValue(
\Mockery::mock(\s9e\TextFormatter\Parser::class)
->shouldReceive('parse')
->andReturn('<r/>')
->getMock()
);
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
$rendererProp->setAccessible(true);
$rendererProp->setValue(
\Mockery::mock(\s9e\TextFormatter\Renderer::class)
->shouldReceive('render')
->andReturn('<b>Bold</b>')
->getMock()
);
$html = BbcodeFormatter::format('[b]Bold[/b]');
expect($html)->toContain('<b>');
});
it('initializes parser and renderer when not set', function (): void {
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
$parserProp->setAccessible(true);
$parserProp->setValue(null);
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
$rendererProp->setAccessible(true);
$rendererProp->setValue(null);
$html = BbcodeFormatter::format('[b]Bold[/b]');
expect($html)->toBeString();
expect($parserProp->getValue())->not->toBeNull();
expect($rendererProp->getValue())->not->toBeNull();
});
it('build returns parser and renderer', function (): void {
putenv('BBCODE_FORCE_FAIL');
unset($_ENV['BBCODE_FORCE_FAIL'], $_SERVER['BBCODE_FORCE_FAIL']);
$ref = new ReflectionMethod(BbcodeFormatter::class, 'build');
$ref->setAccessible(true);
$result = $ref->invoke(null);
expect($result)->toBeArray();
expect($result)->toHaveCount(2);
expect($result[0])->toBeInstanceOf(\s9e\TextFormatter\Parser::class);
expect($result[1])->toBeInstanceOf(\s9e\TextFormatter\Renderer::class);
});
it('formats with real build when parser is reset', function (): void {
putenv('BBCODE_FORCE_FAIL');
unset($_ENV['BBCODE_FORCE_FAIL'], $_SERVER['BBCODE_FORCE_FAIL']);
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
$parserProp->setAccessible(true);
$parserProp->setValue(null);
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
$rendererProp->setAccessible(true);
$rendererProp->setValue(null);
$html = BbcodeFormatter::format('[b]Bold[/b]');
expect($html)->toBeString();
expect($parserProp->getValue())->not->toBeNull();
expect($rendererProp->getValue())->not->toBeNull();
});
it('throws when bbcode formatter cannot initialize', function (): void {
putenv('BBCODE_FORCE_FAIL=1');
$_ENV['BBCODE_FORCE_FAIL'] = '1';
$_SERVER['BBCODE_FORCE_FAIL'] = '1';
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
$parserProp->setAccessible(true);
$parserProp->setValue(null);
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
$rendererProp->setAccessible(true);
$rendererProp->setValue(null);
try {
BbcodeFormatter::format('test');
$this->fail('Expected exception not thrown.');
} catch (Throwable $e) {
expect($e)->toBeInstanceOf(RuntimeException::class);
} finally {
putenv('BBCODE_FORCE_FAIL');
unset($_ENV['BBCODE_FORCE_FAIL'], $_SERVER['BBCODE_FORCE_FAIL']);
} }
});
class Renderer afterEach(function (): void {
{ \Mockery::close();
public function render(string $xml): string });
{
return '<p>ok</p>';
}
}
class Configurator
{
public static bool $returnEmpty = false;
public object $plugins;
public object $tags;
public function __construct()
{
$this->plugins = new class {
public function load(string $name): object
{
return new class {
public function addFromRepository(string $name): self
{
return $this;
}
};
}
};
$this->tags = new class implements \ArrayAccess {
public array $store = [];
public function add($name)
{
$obj = new \stdClass();
$this->store[$name] = $obj;
return $obj;
}
public function offsetExists($offset): bool
{
return array_key_exists($offset, $this->store);
}
public function offsetGet($offset): mixed
{
return $this->store[$offset] ?? null;
}
public function offsetSet($offset, $value): void
{
$this->store[$offset] = $value;
}
public function offsetUnset($offset): void
{
unset($this->store[$offset]);
}
};
$this->tags['QUOTE'] = new \stdClass();
}
public function finalize(): array
{
if (self::$returnEmpty) {
return [];
}
return [
'parser' => new Parser(),
'renderer' => new Renderer(),
];
}
}
}
namespace {
use App\Actions\BbcodeFormatter;
it('returns empty string for null and empty input', function (): void {
expect(BbcodeFormatter::format(null))->toBe('');
expect(BbcodeFormatter::format(''))->toBe('');
});
it('formats bbcode content', function (): void {
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
$parserProp->setAccessible(true);
$parserProp->setValue(
\Mockery::mock(\s9e\TextFormatter\Parser::class)
->shouldReceive('parse')
->andReturn('<r/>')
->getMock()
);
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
$rendererProp->setAccessible(true);
$rendererProp->setValue(
\Mockery::mock(\s9e\TextFormatter\Renderer::class)
->shouldReceive('render')
->andReturn('<b>Bold</b>')
->getMock()
);
$html = BbcodeFormatter::format('[b]Bold[/b]');
expect($html)->toContain('<b>');
});
it('initializes parser and renderer when not set', function (): void {
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
$parserProp->setAccessible(true);
$parserProp->setValue(null);
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
$rendererProp->setAccessible(true);
$rendererProp->setValue(null);
$html = BbcodeFormatter::format('[b]Bold[/b]');
expect($html)->toBeString();
expect($parserProp->getValue())->not->toBeNull();
expect($rendererProp->getValue())->not->toBeNull();
});
it('throws when bbcode formatter cannot initialize', function (): void {
\s9e\TextFormatter\Configurator::$returnEmpty = true;
$parserProp = new ReflectionProperty(BbcodeFormatter::class, 'parser');
$parserProp->setAccessible(true);
$parserProp->setValue(null);
$rendererProp = new ReflectionProperty(BbcodeFormatter::class, 'renderer');
$rendererProp->setAccessible(true);
$rendererProp->setValue(null);
try {
BbcodeFormatter::format('test');
$this->fail('Expected exception not thrown.');
} catch (Throwable $e) {
expect($e)->toBeInstanceOf(RuntimeException::class);
} finally {
\s9e\TextFormatter\Configurator::$returnEmpty = false;
}
});
afterEach(function (): void {
\Mockery::close();
});
}