aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/UtilTest.php
diff options
context:
space:
mode:
authorJonas Meurer <jonas@freesources.org>2021-12-17 13:26:43 +0100
committerJonas Meurer <jonas@freesources.org>2021-12-20 11:40:17 +0100
commit8dd119402a19d5ce131cc68340e9db9f0ebdd382 (patch)
tree5e9faea7024cc0e4aa044097346895d73e134c09 /tests/lib/UtilTest.php
parent7ec1317b1bb42bbbeaff3cf623a5dc6570a468c8 (diff)
downloadnextcloud-server-8dd119402a19d5ce131cc68340e9db9f0ebdd382.tar.gz
nextcloud-server-8dd119402a19d5ce131cc68340e9db9f0ebdd382.zip
Improve unit testing for Util::addScript() and Util::getScript()
Instead of checking for a predefined order of the scripts, test the logic: core first, dependencies before their children, no duplicates and all scripts still listed. Signed-off-by: Jonas Meurer <jonas@freesources.org>
Diffstat (limited to 'tests/lib/UtilTest.php')
-rw-r--r--tests/lib/UtilTest.php58
1 files changed, 53 insertions, 5 deletions
diff --git a/tests/lib/UtilTest.php b/tests/lib/UtilTest.php
index 1b430fd7ecd..1b244d29dd5 100644
--- a/tests/lib/UtilTest.php
+++ b/tests/lib/UtilTest.php
@@ -238,22 +238,70 @@ class UtilTest extends \Test\TestCase {
public function testAddScript() {
\OCP\Util::addScript('core', 'myFancyJSFile1');
\OCP\Util::addScript('files', 'myFancyJSFile2', 'core');
+ \OCP\Util::addScript('myApp5', 'myApp5JSFile', 'myApp2');
\OCP\Util::addScript('myApp', 'myFancyJSFile3');
\OCP\Util::addScript('core', 'myFancyJSFile4');
// after itself
\OCP\Util::addScript('core', 'myFancyJSFile5', 'core');
// add duplicate
\OCP\Util::addScript('core', 'myFancyJSFile1');
-
- $this->assertEquals([
+ // dependency chain
+ \OCP\Util::addScript('myApp4', 'myApp4JSFile', 'myApp3');
+ \OCP\Util::addScript('myApp3', 'myApp3JSFile', 'myApp2');
+ \OCP\Util::addScript('myApp2', 'myApp2JSFile', 'myApp');
+
+ // Core should appear first
+ $this->assertEquals(
+ 0,
+ array_search('core/js/myFancyJSFile1', \OCP\Util::getScripts(), true)
+ );
+ $this->assertEquals(
+ 1,
+ array_search('core/js/myFancyJSFile4', \OCP\Util::getScripts(), true)
+ );
+
+ // Dependencies should appear before their children
+ $this->assertLessThan(
+ array_search('files/js/myFancyJSFile2', \OCP\Util::getScripts(), true),
+ array_search('core/js/myFancyJSFile3', \OCP\Util::getScripts(), true)
+ );
+ $this->assertLessThan(
+ array_search('myApp2/js/myApp2JSFile', \OCP\Util::getScripts(), true),
+ array_search('myApp/js/myFancyJSFile3', \OCP\Util::getScripts(), true)
+ );
+ $this->assertLessThan(
+ array_search('myApp3/js/myApp3JSFile', \OCP\Util::getScripts(), true),
+ array_search('myApp2/js/myApp2JSFile', \OCP\Util::getScripts(), true)
+ );
+ $this->assertLessThan(
+ array_search('myApp4/js/myApp4JSFile', \OCP\Util::getScripts(), true),
+ array_search('myApp3/js/myApp3JSFile', \OCP\Util::getScripts(), true)
+ );
+ $this->assertLessThan(
+ array_search('myApp5/js/myApp5JSFile', \OCP\Util::getScripts(), true),
+ array_search('myApp2/js/myApp2JSFile', \OCP\Util::getScripts(), true)
+ );
+
+ // No duplicates
+ $this->assertEquals(
+ \OCP\Util::getScripts(),
+ array_unique(\OCP\Util::getScripts())
+ );
+
+ // All scripts still there
+ $scripts = [
'core/js/myFancyJSFile1',
'core/js/myFancyJSFile4',
'files/js/myFancyJSFile2',
'core/js/myFancyJSFile5',
- 'files/l10n/en',
- 'myApp/l10n/en',
'myApp/js/myFancyJSFile3',
- ], array_values(\OCP\Util::getScripts()));
+ 'myApp2/js/myApp2JSFile',
+ 'myApp3/js/myApp3JSFile',
+ 'myApp4/js/myApp4JSFile',
+ ];
+ foreach ($scripts as $script) {
+ $this->assertContains($script, \OCP\Util::getScripts());
+ }
}
public function testAddVendorScript() {