From 2ea379e0b03767682d20a11bd1096a429f5bb235 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 31 Jan 2023 19:32:03 +0000 Subject: [PATCH] MDL-77100 mod_data: replace calls to str_ends_with, fix assertions. Calls to `str_ends_with` are polyfilled currently, as the method is not present in PHP7.4 or earlier. We should avoid uses of it so as to not trip up compatibility standard checkers. --- mod/data/tests/preset_test.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mod/data/tests/preset_test.php b/mod/data/tests/preset_test.php index 72b8df62257..37f98566703 100644 --- a/mod/data/tests/preset_test.php +++ b/mod/data/tests/preset_test.php @@ -386,12 +386,21 @@ class preset_test extends \advanced_testcase { $files = $ziparchive->list_files(); foreach ($files as $file) { $this->assertContains($file->pathname, $presetfilenames); + // Check the file is not empty (except CSS, JS and listtemplateheader/footer files which are empty by default). - $ishtmlorxmlfile = str_ends_with($file->pathname, '.html') || str_ends_with($file->pathname, '.xml'); - $islistheader = $file->pathname != manager::TEMPLATES_LIST['listtemplateheader']; - $islistfooter = $file->pathname != manager::TEMPLATES_LIST['listtemplatefooter']; - if ($ishtmlorxmlfile && !$islistheader && !$islistfooter) { + $extension = pathinfo($file->pathname, PATHINFO_EXTENSION); + $ishtmlorxmlfile = in_array($extension, ['html', 'xml']); + + $expectedemptyfiles = array_intersect_key(manager::TEMPLATES_LIST, array_flip([ + 'listtemplateheader', + 'listtemplatefooter', + 'rsstitletemplate', + ])); + + if ($ishtmlorxmlfile && !in_array($file->pathname, $expectedemptyfiles)) { $this->assertGreaterThan(0, $file->size); + } else { + $this->assertEquals(0, $file->size); } } $ziparchive->close();