Skip to content

Commit d125ed5

Browse files
nworrgithub-actions[bot]
authored andcommitted
unit tests, add js files in default/repo/subfolder
1 parent a7df46b commit d125ed5

File tree

13 files changed

+1267
-0
lines changed

13 files changed

+1267
-0
lines changed

tests/units/classes/Project/ProjectTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Lizmap\Project;
4+
use Lizmap\Project\ProjectFilesFinder;
45
use PHPUnit\Framework\TestCase;
56

67
/**
@@ -494,4 +495,66 @@ public function testCheckAcl($aclData, $options, $expectedRet)
494495
$proj->setCfg($config);
495496
$this->assertEquals($expectedRet, $proj->checkAcl());
496497
}
498+
499+
public static function userFiles4Projets() {
500+
$eventsBaseURL = 'view~media:getMedia?repository=repo1&project=events&';
501+
return array(
502+
array(
503+
'montpellier',
504+
'montpellier',
505+
array('path' => __DIR__.'/../../../qgis-projects/demoqgis'),
506+
array(
507+
'css'=> array(),
508+
'mjs' => array(),
509+
'js' => array()
510+
),
511+
),
512+
array(
513+
'events',
514+
'repo1',
515+
array('path' => __DIR__.'/Ressources/root4Repository/repo1'),
516+
array('css'=> array(
517+
'view~media:getCssFile?repository=repo1&project=events&path=media/js/events/style1.css'
518+
),
519+
'mjs' => array(
520+
'view~media:getMedia?repository=repo1&project=events&path=media/js/events/mjs.mjs'
521+
),
522+
'js' => array(
523+
$eventsBaseURL.'path=media/js/default/jsdefaultinrepo.js',
524+
$eventsBaseURL.'path=../media/js/default/jsdefaultinroot.js',
525+
$eventsBaseURL.'path=media/js/events/subfolder/jsinsubfolder.js',
526+
$eventsBaseURL.'path=media/js/events/jsprojetinrepo.js',
527+
$eventsBaseURL.'path=../media/js/events/jsprojetinroot.js',
528+
)
529+
)
530+
)
531+
,
532+
);
533+
}
534+
535+
/**
536+
* @dataProvider userFiles4Projets
537+
*/
538+
public function testFinder(string $projectName, $repoName, array $projectData, array $expectedFiles) {
539+
$repo = new Project\Repository($repoName, $projectData
540+
, null, null, null
541+
);
542+
543+
$project = new ProjectForTests();
544+
$project->setRepo($repo);
545+
$project->setKey($projectName);
546+
$finder = new ProjectFilesFinder();
547+
$listFiles = $finder->listFileURLS($project, true);
548+
foreach($listFiles as $fileExt => $list) {
549+
// remove mtime=XXX From URLs
550+
$urlsWithoutMtime = array_map( function ($url) {
551+
$urlok = preg_replace('/&mtime=[0-9]*/', '', $url);
552+
return $urlok;
553+
}, $list);
554+
// sorting to ensure list are in same order
555+
sort($urlsWithoutMtime);
556+
sort($expectedFiles[$fileExt]);
557+
$this->assertEquals($urlsWithoutMtime, $expectedFiles[$fileExt]);
558+
}
559+
}
497560
}

tests/units/classes/Project/Ressources/root4Repository/media/js/default/jsdefaultinroot.js

Whitespace-only changes.

tests/units/classes/Project/Ressources/root4Repository/media/js/events/jsprojetinroot.js

Whitespace-only changes.

tests/units/classes/Project/Ressources/root4Repository/media/js/invalid_project/unfoundable.js

Whitespace-only changes.

0 commit comments

Comments
 (0)