Enrichit le reporting SCORM/xAPI et met en conformité RGAA le player
SCORM/xAPI : - Ajoute l'export SCORM 2004 (3rd/4th edition) au choix, en plus du 1.2 par défaut : sépare completion_status/success_status (un échec reste "completed" au lieu de retomber à tort en "incomplete" comme force la 1.2), remonte aussi cmi.interactions.n.* par question répondue. - Fournit cmi.core.score.min/max (1.2 et 2004), calculé depuis les récompenses de quiz du jeu, pour que le LMS affiche un vrai pourcentage au lieu du score brut à tort étiqueté "%". - Libellés de verbes xAPI en français en plus de l'anglais. Accessibilité (RGAA/WCAG 2.1 AA) sur le player : - Navigation clavier des objets de scène "au clic"/"au survol" (tabindex, role, Entrée/Espace, focus/blur). - alt sur les images (nom auteur ou décoratif), aria-hidden sur les icônes seules, role="dialog"/aria-live sur les boîtes de dialogue/quiz. - Landmark <main> + titre de page, respect de prefers-reduced-motion. - Le quiz n'avance plus automatiquement après un délai fixe : bouton "Continuer →" explicite (RGAA 2.2.1). - Avertissement de contraste dans l'éditeur de style de dialogue. - Déclaration d'accessibilité téléchargeable depuis la modale d'export.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Déclaration d'accessibilité (voir publish/accessibility_declaration.py,
|
||||
routes/publish/accessibility_declaration.py) — un résumé de ce que le
|
||||
moteur implémente, PAS une certification RGAA complète."""
|
||||
from tests.test_auth import anon_client # noqa: F401
|
||||
|
||||
|
||||
def test_accessibility_declaration_route_returns_a_text_attachment(client, game):
|
||||
resp = client.get(f"/game/{game}/accessibility-declaration")
|
||||
assert resp.status_code == 200
|
||||
assert "text/plain" in resp.headers["Content-Type"]
|
||||
assert "attachment" in resp.headers["Content-Disposition"]
|
||||
|
||||
|
||||
def test_accessibility_declaration_mentions_the_game_name(client, game):
|
||||
import db
|
||||
game_name = db.game_meta(game)["name"]
|
||||
resp = client.get(f"/game/{game}/accessibility-declaration")
|
||||
text = resp.data.decode("utf-8")
|
||||
assert "Déclaration d'accessibilité" in text
|
||||
assert game_name in text
|
||||
|
||||
|
||||
def test_accessibility_declaration_route_is_isolated_like_other_game_routes(anon_client):
|
||||
"""Même garde d'accès que /game/<slug>/publish (core/auth_guard.py) —
|
||||
aucune vérification supplémentaire écrite pour cette route."""
|
||||
from tests.test_auth import _register, _confirm_2fa, _complete_onboarding, _cleanup_project
|
||||
|
||||
_register(anon_client, "a11ydeclarationisolation@example.com")
|
||||
_confirm_2fa(anon_client)
|
||||
_complete_onboarding(anon_client)
|
||||
try:
|
||||
resp = anon_client.get("/game/un-projet-qui-nest-pas-le-sien/accessibility-declaration")
|
||||
assert resp.status_code == 403
|
||||
finally:
|
||||
_cleanup_project("a11ydeclarationisolation@example.com")
|
||||
@@ -83,6 +83,70 @@ def test_export_scorm_index_html_embeds_the_xapi_config_when_set(client, game):
|
||||
assert 'src="static/js/play/offline/xapi-client.js"' in html
|
||||
|
||||
|
||||
def test_export_scorm_index_html_embeds_the_success_threshold(client, game):
|
||||
resp = client.post(f"/game/{game}/export-scorm")
|
||||
import io
|
||||
with zipfile.ZipFile(io.BytesIO(resp.data)) as zf:
|
||||
html = zf.read("index.html").decode("utf-8")
|
||||
assert "window.FORGE_SUCCESS_THRESHOLD_PERCENT = 70;" in html
|
||||
|
||||
db.set_success_threshold(game, 40)
|
||||
resp = client.post(f"/game/{game}/export-scorm")
|
||||
with zipfile.ZipFile(io.BytesIO(resp.data)) as zf:
|
||||
html = zf.read("index.html").decode("utf-8")
|
||||
assert "window.FORGE_SUCCESS_THRESHOLD_PERCENT = 40;" in html
|
||||
|
||||
|
||||
def test_export_scorm_defaults_to_scorm_1_2_manifest_and_wrapper(client, game):
|
||||
resp = client.post(f"/game/{game}/export-scorm")
|
||||
import io
|
||||
with zipfile.ZipFile(io.BytesIO(resp.data)) as zf:
|
||||
manifest = zf.read("imsmanifest.xml").decode("utf-8")
|
||||
html = zf.read("index.html").decode("utf-8")
|
||||
assert "<schemaversion>1.2</schemaversion>" in manifest
|
||||
assert 'adlcp:scormtype="sco"' in manifest
|
||||
assert 'src="static/js/play/offline/scorm-api.js"' in html
|
||||
assert 'src="static/js/play/offline/scorm2004-api.js"' not in html
|
||||
|
||||
|
||||
def test_export_scorm_2004_uses_the_2004_manifest_and_wrapper(client, game):
|
||||
db.set_scorm_version(game, "2004")
|
||||
resp = client.post(f"/game/{game}/export-scorm")
|
||||
import io
|
||||
with zipfile.ZipFile(io.BytesIO(resp.data)) as zf:
|
||||
names = set(zf.namelist())
|
||||
manifest = zf.read("imsmanifest.xml").decode("utf-8")
|
||||
html = zf.read("index.html").decode("utf-8")
|
||||
assert "static/js/play/offline/scorm2004-api.js" in names
|
||||
assert "<schemaversion>2004 4th Edition</schemaversion>" in manifest
|
||||
assert 'adlcp:scormType="sco"' in manifest
|
||||
assert 'src="static/js/play/offline/scorm2004-api.js"' in html
|
||||
assert 'src="static/js/play/offline/scorm-api.js"' not in html
|
||||
|
||||
|
||||
def test_export_scorm_index_html_embeds_the_max_quiz_score(client, game):
|
||||
"""Sans quête/question : max=0 (SCORM 1.2/2004 n'ont alors rien à
|
||||
barémer, voir static/js/play/offline/scorm-api.js)."""
|
||||
resp = client.post(f"/game/{game}/export-scorm")
|
||||
import io
|
||||
with zipfile.ZipFile(io.BytesIO(resp.data)) as zf:
|
||||
html = zf.read("index.html").decode("utf-8")
|
||||
assert "window.FORGE_MAX_QUIZ_SCORE = 0;" in html
|
||||
|
||||
quest = db.create_quest(game, "Une quête")
|
||||
db.set_quest_dialogues(game, quest["id"], {
|
||||
"nouvelle": [], "terminee": [],
|
||||
"en_cours": [
|
||||
{"type": "question", "text": "1+1 ?", "choices": ["1", "2"], "correct_index": 1, "reward_amount": 5},
|
||||
{"type": "question", "text": "2+2 ?", "choices": ["3", "4"], "correct_index": 1, "reward_amount": 7},
|
||||
],
|
||||
})
|
||||
resp = client.post(f"/game/{game}/export-scorm")
|
||||
with zipfile.ZipFile(io.BytesIO(resp.data)) as zf:
|
||||
html = zf.read("index.html").decode("utf-8")
|
||||
assert "window.FORGE_MAX_QUIZ_SCORE = 12;" in html
|
||||
|
||||
|
||||
def test_export_scorm_route_is_isolated_like_other_game_routes(anon_client):
|
||||
"""Même garde d'accès que /game/<slug>/publish (core/auth_guard.py) —
|
||||
aucune vérification supplémentaire écrite pour cette route."""
|
||||
|
||||
@@ -76,6 +76,38 @@ def test_render_scene_object_shows_idle_frame_pixel_positioned(tmp_game_slug_cle
|
||||
assert 'data-personnage="1"' in html
|
||||
|
||||
|
||||
def test_render_scene_object_alt_uses_the_authored_name_rgaa(tmp_game_slug_cleanup):
|
||||
"""RGAA/WCAG 1.1.1 : le nom donné par l'auteur (panneau "ℹ️
|
||||
Informations") sert d'alternative textuelle — jamais aucun attribut
|
||||
alt du tout n'était généré avant."""
|
||||
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
|
||||
obj_id = screens.add_scene_object(slug, screen_id, forge_character="zombie")
|
||||
screens.set_scene_object_name(slug, obj_id, "Zombie du hangar")
|
||||
obj = screens.get_scene_object(slug, obj_id)
|
||||
html = screens.render_scene_object(obj)
|
||||
assert 'alt="Zombie du hangar"' in html
|
||||
|
||||
|
||||
def test_render_scene_object_alt_is_empty_when_unnamed_rgaa(tmp_game_slug_cleanup):
|
||||
"""alt="" (décoratif) plutôt qu'aucun attribut du tout quand l'auteur
|
||||
n'a pas nommé l'objet."""
|
||||
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
|
||||
obj_id = screens.add_scene_object(slug, screen_id, forge_character="zombie")
|
||||
obj = screens.get_scene_object(slug, obj_id)
|
||||
html = screens.render_scene_object(obj)
|
||||
assert 'alt=""' in html
|
||||
|
||||
|
||||
def test_render_scene_object_fond_alt_is_always_empty_rgaa(tmp_game_slug_cleanup):
|
||||
"""Un "fond" est toujours décoratif — alt="" même s'il est nommé."""
|
||||
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
|
||||
obj_id = screens.add_scene_object(slug, screen_id, kind="fond", background_slug="foret")
|
||||
screens.set_scene_object_name(slug, obj_id, "Grand décor de fond")
|
||||
obj = screens.get_scene_object(slug, obj_id)
|
||||
html = screens.render_scene_object(obj)
|
||||
assert 'alt=""' in html
|
||||
|
||||
|
||||
def test_delete_scene_object_cleans_up_referencing_flow_nodes(tmp_game_slug_cleanup):
|
||||
slug, screen_id = _create_jeu2d_game(tmp_game_slug_cleanup)
|
||||
obj_id = screens.add_scene_object(slug, screen_id)
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""Seuil de réussite (voir db/games/get_success_threshold.py,
|
||||
routes/publish/scoring_settings.py) — détermine le statut SCORM/xAPI
|
||||
"reussi"/"echoue" en fin de partie, voir static/js/play/
|
||||
dialogue-box-controller.js::forgeComputeFinalScormStatus."""
|
||||
import db
|
||||
from tests.test_auth import anon_client # noqa: F401
|
||||
|
||||
|
||||
def test_scoring_settings_get_defaults_to_seventy_percent(client, game):
|
||||
resp = client.get(f"/game/{game}/scoring-settings")
|
||||
assert resp.status_code == 200
|
||||
assert resp.get_json() == {"success_threshold_percent": 70}
|
||||
|
||||
|
||||
def test_scoring_settings_post_then_get_round_trip(client, game):
|
||||
resp = client.post(f"/game/{game}/scoring-settings", json={"success_threshold_percent": 50})
|
||||
assert resp.status_code == 200
|
||||
assert resp.get_json() == {"ok": True, "success_threshold_percent": 50}
|
||||
|
||||
resp = client.get(f"/game/{game}/scoring-settings")
|
||||
assert resp.get_json() == {"success_threshold_percent": 50}
|
||||
|
||||
|
||||
def test_scoring_settings_post_clamps_out_of_range_values(client, game):
|
||||
client.post(f"/game/{game}/scoring-settings", json={"success_threshold_percent": 150})
|
||||
assert db.get_success_threshold(game) == 100
|
||||
|
||||
client.post(f"/game/{game}/scoring-settings", json={"success_threshold_percent": -10})
|
||||
assert db.get_success_threshold(game) == 0
|
||||
|
||||
|
||||
def test_scoring_settings_post_rejects_invalid_payload(client, game):
|
||||
resp = client.post(f"/game/{game}/scoring-settings", json={"success_threshold_percent": "abc"})
|
||||
assert resp.status_code == 400
|
||||
|
||||
|
||||
def test_scoring_settings_route_is_isolated_like_other_game_routes(anon_client):
|
||||
"""Même garde d'accès que /game/<slug>/publish (core/auth_guard.py) —
|
||||
aucune vérification supplémentaire écrite pour cette route."""
|
||||
from tests.test_auth import _register, _confirm_2fa, _complete_onboarding, _cleanup_project
|
||||
|
||||
_register(anon_client, "scoringsettingsisolation@example.com")
|
||||
_confirm_2fa(anon_client)
|
||||
_complete_onboarding(anon_client)
|
||||
try:
|
||||
resp = anon_client.get("/game/un-projet-qui-nest-pas-le-sien/scoring-settings")
|
||||
assert resp.status_code == 403
|
||||
resp = anon_client.post("/game/un-projet-qui-nest-pas-le-sien/scoring-settings", json={})
|
||||
assert resp.status_code == 403
|
||||
finally:
|
||||
_cleanup_project("scoringsettingsisolation@example.com")
|
||||
@@ -0,0 +1,44 @@
|
||||
"""Version SCORM exportée (voir db/games/get_scorm_version.py,
|
||||
routes/publish/scorm_version_settings.py) — '1.2' par défaut, '2004' au
|
||||
choix (sépare completion_status/success_status, voir static/js/play/
|
||||
offline/scorm2004-api.js)."""
|
||||
import db
|
||||
from tests.test_auth import anon_client # noqa: F401
|
||||
|
||||
|
||||
def test_scorm_version_get_defaults_to_one_dot_two(client, game):
|
||||
resp = client.get(f"/game/{game}/scorm-version")
|
||||
assert resp.status_code == 200
|
||||
assert resp.get_json() == {"scorm_version": "1.2"}
|
||||
|
||||
|
||||
def test_scorm_version_post_then_get_round_trip(client, game):
|
||||
resp = client.post(f"/game/{game}/scorm-version", json={"scorm_version": "2004"})
|
||||
assert resp.status_code == 200
|
||||
assert resp.get_json() == {"ok": True, "scorm_version": "2004"}
|
||||
|
||||
resp = client.get(f"/game/{game}/scorm-version")
|
||||
assert resp.get_json() == {"scorm_version": "2004"}
|
||||
|
||||
|
||||
def test_scorm_version_post_rejects_invalid_value(client, game):
|
||||
resp = client.post(f"/game/{game}/scorm-version", json={"scorm_version": "3rd-edition"})
|
||||
assert resp.status_code == 400
|
||||
assert db.get_scorm_version(game) == "1.2"
|
||||
|
||||
|
||||
def test_scorm_version_route_is_isolated_like_other_game_routes(anon_client):
|
||||
"""Même garde d'accès que /game/<slug>/publish (core/auth_guard.py) —
|
||||
aucune vérification supplémentaire écrite pour cette route."""
|
||||
from tests.test_auth import _register, _confirm_2fa, _complete_onboarding, _cleanup_project
|
||||
|
||||
_register(anon_client, "scormversionisolation@example.com")
|
||||
_confirm_2fa(anon_client)
|
||||
_complete_onboarding(anon_client)
|
||||
try:
|
||||
resp = anon_client.get("/game/un-projet-qui-nest-pas-le-sien/scorm-version")
|
||||
assert resp.status_code == 403
|
||||
resp = anon_client.post("/game/un-projet-qui-nest-pas-le-sien/scorm-version", json={})
|
||||
assert resp.status_code == 403
|
||||
finally:
|
||||
_cleanup_project("scormversionisolation@example.com")
|
||||
Reference in New Issue
Block a user