[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 airnotifier functions unit tests 19 * 20 * @package message_airnotifier 21 * @category external 22 * @copyright 2012 Jerome Mouneyrac 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 require_once($CFG->dirroot . '/webservice/tests/helpers.php'); 31 32 /** 33 * External airnotifier functions unit tests 34 * 35 * @package message_airnotifier 36 * @category external 37 * @copyright 2012 Jerome Mouneyrac 38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 39 */ 40 class message_airnotifier_external_testcase extends externallib_advanced_testcase { 41 42 /** 43 * Tests set up 44 */ 45 protected function setUp() { 46 global $CFG; 47 require_once($CFG->dirroot . '/message/output/airnotifier/externallib.php'); 48 } 49 50 /** 51 * Test is_system_configured 52 */ 53 public function test_is_system_configured() { 54 global $DB; 55 56 $this->resetAfterTest(true); 57 58 $user = self::getDataGenerator()->create_user(); 59 self::setUser($user); 60 61 // In a clean installation, it should be not configured. 62 $configured = message_airnotifier_external::is_system_configured(); 63 $configured = external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured); 64 $this->assertEquals(0, $configured); 65 66 // Fake configuration. 67 set_config('airnotifieraccesskey', random_string()); 68 // Enable the plugin. 69 $DB->set_field('message_processors', 'enabled', 1, array('name' => 'airnotifier')); 70 71 $configured = message_airnotifier_external::is_system_configured(); 72 $configured = external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured); 73 $this->assertEquals(1, $configured); 74 } 75 76 /** 77 * Test are_notification_preferences_configured 78 */ 79 public function test_are_notification_preferences_configured() { 80 81 $this->resetAfterTest(true); 82 83 $user1 = self::getDataGenerator()->create_user(); 84 $user2 = self::getDataGenerator()->create_user(); 85 $user3 = self::getDataGenerator()->create_user(); 86 87 self::setUser($user1); 88 89 set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user1); 90 set_user_preference('message_provider_moodle_instantmessage_loggedoff', 'airnotifier', $user1); 91 set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user2); 92 set_user_preference('message_provider_moodle_instantmessage_loggedin', 'airnotifier', $user3); 93 94 $params = array($user1->id, $user2->id, $user3->id); 95 96 $preferences = message_airnotifier_external::are_notification_preferences_configured($params); 97 $returnsdescription = message_airnotifier_external::are_notification_preferences_configured_returns(); 98 $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); 99 100 $expected = array( 101 array( 102 'userid' => $user1->id, 103 'configured' => 1 104 ) 105 ); 106 107 $this->assertEquals(1, count($preferences['users'])); 108 $this->assertEquals($expected, $preferences['users']); 109 $this->assertEquals(2, count($preferences['warnings'])); 110 111 // Now, remove one user. 112 delete_user($user2); 113 $preferences = message_airnotifier_external::are_notification_preferences_configured($params); 114 $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); 115 $this->assertEquals(1, count($preferences['users'])); 116 $this->assertEquals($expected, $preferences['users']); 117 $this->assertEquals(2, count($preferences['warnings'])); 118 119 // Now, remove one user1 preference (the user still has one prefernce for airnotifier). 120 unset_user_preference('message_provider_moodle_instantmessage_loggedin', $user1); 121 $preferences = message_airnotifier_external::are_notification_preferences_configured($params); 122 $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); 123 $this->assertEquals($expected, $preferences['users']); 124 125 // Delete the last user1 preference. 126 unset_user_preference('message_provider_moodle_instantmessage_loggedoff', $user1); 127 $preferences = message_airnotifier_external::are_notification_preferences_configured($params); 128 $preferences = external_api::clean_returnvalue($returnsdescription, $preferences); 129 $expected = array( 130 array( 131 'userid' => $user1->id, 132 'configured' => 0 133 ) 134 ); 135 $this->assertEquals($expected, $preferences['users']); 136 } 137 138 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |