"""Pytest-tesztek a jmap.py Joomla manifest -> deployed-path mapperhez. Minden teszt egy szintetikus, minimál kicsomagolt bővítmény-csomagot épít fel tmp_path alatt (manifest-XML + pár dummy forrásfájl), lefuttatja a mappinget, és a kapott docroot-fát ellenőrzi a Joomla 3.x installer-szabályok szerint. """ from __future__ import annotations import subprocess import sys from pathlib import Path import pytest import jmap def _write(path: Path, content: str = "") -> None: path.parent.mkdir(parents=True, exist_ok=True) path.write_text(content, encoding="utf-8") def _run(package_dir: Path, out_dir: Path) -> list[jmap.CopyOp]: manifest_path = jmap.find_manifest(package_dir) ops = jmap.build_operations(manifest_path, out_dir) jmap.execute(ops) return ops # --------------------------------------------------------------------------- # component: site + admin + media + languages # --------------------------------------------------------------------------- def test_component_site_admin_media_language(tmp_path: Path) -> None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "com_hello.xml", """ com_hello helloworld.php controllers helloworld.php en-GB/en-GB.com_hello.sys.ini images en-GB/en-GB.com_hello.ini """, ) _write(pkg / "sitefiles/helloworld.php", " emberi megjelenítő-cím # volt, nem a gépi elemnév; a helyes forrás a ill. # a nyelvi fájlnév/scriptfile-mintázat/name-fallback prioritási láncban). # --------------------------------------------------------------------------- def test_component_name_from_files_folder_com_prefix(tmp_path: Path) -> None: """Elsődleges forrás: -- a emberi cím, eltér.""" pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "manifest.xml", """ Totally Human Display Title index.html """, ) _write(pkg / "com_realname/index.html", "") _run(pkg, out) assert (out / "components/com_realname/index.html").read_text() == "" assert not (out / "components/totallyhumandisplaytitle").exists() def test_component_name_fallback_removes_spaces_not_underscore(tmp_path: Path) -> None: """Végső fallback (nincs com_-folder, nincs nyelvi fájl, nincs scriptfile): a normalizálása szóköz-ELTÁVOLÍTÁSSAL történik, NEM aláhúzás-cserével. """ pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "manifest.xml", """ OneAll Social Login index.html """, ) _write(pkg / "index.html", "") _run(pkg, out) assert (out / "components/com_oneallsociallogin/index.html").exists() assert not (out / "components/com_oneall_social_login").exists() def test_component_with_embedded_modules_and_plugins_real_pattern(tmp_path: Path) -> None: """A valós OneAll Social Login csomag mintázatának replikája: EGYETLEN type="component" manifest, ami -val adja meg a deployed-nevet, tag-eket (nem -t) használ, és beágyazott / szekciókat tartalmaz (NEM pkg_ package -- nincs külön al-manifest, minden egy fájlban van). """ pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "manifest.xml", """ OneAll Social Login install/script.oneallsociallogin.php index.html oneallsociallogin.php COM_ONEALLSOCIALLOGIN controller.php en-GB.com_oneallsociallogin.sys.ini mod_oneallsociallogin.php oneallsociallogin.php """, ) _write(pkg / "com_oneallsociallogin/index.html", "") _write(pkg / "com_oneallsociallogin/oneallsociallogin.php", " None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "mod_hello.xml", """ mod_hello mod_hello.php helper.php images """, ) _write(pkg / "modfiles/mod_hello.php", " None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "mod_admhello.xml", """ mod_admhello mod_admhello.php """, ) _write(pkg / "mod_admhello.php", " None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "plg_hello.xml", """ PLG_CONTENT_HELLO hello.php language """, ) _write(pkg / "plgfiles/hello.php", " None: """Ha nincs , a utolsó '_'-tagja adja az elementet.""" pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "plg_system_fallback.xml", """ PLG_SYSTEM_FALLBACK fallback.php """, ) _write(pkg / "fallback.php", " None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "lib_hello.xml", """ hello hello.php sub """, ) _write(pkg / "libfiles/hello.php", " None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "tpl_hello.xml", """ hello index.php css """, ) _write(pkg / "tplfiles/index.php", " None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "pkg_hello.xml", """ pkg_hello com_hello plg_hello """, ) _write( pkg / "packages/com_hello/com_hello.xml", """ com_hello helloworld.php """, ) _write(pkg / "packages/com_hello/site/helloworld.php", " PLG_CONTENT_HELLO hello.php """, ) _write(pkg / "packages/plg_hello/hello.php", " None: pkg = tmp_path / "pkg" pkg.mkdir() with pytest.raises(jmap.JoomlaManifestError, match="nem található"): jmap.find_manifest(pkg) def test_multiple_manifests_raises(tmp_path: Path) -> None: pkg = tmp_path / "pkg" _write(pkg / "a.xml", 'com_a') _write(pkg / "b.xml", 'com_b') with pytest.raises(jmap.JoomlaManifestError, match="több lehetséges manifest"): jmap.find_manifest(pkg) def test_unsupported_extension_type_raises(tmp_path: Path) -> None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write(pkg / "weird.xml", 'x') manifest_path = jmap.find_manifest(pkg) with pytest.raises(jmap.JoomlaManifestError, match="nem támogatott extension type"): jmap.build_operations(manifest_path, out) def test_missing_source_file_raises(tmp_path: Path) -> None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "com_broken.xml", """ com_broken missing.php """, ) manifest_path = jmap.find_manifest(pkg) ops = jmap.build_operations(manifest_path, out) with pytest.raises(jmap.JoomlaManifestError, match="nem létezik"): jmap.execute(ops) def test_plugin_missing_group_raises(tmp_path: Path) -> None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "plg_nogroup.xml", """ PLG_NOGROUP nogroup.php """, ) manifest_path = jmap.find_manifest(pkg) with pytest.raises(jmap.JoomlaManifestError, match="'group'"): jmap.build_operations(manifest_path, out) # --------------------------------------------------------------------------- # CLI end-to-end (subprocess) # --------------------------------------------------------------------------- def test_cli_end_to_end(tmp_path: Path) -> None: pkg = tmp_path / "pkg" out = tmp_path / "out" _write( pkg / "com_hello.xml", """ com_hello helloworld.php """, ) _write(pkg / "helloworld.php", " None: pkg = tmp_path / "empty_pkg" pkg.mkdir() out = tmp_path / "out" # A jmap-modul tényleges fájl-útvonalát az importált modulból vesszük, # nem a teszt-fájl mellől -- a build-repóban jmap.py a lib/-ben, # test_jmap.py a tests/-ben él, a két fájl NEM ugyanabban a könyvtárban. script = Path(jmap.__file__) result = subprocess.run( [sys.executable, str(script), "--package", str(pkg), "--out", str(out)], capture_output=True, text=True, check=False, ) assert result.returncode == 1 assert "hiba:" in result.stderr