Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Unit tests for report_insights externallib. 19 * 20 * @package report_insights 21 * @copyright 2019 David MonllaĆ³ {@link http://www.davidmonllao.com} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once (__DIR__ . '/../../../analytics/tests/fixtures/test_indicator_max.php'); 28 require_once (__DIR__ . '/../../../analytics/tests/fixtures/test_target_shortname.php'); 29 30 /** 31 * Unit tests for report_insights externallib. 32 * 33 * @package report_insights 34 * @copyright 2019 David MonllaĆ³ {@link http://www.davidmonllao.com} 35 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 36 */ 37 class report_insights_external_testcase extends advanced_testcase { 38 39 /** 40 * test_action_executed 41 */ 42 public function test_action_executed() { 43 global $DB; 44 45 $this->setAdminUser(); 46 $target = \core_analytics\manager::get_target('test_target_shortname'); 47 $indicators = array('test_indicator_max'); 48 foreach ($indicators as $key => $indicator) { 49 $indicators[$key] = \core_analytics\manager::get_indicator($indicator); 50 } 51 52 $model = \core_analytics\model::create($target, $indicators); 53 $modelobj = $model->get_model_obj(); 54 $model->enable('\core\analytics\time_splitting\single_range'); 55 56 $this->resetAfterTest(true); 57 58 $course1 = $this->getDataGenerator()->create_course(); 59 $course2 = $this->getDataGenerator()->create_course(); 60 $context = \context_course::instance($course1->id); 61 62 $teacher1 = $this->getDataGenerator()->create_user(); 63 $teacher2 = $this->getDataGenerator()->create_user(); 64 65 $this->getDataGenerator()->enrol_user($teacher1->id, $course1->id, 'editingteacher'); 66 $this->getDataGenerator()->enrol_user($teacher2->id, $course1->id, 'editingteacher'); 67 68 // The only relevant fields are modelid, contextid and sampleid. I'm cheating and setting 69 // contextid as the course context so teachers can access these predictions. 70 $pred = new \stdClass(); 71 $pred->modelid = $model->get_id(); 72 $pred->contextid = $context->id; 73 $pred->sampleid = $course1->id; 74 $pred->rangeindex = 1; 75 $pred->prediction = 1; 76 $pred->predictionscore = 1; 77 $pred->calculations = json_encode(array('test_indicator_max' => 1)); 78 $pred->timecreated = time(); 79 $DB->insert_record('analytics_predictions', $pred); 80 81 $pred->sampleid = $course2->id; 82 $DB->insert_record('analytics_predictions', $pred); 83 84 $this->assertEquals(0, $DB->count_records('analytics_prediction_actions')); 85 86 // Teacher 2 flags a prediction (it doesn't matter which one) as fixed. 87 $this->setUser($teacher2); 88 list($ignored, $predictions) = $model->get_predictions($context, true); 89 $prediction = reset($predictions); 90 91 \report_insights\external::action_executed(\core_analytics\prediction::ACTION_FIXED, 92 [$prediction->get_prediction_data()->id]); 93 $recordset = $model->get_prediction_actions($context); 94 $this->assertCount(1, $recordset); 95 $recordset->close(); 96 $this->assertEquals(1, $DB->count_records('analytics_prediction_actions')); 97 $action = $DB->get_record('analytics_prediction_actions', array('userid' => $teacher2->id)); 98 $this->assertEquals(\core_analytics\prediction::ACTION_FIXED, $action->actionname); 99 100 \report_insights\external::action_executed(\core_analytics\prediction::ACTION_INCORRECTLY_FLAGGED, 101 [$prediction->get_prediction_data()->id]); 102 $recordset = $model->get_prediction_actions($context); 103 $this->assertCount(2, $recordset); 104 $recordset->close(); 105 $this->assertEquals(2, $DB->count_records('analytics_prediction_actions')); 106 } 107 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body