Compare commits

...

4 Commits

Author SHA1 Message Date
admin 98be743f35 Add MA200 signal overview for top altcoins 2025-11-17 16:16:50 +01:00
admin 5da0df88e0 Merge pull request #5 from metacube2/codex/projekt-fur-bandreservierung-erstellen-rx0gem
Add CLI functional test harness
2025-11-17 15:36:57 +01:00
admin 52c796d2db Add CLI functional test harness 2025-11-17 15:36:28 +01:00
admin bc9e3367b7 Merge pull request #4 from metacube2/codex/projekt-fur-bandreservierung-erstellen
Implement Bandreservierung Plattform
2025-11-17 15:05:10 +01:00
2 changed files with 649 additions and 0 deletions
+342
View File
@@ -0,0 +1,342 @@
<?php
$altcoins = [
[
'name' => 'Ethereum (ETH)',
'symbol' => 'ETH',
'price' => 3725.42,
'ma200' => 3450.15,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'BNB',
'symbol' => 'BNB',
'price' => 598.12,
'ma200' => 612.77,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'Solana (SOL)',
'symbol' => 'SOL',
'price' => 158.34,
'ma200' => 143.05,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'XRP',
'symbol' => 'XRP',
'price' => 0.57,
'ma200' => 0.63,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'Dogecoin (DOGE)',
'symbol' => 'DOGE',
'price' => 0.19,
'ma200' => 0.15,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'Cardano (ADA)',
'symbol' => 'ADA',
'price' => 0.48,
'ma200' => 0.62,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'Avalanche (AVAX)',
'symbol' => 'AVAX',
'price' => 47.22,
'ma200' => 44.61,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'Polkadot (DOT)',
'symbol' => 'DOT',
'price' => 8.81,
'ma200' => 7.29,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'Chainlink (LINK)',
'symbol' => 'LINK',
'price' => 17.02,
'ma200' => 18.40,
'last_update' => '2024-04-21 14:00 UTC',
],
[
'name' => 'Polygon (MATIC)',
'symbol' => 'MATIC',
'price' => 0.92,
'ma200' => 0.98,
'last_update' => '2024-04-21 14:00 UTC',
],
];
function determineSignal(float $price, float $ma200): array
{
if ($price >= $ma200) {
return ['LONG', 'Preis notiert über dem 200-Tage-Durchschnitt.'];
}
return ['SHORT', 'Preis notiert unter dem 200-Tage-Durchschnitt.'];
}
function formatNumber(float $value, int $decimals = 2): string
{
return number_format($value, $decimals, ',', '.');
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Top 10 Altcoins MA200 Signale</title>
<style>
:root {
color-scheme: light dark;
--bg: #0f172a;
--fg: #f8fafc;
--card: #1e293b;
--accent: #10b981;
--warning: #f59e0b;
--danger: #ef4444;
--muted: #94a3b8;
}
* {
box-sizing: border-box;
font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
body {
margin: 0;
min-height: 100vh;
background: radial-gradient(circle at top, rgba(16,185,129,0.25), transparent 55%),
var(--bg);
color: var(--fg);
display: flex;
align-items: center;
justify-content: center;
padding: 2rem 1rem;
}
main {
width: min(1100px, 100%);
background: rgba(15,23,42,0.85);
border: 1px solid rgba(148,163,184,0.2);
border-radius: 24px;
box-shadow: 0 15px 60px rgba(0,0,0,0.45);
padding: 2rem 2.5rem 2.5rem;
}
header {
display: flex;
flex-direction: column;
gap: 0.5rem;
margin-bottom: 2rem;
}
header h1 {
margin: 0;
font-size: clamp(2rem, 4vw, 3rem);
line-height: 1.2;
}
header p {
margin: 0;
color: var(--muted);
}
table {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
}
thead th {
text-align: left;
font-size: 0.85rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--muted);
border-bottom: 1px solid rgba(148,163,184,0.2);
padding-bottom: 0.75rem;
}
tbody td {
padding: 1rem 0;
border-bottom: 1px solid rgba(148,163,184,0.1);
}
tbody tr:last-child td {
border-bottom: none;
}
.symbol {
color: var(--muted);
font-size: 0.9rem;
}
.price {
font-variant-numeric: tabular-nums;
}
.signal {
display: inline-flex;
align-items: center;
gap: 0.5rem;
padding: 0.35rem 0.75rem;
border-radius: 999px;
font-size: 0.9rem;
font-weight: 600;
letter-spacing: 0.05em;
}
.signal-long {
background: rgba(16,185,129,0.15);
border: 1px solid rgba(16,185,129,0.5);
color: var(--accent);
}
.signal-short {
background: rgba(239,68,68,0.15);
border: 1px solid rgba(239,68,68,0.5);
color: var(--danger);
}
.telegram-card {
margin-top: 2rem;
background: rgba(30,41,59,0.9);
border: 1px solid rgba(59,130,246,0.4);
border-radius: 18px;
padding: 1.5rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.telegram-card h2 {
margin: 0;
font-size: 1.2rem;
}
.telegram-card p {
margin: 0;
color: var(--muted);
line-height: 1.5;
}
.telegram-card pre {
margin: 0;
padding: 1rem;
background: rgba(15,23,42,0.8);
border-radius: 12px;
border: 1px solid rgba(148,163,184,0.15);
font-size: 0.9rem;
white-space: pre-wrap;
}
@media (max-width: 720px) {
main {
padding: 1.5rem;
}
table, thead, tbody, tr, td, th {
display: block;
}
thead {
display: none;
}
tbody tr {
border: 1px solid rgba(148,163,184,0.2);
border-radius: 18px;
padding: 1rem 1.25rem;
margin-bottom: 1rem;
}
tbody td {
border: none;
padding: 0.35rem 0;
}
tbody td::before {
content: attr(data-label);
display: block;
font-size: 0.75rem;
letter-spacing: 0.08em;
text-transform: uppercase;
color: var(--muted);
margin-bottom: 0.2rem;
}
}
</style>
</head>
<body>
<main>
<header>
<h1>Top 10 Altcoins &amp; MA200 Signale</h1>
<p>Überblick über mögliche Einstiegszonen basierend auf dem 200-Tage-Durchschnitt. Die Signale (Long oder Short)
können direkt an den Telegram-Channel weitergeleitet werden.</p>
</header>
<table>
<thead>
<tr>
<th>Asset</th>
<th>Preis (USD)</th>
<th>MA200 (USD)</th>
<th>Abweichung</th>
<th>Signal</th>
<th>Zuletzt aktualisiert</th>
</tr>
</thead>
<tbody>
<?php foreach ($altcoins as $coin):
[$signal, $reason] = determineSignal($coin['price'], $coin['ma200']);
$diff = $coin['price'] - $coin['ma200'];
$diffPercent = ($coin['ma200'] > 0)
? ($diff / $coin['ma200']) * 100
: 0;
?>
<tr>
<td data-label="Asset">
<strong><?php echo htmlspecialchars($coin['name']); ?></strong>
<div class="symbol"><?php echo htmlspecialchars($coin['symbol']); ?></div>
</td>
<td data-label="Preis" class="price">$ <?php echo formatNumber($coin['price']); ?></td>
<td data-label="MA200" class="price">$ <?php echo formatNumber($coin['ma200']); ?></td>
<td data-label="Abweichung">
<?php echo ($diff >= 0 ? '+' : '-') . formatNumber(abs($diff)); ?>
<span class="symbol">(<?php echo ($diffPercent >= 0 ? '+' : '-') . formatNumber(abs($diffPercent)); ?> %)</span>
</td>
<td data-label="Signal">
<span class="signal signal-<?php echo strtolower($signal); ?>">
<?php echo $signal; ?>
</span>
<div class="symbol"><?php echo $reason; ?></div>
</td>
<td data-label="Update" class="symbol"><?php echo htmlspecialchars($coin['last_update']); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
$signals = array_map(function ($coin) {
[$signal, $reason] = determineSignal($coin['price'], $coin['ma200']);
return sprintf('%s (%s): %s %s', $coin['name'], $coin['symbol'], $signal, $reason);
}, $altcoins);
?>
<section class="telegram-card">
<h2>Telegram Broadcast</h2>
<p>Kopiere die Zusammenfassung, um sie in deinem Signal-Channel zu posten, sobald eine MA200-Überschreitung
stattfindet.</p>
<pre><?php echo htmlspecialchars(implode("\n", $signals)); ?></pre>
</section>
</main>
</body>
</html>
+307
View File
@@ -0,0 +1,307 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
require_once __DIR__ . '/includes/config.php';
$options = array_slice($argv, 1);
if (in_array('--fresh', $options, true) && file_exists(DB_PATH)) {
unlink(DB_PATH);
echo "Bestehende Datenbank entfernt wird neu initialisiert.\n";
}
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/auth.php';
require_once __DIR__ . '/includes/email.php';
if (!isset($_SERVER['REQUEST_METHOD'])) {
$_SERVER['REQUEST_METHOD'] = 'GET';
}
final class FunctionalTestRunner
{
private PDO $pdo;
private array $results = [];
private int $passed = 0;
private int $failed = 0;
public function __construct(PDO $pdo)
{
$this->pdo = $pdo;
}
public function run(string $title, callable $test, bool $transactional = false): void
{
try {
if ($transactional) {
$this->pdo->beginTransaction();
}
$details = $test($this->pdo);
if ($transactional && $this->pdo->inTransaction()) {
$this->pdo->rollBack();
}
$this->record('PASS', $title, $details);
} catch (Throwable $e) {
if ($transactional && $this->pdo->inTransaction()) {
$this->pdo->rollBack();
}
$this->record('FAIL', $title, $e->getMessage());
}
}
private function record(string $status, string $title, ?string $details): void
{
$status === 'PASS' ? $this->passed++ : $this->failed++;
$this->results[] = [
'status' => $status,
'title' => $title,
'details' => $details ?? '',
];
}
public function summary(): void
{
foreach ($this->results as $result) {
$symbol = $result['status'] === 'PASS' ? '\u{2705}' : '\u{274C}';
echo sprintf("%s %s\n", $symbol, $result['title']);
if ($result['details'] !== '') {
echo sprintf(" %s\n", $result['details']);
}
}
echo str_repeat('-', 50) . "\n";
echo sprintf("Ergebnis: %d bestanden, %d fehlgeschlagen\n", $this->passed, $this->failed);
exit($this->failed === 0 ? 0 : 1);
}
}
function renderPage(string $file, array $get = [], array $post = []): string
{
$previousGet = $_GET ?? [];
$previousPost = $_POST ?? [];
$previousMethod = $_SERVER['REQUEST_METHOD'] ?? 'GET';
$_GET = $get;
$_POST = $post;
$_SERVER['REQUEST_METHOD'] = empty($post) ? 'GET' : 'POST';
ob_start();
include __DIR__ . '/' . ltrim($file, '/');
$output = ob_get_clean();
$_GET = $previousGet;
$_POST = $previousPost;
$_SERVER['REQUEST_METHOD'] = $previousMethod;
return $output;
}
function restartSession(): void
{
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
}
$pdo = db();
$runner = new FunctionalTestRunner($pdo);
$runner->run('Storage-Verzeichnis vorhanden', function () {
if (!is_dir(__DIR__ . '/storage')) {
throw new RuntimeException('Ordner storage fehlt.');
}
return 'Pfad: ' . realpath(__DIR__ . '/storage');
});
$runner->run('Datenbank initialisiert', function (PDO $pdo) {
if (!file_exists(DB_PATH)) {
throw new RuntimeException('database.sqlite wurde nicht erstellt.');
}
$tables = $pdo->query("SELECT name FROM sqlite_master WHERE type='table'")
->fetchAll(PDO::FETCH_COLUMN);
$required = ['users', 'bands', 'requests', 'reviews', 'settings'];
foreach ($required as $table) {
if (!in_array($table, $tables, true)) {
throw new RuntimeException('Tabelle ' . $table . ' fehlt.');
}
}
return 'Tabellen gefunden: ' . implode(', ', $required);
});
$runner->run('Seed-Daten verfügbar', function (PDO $pdo) {
$users = (int) $pdo->query('SELECT COUNT(*) FROM users')->fetchColumn();
$bands = (int) $pdo->query('SELECT COUNT(*) FROM bands')->fetchColumn();
if ($users < 3 || $bands < 2) {
throw new RuntimeException('Seed-Daten unvollständig.');
}
return sprintf('Users: %d, Bands: %d', $users, $bands);
});
$runner->run('Login / Logout Workflow', function () {
if (!login('david@example.com', 'secret123')) {
throw new RuntimeException('Login schlug fehl.');
}
$user = currentUser();
if (!$user || $user['role'] !== 'kunde') {
throw new RuntimeException('Session liefert keinen Kunden.');
}
logout();
restartSession();
if (currentUser()) {
throw new RuntimeException('Logout hat Session nicht geleert.');
}
return 'Login erfolgreich für ' . $user['name'];
});
$runner->run('Band-Filter & Durchschnitt', function () {
$bands = allBands(['genre' => 'Funk']);
if (!$bands) {
throw new RuntimeException('Filter lieferte keine Band.');
}
$rating = averageRating((int) $bands[0]['id']);
if ($rating === null) {
throw new RuntimeException('Keine Bewertung vorhanden.');
}
return sprintf('%d Bands, Ø Bewertung %.1f★', count($bands), $rating);
});
$runner->run('Medien & Verfügbarkeiten geladen', function () {
$media = bandMedia(1);
$availability = bandAvailability(1);
$reviews = bandReviews(1);
if (!$media || !$availability || !$reviews) {
throw new RuntimeException('Band 1 hat unvollständige Daten.');
}
return sprintf('Medien: %d, Slots: %d, Reviews: %d', count($media), count($availability), count($reviews));
});
$runner->run('Anfrage speichern (Transaktion)', function (PDO $pdo) {
$before = (int) $pdo->query('SELECT COUNT(*) FROM requests')->fetchColumn();
createRequest([
'band_id' => 1,
'user_id' => 3,
'event_date' => (new DateTimeImmutable('+60 days'))->format('Y-m-d'),
'location' => 'Teststadt',
'budget' => 4500,
'event_type' => 'Testevent',
'message' => 'Funktionstest Anfrage',
]);
$after = (int) $pdo->query('SELECT COUNT(*) FROM requests')->fetchColumn();
if ($after !== $before + 1) {
throw new RuntimeException('Anfrage wurde nicht gespeichert.');
}
return 'Requests gesamt (temporär): ' . $after;
}, true);
$runner->run('Bewertungen speichern & Eligibility', function (PDO $pdo) {
if (!eligibleForReview(1, 3)) {
throw new RuntimeException('User 3 sollte berechtigt sein.');
}
$before = (int) $pdo->query('SELECT COUNT(*) FROM reviews')->fetchColumn();
storeReview([
'band_id' => 1,
'user_id' => 3,
'rating' => 4,
'comment' => 'Testkommentar',
]);
$after = (int) $pdo->query('SELECT COUNT(*) FROM reviews')->fetchColumn();
if ($after !== $before + 1) {
throw new RuntimeException('Review wurde nicht gespeichert.');
}
return 'Reviews gesamt (temporär): ' . $after;
}, true);
$runner->run('Einstellungen lesen & aktualisieren', function () {
$current = settings();
$originalFee = $current['service_fee'] ?? '0';
updateSetting('service_fee', '12');
$updated = settings();
if (($updated['service_fee'] ?? null) !== '12') {
throw new RuntimeException('Service Fee konnte nicht aktualisiert werden.');
}
updateSetting('service_fee', $originalFee);
return 'Service Fee temporär auf 12 gesetzt.';
}, true);
$runner->run('Moderations-Aktionen', function (PDO $pdo) {
changeBandStatus(1, 'prüfung');
$status = $pdo->query('SELECT status FROM bands WHERE id = 1')->fetchColumn();
if ($status !== 'prüfung') {
throw new RuntimeException('Bandstatus änderte sich nicht.');
}
changeReviewStatus(1, 'gesperrt');
$reviewStatus = $pdo->query('SELECT status FROM reviews WHERE id = 1')->fetchColumn();
if ($reviewStatus !== 'gesperrt') {
throw new RuntimeException('Reviewstatus änderte sich nicht.');
}
return 'Statusänderungen durchgeführt.';
}, true);
$runner->run('Registrierung legt Band an', function (PDO $pdo) {
$email = 'tester+' . uniqid('', true) . '@example.com';
$result = register([
'name' => 'Functional Tester',
'email' => $email,
'password' => 'secret123',
'role' => 'band',
'city' => 'Testingen',
'band_name' => 'QA Ensemble',
'genre' => 'QA Funk',
]);
if (empty($result['token']) || strlen($result['token']) < 20) {
throw new RuntimeException('Verifikationstoken fehlt.');
}
$user = $pdo->prepare('SELECT id, role FROM users WHERE email = :email');
$user->execute([':email' => $email]);
$userRow = $user->fetch(PDO::FETCH_ASSOC);
if (!$userRow || $userRow['role'] !== 'band') {
throw new RuntimeException('User wurde nicht gespeichert.');
}
$band = $pdo->prepare('SELECT status FROM bands WHERE user_id = :id');
$band->execute([':id' => $userRow['id']]);
$bandRow = $band->fetch(PDO::FETCH_ASSOC);
if (!$bandRow || $bandRow['status'] !== 'prüfung') {
throw new RuntimeException('Bandprofil wurde nicht angelegt.');
}
return 'Token erstellt und Bandstatus "prüfung" bestätigt.';
}, true);
$runner->run('Startseite rendert fehlerfrei', function () {
$html = renderPage('index.php');
if (strpos($html, 'Aktive Bands') === false) {
throw new RuntimeException('Indexseite liefert keinen Inhalt.');
}
return 'HTML-Länge: ' . strlen($html) . ' Zeichen';
});
$runner->run('Band-Detailseite rendert', function () {
$html = renderPage('band-detail.php', ['id' => 1]);
if (strpos($html, 'Verfügbarkeit') === false) {
throw new RuntimeException('Band-Detailseite unvollständig.');
}
return 'HTML-Länge: ' . strlen($html) . ' Zeichen';
});
$runner->run('Anfrageformular rendert', function () {
$html = renderPage('anfrage.php', ['band_id' => 1]);
if (strpos($html, 'Anfrage an') === false) {
throw new RuntimeException('Anfrageformular fehlgeschlagen.');
}
return 'HTML-Länge: ' . strlen($html) . ' Zeichen';
});
$runner->run('E-Mail Logging (kein Versand)', function () {
$logDir = __DIR__ . '/storage/logs';
if (!is_dir($logDir)) {
mkdir($logDir, 0775, true);
}
$logFile = $logDir . '/mail.log';
$before = file_exists($logFile) ? filesize($logFile) : 0;
sendEmail('qa@example.com', 'Functional Test', 'Nur Logeintrag kein Versand.');
$after = filesize($logFile);
if ($after <= $before) {
throw new RuntimeException('Mail-Log wurde nicht aktualisiert.');
}
return 'Logeintrag ergänzt, Versand erfolgt nur als Datei.';
});
$runner->summary();