From 8ead8802fbdf44098f86c6fbed8a1ce7959b77ae Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Thu, 20 Mar 2014 12:12:25 +0800 Subject: [PATCH] MDL-44596 logging: Add callbacks to all reports that support log stores --- report/log/lib.php | 14 ++++++ report/log/tests/lib_test.php | 57 +++++++++++++++++++++++++ report/loglive/lib.php | 14 ++++++ report/loglive/tests/lib_test.php | 57 +++++++++++++++++++++++++ report/outline/lib.php | 14 ++++++ report/outline/tests/lib_test.php | 56 ++++++++++++++++++++++++ report/participation/lib.php | 14 ++++++ report/participation/tests/lib_test.php | 56 ++++++++++++++++++++++++ report/stats/lib.php | 14 ++++++ report/stats/tests/lib_test.php | 56 ++++++++++++++++++++++++ 10 files changed, 352 insertions(+) create mode 100644 report/log/tests/lib_test.php create mode 100644 report/loglive/tests/lib_test.php create mode 100644 report/outline/tests/lib_test.php create mode 100644 report/participation/tests/lib_test.php create mode 100644 report/stats/tests/lib_test.php diff --git a/report/log/lib.php b/report/log/lib.php index c45bf1c8454..867da4dc4d9 100644 --- a/report/log/lib.php +++ b/report/log/lib.php @@ -40,6 +40,20 @@ function report_log_extend_navigation_course($navigation, $course, $context) { } } +/** + * Callback to verify if the given instance of store is supported by this report or not. + * + * @param string $instance store instance. + * + * @return bool returns true if the store is supported by the report, false otherwise. + */ +function report_log_supports_logstore($instance) { + if ($instance instanceof \core\log\sql_select_reader) { + return true; + } + return false; +} + /** * This function extends the course navigation with the report items * diff --git a/report/log/tests/lib_test.php b/report/log/tests/lib_test.php new file mode 100644 index 00000000000..0b605f61deb --- /dev/null +++ b/report/log/tests/lib_test.php @@ -0,0 +1,57 @@ +. + +/** + * Tests for report library functions. + * + * @package report_log + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Class report_log_events_testcase. + * + * @package report_log + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +class report_log_lib_testcase extends advanced_testcase { + + /** + * Test report_log_supports_logstore. + */ + public function test_report_log_supports_logstore() { + $logmanager = get_log_manager(); + $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); + + $supportedstores = array( + 'logstore_database' => '\logstore_database\log\store', + 'logstore_legacy' => '\logstore_legacy\log\store', + 'logstore_standard' => '\logstore_standard\log\store' + ); + + // Make sure all supported stores are installed. + $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); + $stores = $logmanager->get_supported_logstores('log'); + $stores = array_keys($stores); + foreach ($expectedstores as $expectedstore) { + $this->assertContains($expectedstore, $stores); + } + } +} diff --git a/report/loglive/lib.php b/report/loglive/lib.php index be4edf243d3..c0d3237bdac 100644 --- a/report/loglive/lib.php +++ b/report/loglive/lib.php @@ -43,3 +43,17 @@ function report_loglive_extend_navigation_course($navigation, $course, $context) $navigation->add(get_string('pluginname', 'report_loglive'), $action, navigation_node::TYPE_SETTING, null, null, new pix_icon('i/report', '')); } } + +/** + * Callback to verify if the given instance of store is supported by this report or not. + * + * @param string $instance store instance. + * + * @return bool returns true if the store is supported by the report, false otherwise. + */ +function report_loglive_supports_logstore($instance) { + if ($instance instanceof \core\log\sql_select_reader) { + return true; + } + return false; +} diff --git a/report/loglive/tests/lib_test.php b/report/loglive/tests/lib_test.php new file mode 100644 index 00000000000..5461902407b --- /dev/null +++ b/report/loglive/tests/lib_test.php @@ -0,0 +1,57 @@ +. + +/** + * Tests for report library functions. + * + * @package report_loglive + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Class report_loglive_lib_testcase + * + * @package report_loglive + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +class report_loglive_lib_testcase extends advanced_testcase { + + /** + * Test report_log_supports_logstore. + */ + public function test_report_participation_supports_logstore() { + $logmanager = get_log_manager(); + $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); + + $supportedstores = array( + 'logstore_database' => '\logstore_legacy\log\database', + 'logstore_legacy' => '\logstore_legacy\log\store', + 'logstore_standard' => '\logstore_standard\log\store' + ); + + // Make sure all supported stores are installed. + $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); + $stores = $logmanager->get_supported_logstores('loglive'); + $stores = array_keys($stores); + foreach ($expectedstores as $expectedstore) { + $this->assertContains($expectedstore, $stores); + } + } +} diff --git a/report/outline/lib.php b/report/outline/lib.php index 11b27fe6ff7..16a300708a4 100644 --- a/report/outline/lib.php +++ b/report/outline/lib.php @@ -105,3 +105,17 @@ function report_outline_page_type_list($pagetype, $parentcontext, $currentcontex ); return $array; } + +/** + * Callback to verify if the given instance of store is supported by this report or not. + * + * @param string $instance store instance. + * + * @return bool returns true if the store is supported by the report, false otherwise. + */ +function report_outline_supports_logstore($instance) { + if ($instance instanceof \core\log\sql_internal_reader || $instance instanceof \logstore_legacy\log\store) { + return true; + } + return false; +} diff --git a/report/outline/tests/lib_test.php b/report/outline/tests/lib_test.php new file mode 100644 index 00000000000..95593fb984d --- /dev/null +++ b/report/outline/tests/lib_test.php @@ -0,0 +1,56 @@ +. + +/** + * Tests for report library functions. + * + * @package report_outline + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Class report_outline_lib_testcase + * + * @package report_outline + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +class report_outline_lib_testcase extends advanced_testcase { + + /** + * Test report_log_supports_logstore. + */ + public function test_report_participation_supports_logstore() { + $logmanager = get_log_manager(); + $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); + + $supportedstores = array( + 'logstore_legacy' => '\logstore_legacy\log\store', + 'logstore_standard' => '\logstore_standard\log\store' + ); + + // Make sure all supported stores are installed. + $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); + $stores = $logmanager->get_supported_logstores('outline'); + $stores = array_keys($stores); + foreach ($expectedstores as $expectedstore) { + $this->assertContains($expectedstore, $stores); + } + } +} diff --git a/report/participation/lib.php b/report/participation/lib.php index bf6be747f27..008395e449c 100644 --- a/report/participation/lib.php +++ b/report/participation/lib.php @@ -55,4 +55,18 @@ function report_participation_page_type_list($pagetype, $parentcontext, $current 'report-participation-index' => get_string('page-report-participation-index', 'report_participation'), ); return $array; +} + +/** + * Callback to verify if the given instance of store is supported by this report or not. + * + * @param string $instance store instance. + * + * @return bool returns true if the store is supported by the report, false otherwise. + */ +function report_participation_supports_logstore($instance) { + if ($instance instanceof \core\log\sql_internal_reader || $instance instanceof \logstore_legacy\log\store) { + return true; + } + return false; } \ No newline at end of file diff --git a/report/participation/tests/lib_test.php b/report/participation/tests/lib_test.php new file mode 100644 index 00000000000..3f2d05be46a --- /dev/null +++ b/report/participation/tests/lib_test.php @@ -0,0 +1,56 @@ +. + +/** + * Tests for report library functions. + * + * @package report_participation + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Class report_participation_lib_testcase + * + * @package report_participation + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +class report_participation_lib_testcase extends advanced_testcase { + + /** + * Test report_log_supports_logstore. + */ + public function test_report_participation_supports_logstore() { + $logmanager = get_log_manager(); + $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); + + $supportedstores = array( + 'logstore_legacy' => '\logstore_legacy\log\store', + 'logstore_standard' => '\logstore_standard\log\store' + ); + + // Make sure all supported stores are installed. + $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); + $stores = $logmanager->get_supported_logstores('participation'); + $stores = array_keys($stores); + foreach ($expectedstores as $expectedstore) { + $this->assertContains($expectedstore, $stores); + } + } +} diff --git a/report/stats/lib.php b/report/stats/lib.php index 1c191a453c1..e3232a5434c 100644 --- a/report/stats/lib.php +++ b/report/stats/lib.php @@ -112,4 +112,18 @@ function report_stats_page_type_list($pagetype, $parentcontext, $currentcontext) 'report-stats-user' => get_string('page-report-stats-user', 'report_stats') ); return $array; +} + +/** + * Callback to verify if the given instance of store is supported by this report or not. + * + * @param string $instance store instance. + * + * @return bool returns true if the store is supported by the report, false otherwise. + */ +function report_stats_supports_logstore($instance) { + if ($instance instanceof \core\log\sql_internal_reader || $instance instanceof \logstore_legacy\log\store) { + return true; + } + return false; } \ No newline at end of file diff --git a/report/stats/tests/lib_test.php b/report/stats/tests/lib_test.php new file mode 100644 index 00000000000..6d6630f17f7 --- /dev/null +++ b/report/stats/tests/lib_test.php @@ -0,0 +1,56 @@ +. + +/** + * Tests for report library functions. + * + * @package report_stats + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Class report_stats_lib_testcase + * + * @package report_stats + * @copyright 2014 onwards Ankit agarwal + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ +class report_stats_lib_testcase extends advanced_testcase { + + /** + * Test report_log_supports_logstore. + */ + public function test_report_participation_supports_logstore() { + $logmanager = get_log_manager(); + $allstores = \core_component::get_plugin_list_with_class('logstore', 'log\store'); + + $supportedstores = array( + 'logstore_legacy' => '\logstore_legacy\log\store', + 'logstore_standard' => '\logstore_standard\log\store' + ); + + // Make sure all supported stores are installed. + $expectedstores = array_keys(array_intersect($allstores, $supportedstores)); + $stores = $logmanager->get_supported_logstores('stats'); + $stores = array_keys($stores); + foreach ($expectedstores as $expectedstore) { + $this->assertContains($expectedstore, $stores); + } + } +}