Paillasse/portail/tests/Reels/preparer-parcours.php

43 lines
1.7 KiB
PHP
Raw Normal View History

<?php
// Données de test du parcours réel (étape 11), à lancer sur le serveur :
// sudo -u www-data HOME=/tmp php8.3 artisan tinker tests/Reels/preparer-parcours.php
// Les identifiants générés vont dans un fichier 600 lu par parcours-lab.py ;
// ils ne sont jamais affichés. Supprimer ces données après le test.
use App\Models\Classe;
use App\Models\Eleve;
use App\Models\Etablissement;
use App\Models\Lab;
use App\Models\Seance;
use App\Models\User;
use App\Support\CodeLisible;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
$motDePasse = Str::password(24, symbols: false);
$code = CodeLisible::genere(6);
$etablissement = Etablissement::create(['nom' => 'Lycée Test Étape 11', 'ville' => 'Test']);
$prof = User::create(['name' => 'Prof Test 11', 'email' => 'prof11@syllabus.test', 'password' => $motDePasse, 'etablissement_id' => $etablissement->id]);
$classe = Classe::create(['etablissement_id' => $etablissement->id, 'user_id' => $prof->id, 'nom' => 'Classe Test 11', 'formation' => 'Test']);
Eleve::create(['classe_id' => $classe->id, 'prenom' => 'Testeur', 'identifiant' => 'testeur11', 'code_secret' => Hash::make($code), 'jeton_qr' => Str::random(32)]);
$seance = Seance::create([
'classe_id' => $classe->id,
'lab_id' => Lab::where('identifiant', '08-deux-lan-routeur')->value('id'),
'statut' => Seance::SALLE_ATTENTE,
'demarree_a' => now(),
]);
$fichier = '/tmp/parcours-identifiants.json';
file_put_contents($fichier, json_encode([
'prof_email' => $prof->email,
'prof_mot_de_passe' => $motDePasse,
'eleve_identifiant' => 'testeur11',
'eleve_code' => $code,
'seance_id' => $seance->id,
]));
chmod($fichier, 0600);
echo "données de test prêtes (séance {$seance->id})\n";