From d125ed56c135a79d9dbdf82842ba8cc049fbcc45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Martin?= Date: Mon, 18 Nov 2024 22:16:16 +0100 Subject: [PATCH] unit tests, add js files in default/repo/subfolder --- tests/units/classes/Project/ProjectTest.php | 63 ++ .../media/js/default/jsdefaultinroot.js | 0 .../media/js/events/jsprojetinroot.js | 0 .../media/js/invalid_project/unfoundable.js | 0 .../root4Repository/repo1/events.qgs | 957 ++++++++++++++++++ .../root4Repository/repo1/events.qgs.cfg | 247 +++++ .../repo1/media/js/default/jsdefaultinrepo.js | 0 .../repo1/media/js/events/jsprojetinrepo.js | 0 .../repo1/media/js/events/mjs.mjs | 0 .../repo1/media/js/events/style1.css | 0 .../js/events/subfolder/jsinsubfolder.js | 0 .../media/js/invalid_project/unfoundable.js | 0 .../repo1/media/js/js_bad_folder.js | 0 13 files changed, 1267 insertions(+) create mode 100644 tests/units/classes/Project/Ressources/root4Repository/media/js/default/jsdefaultinroot.js create mode 100644 tests/units/classes/Project/Ressources/root4Repository/media/js/events/jsprojetinroot.js create mode 100644 tests/units/classes/Project/Ressources/root4Repository/media/js/invalid_project/unfoundable.js create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs.cfg create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/default/jsdefaultinrepo.js create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/jsprojetinrepo.js create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/mjs.mjs create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/style1.css create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/subfolder/jsinsubfolder.js create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/invalid_project/unfoundable.js create mode 100644 tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/js_bad_folder.js diff --git a/tests/units/classes/Project/ProjectTest.php b/tests/units/classes/Project/ProjectTest.php index 3e1fb5511e..414f419bce 100644 --- a/tests/units/classes/Project/ProjectTest.php +++ b/tests/units/classes/Project/ProjectTest.php @@ -1,6 +1,7 @@ setCfg($config); $this->assertEquals($expectedRet, $proj->checkAcl()); } + + public static function userFiles4Projets() { + $eventsBaseURL = 'view~media:getMedia?repository=repo1&project=events&'; + return array( + array( + 'montpellier', + 'montpellier', + array('path' => __DIR__.'/../../../qgis-projects/demoqgis'), + array( + 'css'=> array(), + 'mjs' => array(), + 'js' => array() + ), + ), + array( + 'events', + 'repo1', + array('path' => __DIR__.'/Ressources/root4Repository/repo1'), + array('css'=> array( + 'view~media:getCssFile?repository=repo1&project=events&path=media/js/events/style1.css' + ), + 'mjs' => array( + 'view~media:getMedia?repository=repo1&project=events&path=media/js/events/mjs.mjs' + ), + 'js' => array( + $eventsBaseURL.'path=media/js/default/jsdefaultinrepo.js', + $eventsBaseURL.'path=../media/js/default/jsdefaultinroot.js', + $eventsBaseURL.'path=media/js/events/subfolder/jsinsubfolder.js', + $eventsBaseURL.'path=media/js/events/jsprojetinrepo.js', + $eventsBaseURL.'path=../media/js/events/jsprojetinroot.js', + ) + ) + ) + , + ); + } + + /** + * @dataProvider userFiles4Projets + */ + public function testFinder(string $projectName, $repoName, array $projectData, array $expectedFiles) { + $repo = new Project\Repository($repoName, $projectData + , null, null, null + ); + + $project = new ProjectForTests(); + $project->setRepo($repo); + $project->setKey($projectName); + $finder = new ProjectFilesFinder(); + $listFiles = $finder->listFileURLS($project, true); + foreach($listFiles as $fileExt => $list) { + // remove mtime=XXX From URLs + $urlsWithoutMtime = array_map( function ($url) { + $urlok = preg_replace('/&mtime=[0-9]*/', '', $url); + return $urlok; + }, $list); + // sorting to ensure list are in same order + sort($urlsWithoutMtime); + sort($expectedFiles[$fileExt]); + $this->assertEquals($urlsWithoutMtime, $expectedFiles[$fileExt]); + } + } } diff --git a/tests/units/classes/Project/Ressources/root4Repository/media/js/default/jsdefaultinroot.js b/tests/units/classes/Project/Ressources/root4Repository/media/js/default/jsdefaultinroot.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/media/js/events/jsprojetinroot.js b/tests/units/classes/Project/Ressources/root4Repository/media/js/events/jsprojetinroot.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/media/js/invalid_project/unfoundable.js b/tests/units/classes/Project/Ressources/root4Repository/media/js/invalid_project/unfoundable.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs b/tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs new file mode 100644 index 0000000000..dd66cab5bd --- /dev/null +++ b/tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs @@ -0,0 +1,957 @@ + + + + + + + + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + + + + + + + + + + + + + + + + osm_mapnik20190220152650417 + osm_stamen_toner20190220152651073 + events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101 + + + + + + + + + + meters + + 417828.47766224615043029 + 5393709.71128619741648436 + 441352.08966992393834516 + 5412981.91368997748941183 + + 0 + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + 0 + + + + + + + + + + + + + + + + + + + degrees + + 0 + 0 + 0 + 0 + + 0 + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + 0 + + + degrees + + 0 + 0 + 0 + 0 + + 0 + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + 0 + + + degrees + + 0 + 0 + 0 + 0 + + 0 + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + 0 + + + + + 3.70694994926452637 + 43.51250076293945313 + 4.07507991790771396 + 43.75249862670898438 + + events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101 + ./edition/events.gpkg|layername=events + Touristic events + + + + montpellier_events + + + +proj=longlat +datum=WGS84 +no_defs + 3452 + 4326 + EPSG:4326 + WGS 84 + longlat + WGS84 + true + + + + + + + + + + + + + + + + + + + + + + + + + 0 + 0 + + + + + true + + + + + + + + + + + + + ogr + + + + + + + + + + + 1 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COALESCE( "description", '<NULL>' ) + COALESCE( "description", '<NULL>' ) + + + + + + 0 + 0 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /home/mdouchin/Documents/3liz/Infra/lizmap-demo/demo + + 0 + /home/mdouchin/Documents/3liz/Infra/lizmap-demo/demo + + 0 + generatedlayout + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COALESCE( "description", '<NULL>' ) + <div style="padding:10px;"> +<p style="font-weight:bold;font-size:1.2em;">[% "titre" %]</p> + +<p> <i>[% "field_thematique" %]</i></p> + +<p> +[%'<i class="icon-time"></i> ' || format_date( + "field_date", + 'd MMMM yyyy - HH:mm' +)%] +<br/> +[%'<i class="icon-map-marker"></i> ' || "field_lieu"%] +</p> + +<img style="width: 100%;" src="[% "vignette_src" %]" alt="[% "vignette_alt" %]" title="[% "vignette_alt" %]"/> + +<p style="padding: 10px 0px; font-size:0.8em;">[% "description" %]</p> +<p style="font-size:0.8em;"><a href="[% "url" %]" target="_blank">Voir le site</a></p> + +</div> + + + + -20037508.34278924390673637 + -20037508.34278925508260727 + 20037508.34278924390673637 + 20037508.34278924390673637 + + osm_mapnik20190220152650417 + crs=EPSG:3857&format=&type=xyz&url=http://tile.openstreetmap.org/%7Bz%7D/%7Bx%7D/%7By%7D.png + + + + osm-mapnik + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + + + + + + + + + + + + + + 0 + 0 + + + + + false + + + + + wms + + + + + + + + 1 + 1 + 0 + + + + + + + + + None + WholeRaster + Estimated + 0.02 + 0.98 + 2 + + + + + + + 0 + + + + -20037508.34278924390673637 + -20037508.34278925508260727 + 20037508.34278924390673637 + 20037508.34278924390673637 + + osm_stamen_toner20190220152651073 + crs=EPSG:3857&format=&type=xyz&url=http://tile.stamen.com/toner-lite/%7Bz%7D/%7Bx%7D/%7By%7D.png + + + + osm-stamen-toner + + + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + 3857 + 3857 + EPSG:3857 + WGS 84 / Pseudo-Mercator + merc + WGS84 + false + + + + + + + + + + + + + + + + 0 + 0 + + + + + false + + + + + wms + + + + + + + + 1 + 1 + 0 + + + + + + + + + None + WholeRaster + Estimated + 0.02 + 0.98 + 2 + + + + + + + 0 + + + + + + + + + + + + + 1 + EPSG:3857 + 3857 + +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs + + + conditions unknown + true + + 16 + 30 + false + 0 + false + 50 + true + false + 0 + + + edition_polygon_34db893a_6765_42e5_aa9a_712b69e30dc2 + events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101 + tramstop_4cdf2dad_6f48_4491_b318_693cc9184208 + + + false + + + + 390483.99668047408340499 + 5375009.91444000415503979 + 477899.4732063576229848 + 5436768.56305211596190929 + + None + 8 + 90 + + + + + + 1 + + + 255 + + true + + + + MU + 2 + true + + + current_layer + to vertex and segment + 10 + 1 + + false + + 150 + 255 + 255 + 0 + 255 + 255 + 255 + + + + false + + + + + + + + + + + + false + + + + + + false + + + + WGS84 + + + + m2 + meters + + + true + + EPSG:4326 + EPSG:3857 + + + + + false + + + + + + + 5000 + + + + 8 + 8 + 8 + 8 + + Touristic events around Montpellier, France + + + false + + + + false + + + + + + + + + + + + + + + + + + + + + + 2000-01-01T00:00:00 + + + + diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs.cfg b/tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs.cfg new file mode 100644 index 0000000000..c1d7bef5d6 --- /dev/null +++ b/tests/units/classes/Project/Ressources/root4Repository/repo1/events.qgs.cfg @@ -0,0 +1,247 @@ +{ + "options": { + "projection": { + "proj4": "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs", + "ref": "EPSG:4242" + }, + "bbox": [ + 390483.9966804741, + 5375009.914440004, + 477899.4732063576, + 5436768.563052116 + ], + "mapScales": [ + 10000, + 25000, + 50000, + 100000, + 250000, + 500000 + ], + "minScale": 10000, + "maxScale": 500000, + "initialExtent": [ + 390483.9966804741, + 5375009.914440004, + 477899.4732063576, + 5436768.563052116 + ], + "osmMapnik": "True", + "osmStamenToner": "True", + "popupLocation": "right-dock", + "pointTolerance": 25, + "lineTolerance": 10, + "polygonTolerance": 5, + "tmTimeFrameSize": 10, + "tmTimeFrameType": "seconds", + "tmAnimationFrameLength": 1000, + "startupBaselayer": "osm-stamen-toner", + "datavizLocation": "dock", + "atlasLayer": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "atlasDisplayLayerDescription": "True", + "atlasHighlightGeometry": "True", + "atlasZoom": "zoom", + "atlasDisplayPopup": "True", + "atlasMaxWidth": 25, + "atlasDuration": 5 + }, + "layers": { + "montpellier_events": { + "id": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "name": "montpellier_events", + "type": "layer", + "geometryType": "point", + "extent": [ + 3.7069499492645264, + 43.51250076293945, + 4.075079917907714, + 43.752498626708984 + ], + "crs": "EPSG:4326", + "title": "Touristic events", + "abstract": "test pour voir", + "link": "", + "minScale": 1, + "maxScale": 1000000000000, + "toggled": "True", + "popup": "True", + "popupSource": "qgis", + "popupTemplate": "", + "popupMaxFeatures": 10, + "popupDisplayChildren": "False", + "noLegendImage": "False", + "groupAsLayer": "False", + "baseLayer": "False", + "displayInLegend": "True", + "singleTile": "True", + "imageFormat": "image/png", + "cached": "False", + "clientCacheExpiration": 300 + }, + "Hidden": { + "id": "Hidden", + "name": "Hidden", + "shortname": "test_shortname", + "type": "group", + "title": "Hidden", + "abstract": "", + "link": "", + "minScale": 1, + "maxScale": 1000000000000, + "toggled": "True", + "popup": "False", + "popupSource": "auto", + "popupTemplate": "", + "popupMaxFeatures": 10, + "popupDisplayChildren": "False", + "noLegendImage": "False", + "groupAsLayer": "False", + "baseLayer": "False", + "displayInLegend": "True", + "singleTile": "True", + "imageFormat": "image/png", + "cached": "False", + "clientCacheExpiration": 300 + }, + "osm-stamen-toner": { + "id": "osm_stamen_toner20190220152651073", + "name": "osm-stamen-toner", + "type": "layer", + "extent": [ + -20037508.342789244, + -20037508.342789255, + 20037508.342789244, + 20037508.342789244 + ], + "crs": "EPSG:3857", + "title": "osm-test", + "abstract": "", + "link": "", + "minScale": 1, + "maxScale": 1000000000000, + "toggled": "False", + "popup": "False", + "popupSource": "auto", + "popupTemplate": "", + "popupMaxFeatures": 10, + "popupDisplayChildren": "False", + "noLegendImage": "False", + "groupAsLayer": "False", + "baseLayer": "False", + "displayInLegend": "True", + "singleTile": "True", + "imageFormat": "image/png", + "cached": "False", + "clientCacheExpiration": 300 + }, + "osm-mapnik": { + "id": "osm_mapnik20190220152650417", + "name": "osm-mapnik", + "type": "layer", + "extent": [ + -20037508.342789244, + -20037508.342789255, + 20037508.342789244, + 20037508.342789244 + ], + "crs": "EPSG:3857", + "title": "osm-mapnik", + "abstract": "", + "link": "", + "minScale": 1, + "maxScale": 1000000000000, + "toggled": "False", + "popup": "False", + "popupSource": "auto", + "popupTemplate": "", + "popupMaxFeatures": 10, + "popupDisplayChildren": "False", + "noLegendImage": "False", + "groupAsLayer": "False", + "baseLayer": "False", + "displayInLegend": "True", + "singleTile": "True", + "imageFormat": "image/png", + "cached": "False", + "clientCacheExpiration": 300 + } + }, + "locateByLayer": { + "montpellier_events": { + "fieldName": "titre", + "displayGeom": "False", + "minLength": 0, + "filterOnLocate": "False", + "layerId": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "order": 0 + } + }, + "attributeLayers": { + "montpellier_events": { + "primaryKey": "fid", + "hiddenFields": "", + "pivot": "False", + "hideAsChild": "False", + "hideLayer": "False", + "layerId": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "order": 0 + } + }, + "datavizLayers": { + "0": { + "title": "Mon titre", + "type": "scatter", + "x_field": "field_communes", + "aggregation": "count", + "y_field": "fid", + "color": "#00aaff", + "colorfield": "", + "has_y2_field": "False", + "y2_field": "", + "color2": "", + "colorfield2": "", + "popup_display_child_plot": "False", + "only_show_child": "False", + "layerId": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "order": 0 + } + }, + "formFilterLayers": { + "0": { + "title": "Cat", + "type": "uniquevalues", + "field": "field_thematique", + "min_date": "", + "max_date": "", + "format": "checkboxes", + "splitter": ", ", + "provider": "ogr", + "layerId": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "order": 0 + }, + "1": { + "title": "Date", + "type": "date", + "field": "", + "min_date": "field_date", + "max_date": "field_date", + "format": "checkboxes", + "splitter": "", + "provider": "ogr", + "layerId": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "order": 1 + }, + "2": { + "title": "Commune", + "type": "uniquevalues", + "field": "field_communes", + "min_date": "", + "max_date": "", + "format": "select", + "splitter": ", ", + "provider": "ogr", + "layerId": "events_4c3b47b8_3939_4c8c_8e91_55bdb13a2101", + "order": 2 + } + } +} diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/default/jsdefaultinrepo.js b/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/default/jsdefaultinrepo.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/jsprojetinrepo.js b/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/jsprojetinrepo.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/mjs.mjs b/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/mjs.mjs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/style1.css b/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/style1.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/subfolder/jsinsubfolder.js b/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/events/subfolder/jsinsubfolder.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/invalid_project/unfoundable.js b/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/invalid_project/unfoundable.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/js_bad_folder.js b/tests/units/classes/Project/Ressources/root4Repository/repo1/media/js/js_bad_folder.js new file mode 100644 index 0000000000..e69de29bb2