kaltura / moodle_plugin

8 stars 37 forks source link

Kaltura filter causes core unit test to fail in Moodle 3.11 and 4.0 #394

Open golenkovm opened 1 year ago

golenkovm commented 1 year ago

When running unit tests with filter_kaltura plugin installed the following core test is failing:

1) externallib_test::test_get_courses_by_field
Failed asserting that actual size 7 matches expected size 6.

/var/www/site/course/tests/externallib_test.php:2756
/var/www/site/lib/phpunit/classes/advanced_testcase.php:80
phpvfscomposer:///var/www/site/vendor/phpunit/phpunit/phpunit:97

It seems like it expects a specific number of filters enabled by default.

golenkovm commented 1 year ago

The following patch was applied to fix the issue, but feel free to implement the fix in your own way:

diff --git a/db/install.php b/db/install.php
index 287bab3..83b7934 100644
--- a/db/install.php
+++ b/db/install.php
@@ -25,5 +25,10 @@ function xmldb_filter_kaltura_install() {
     global $CFG;
     require_once("$CFG->libdir/filterlib.php");

-    filter_set_global_state('kaltura', TEXTFILTER_ON);
+    // Do not enable the filter when running unit tests because some core
+    // tests expect a specific number of filters enabled.
+    if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) {
+        filter_set_global_state('kaltura', TEXTFILTER_ON);
+    }
+
 }