commit 201869a83fcf5ecce1fbbd72b85fdc598565d02b
Author: Petr Skoda <petr.skoda@totaralms.com>
Date: Tue Nov 22 15:16:42 2016 +1300
TL-12455 reportbulder: Backport TL-11198
introduced the ability to add a new function hook in reportbuilder sources
public function phpunit_column_test_add_data(totara_reportbuilder_column_testcase $testcase)
that is supposed to let you inject test data for your specific report into the column tests, easing the hassle of adding custom reports that dont' have existing test data.
However the functions used for loading data into the reportbuilder column test
are protected and cannot be called outside of the class instance.
Therefore trying to inject custom report source data such as
https://github.com/catalyst/totara-mod-ojt/blob/master/rb_sources/rb_source_ojt_completion.php#L491
Leads to a fatal error when running the unit tests
05:03:48.611 Fatal error: Call to protected method advanced_testcase::loadDataSet() from context 'rb_source_ojt_completion' in /var/www/html/mod/ojt/rb_sources/rb_source_ojt_completion.php on line 495
The
data hook in the rb source is essentially useless without any way to
inject data into the test case and I could not find any existing
function that would let us inject data, did I miss a function call in the test case api, or was this an oversight in the implementation?
I've added the following quick patch to improve the situation, but you could also opt to make those functions public
diff --git a/totara/reportbuilder/tests/column_test.php b/totara/reportbuilder/tests/column_test.php
index bc5add4..31eb12e 100644
--- a/totara/reportbuilder/tests/column_test.php
+++ b/totara/reportbuilder/tests/column_test.php
@@ -858,6 +858,13 @@ class totara_reportbuilder_column_testcase extends reportcache_advanced_testcase
return $sources;
}
+ /*
+ * Inject data into the test, resetting the dataset
+ */
+ public function injectData($data) {
+ $this->loadDataSet($this->createArrayDataset($data));
+ }
+
/**
* Check all reports columns and filters
*
Cheers
Francis Devine <francis@catalyst.net.nz>