See Release Notes
Long Term Support Release
Differences Between: [Versions 39 and 311] [Versions 39 and 400] [Versions 39 and 401] [Versions 39 and 402] [Versions 39 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 subscription manager api. 19 * 20 * @package tool_monitor 21 * @category test 22 * @copyright 2014 onwards Simey Lameze <simey@moodle.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 30 /** 31 * Tests for subscription manager. 32 * 33 * Class tool_monitor_subscription_manager_testcase. 34 */ 35 class tool_monitor_subscription_manager_testcase extends advanced_testcase { 36 37 /** 38 * Test count_rule_subscriptions method. 39 */ 40 public function test_count_rule_subscriptions() { 41 42 $this->setAdminUser(); 43 $this->resetAfterTest(true); 44 45 // Create users. 46 $user1 = $this->getDataGenerator()->create_user(); 47 $user2 = $this->getDataGenerator()->create_user(); 48 49 // Create few rules. 50 $monitorgenerator = $this->getDataGenerator()->get_plugin_generator('tool_monitor'); 51 $rule1 = $monitorgenerator->create_rule(); 52 $rule2 = $monitorgenerator->create_rule(); 53 $subs = \tool_monitor\subscription_manager::count_rule_subscriptions($rule1->id); 54 55 // No subscriptions at this point. 56 $this->assertEquals(0, $subs); 57 58 // Subscribe user 1 to rule 1. 59 $record = new stdClass; 60 $record->ruleid = $rule1->id; 61 $record->userid = $user1->id; 62 $monitorgenerator->create_subscription($record); 63 64 // Subscribe user 2 to rule 1. 65 $record->userid = $user2->id; 66 $monitorgenerator->create_subscription($record); 67 68 // Subscribe user 2 to rule 2. 69 $record->ruleid = $rule2->id; 70 $monitorgenerator->create_subscription($record); 71 72 // Should have 2 subscriptions for rule 1 and 1 subscription for rule 2 73 $subs1 = \tool_monitor\subscription_manager::count_rule_subscriptions($rule1->id); 74 $subs2 = \tool_monitor\subscription_manager::count_rule_subscriptions($rule2->id); 75 $this->assertEquals(2, $subs1); 76 $this->assertEquals(1, $subs2); 77 } 78 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body