|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use Lizmap\Project;
|
| 4 | +use Lizmap\Project\ProjectFilesFinder; |
4 | 5 | use PHPUnit\Framework\TestCase;
|
5 | 6 |
|
6 | 7 | /**
|
@@ -494,4 +495,66 @@ public function testCheckAcl($aclData, $options, $expectedRet)
|
494 | 495 | $proj->setCfg($config);
|
495 | 496 | $this->assertEquals($expectedRet, $proj->checkAcl());
|
496 | 497 | }
|
| 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 | + } |
497 | 560 | }
|
0 commit comments