See Release Notes
Long Term Support Release
Differences Between: [Versions 310 and 401] [Versions 39 and 401]
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 * External functions test for record_feedback_action. 19 * 20 * @package core 21 * @category test 22 * @copyright 2020 Shamim Rezaie <shamim@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 namespace core\external; 27 28 defined('MOODLE_INTERNAL') || die(); 29 30 use externallib_advanced_testcase; 31 use context_system; 32 33 global $CFG; 34 35 require_once($CFG->dirroot . '/webservice/tests/helpers.php'); 36 37 /** 38 * Class record_userfeedback_action_testcase 39 * 40 * @copyright 2020 Shamim Rezaie <shamim@moodle.com> 41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 42 * @coversDefaultClass \core\external\record_userfeedback_action 43 */ 44 class record_userfeedback_action_test extends externallib_advanced_testcase { 45 46 /** 47 * Data provider for test_record_userfeedback_action. 48 * 49 * @return array 50 */ 51 public function record_userfeedback_action_provider() { 52 return [ 53 'give action' => ['give'], 54 'remind action' => ['remind'], 55 ]; 56 } 57 58 /** 59 * Test the behaviour of record_userfeedback_action(). 60 * 61 * @dataProvider record_userfeedback_action_provider 62 * @param string $action The action taken by the user 63 * 64 * @covers ::execute 65 */ 66 public function test_record_userfeedback_action(string $action) { 67 $this->resetAfterTest(); 68 69 $context = context_system::instance(); 70 $user = $this->getDataGenerator()->create_user(); 71 $this->setUser($user); 72 $eventsink = $this->redirectEvents(); 73 74 $now = time(); 75 76 // Call the WS and check the action is recorded as expected. 77 $result = record_userfeedback_action::execute($action, $context->id); 78 $this->assertNull($result); 79 80 $preference = get_user_preferences('core_userfeedback_' . $action); 81 $this->assertGreaterThanOrEqual($now, $preference); 82 83 $events = $eventsink->get_events(); 84 $this->assertCount(1, $events); 85 $this->assertInstanceOf('\core\event\userfeedback_' . $action, $events[0]); 86 $eventsink->clear(); 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body