Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 12... Línea 12...
12
// GNU General Public License for more details.
12
// GNU General Public License for more details.
13
//
13
//
14
// You should have received a copy of the GNU General Public License
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/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea -...
16
 
-
 
17
/**
-
 
18
 * Contains unit tests for mod_chat\dates.
-
 
19
 *
-
 
20
 * @package   mod_chat
-
 
21
 * @category  test
-
 
22
 * @copyright 2021 Dongsheng Cai
-
 
23
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
24
 */
-
 
25
 
16
 
Línea 26... Línea 17...
26
declare(strict_types=1);
17
declare(strict_types=1);
Línea 27... Línea 18...
27
 
18
 
28
namespace mod_chat;
19
namespace mod_chat;
29
 
20
 
Línea 30... Línea 21...
30
use advanced_testcase;
21
use advanced_testcase;
31
use cm_info;
22
use cm_info;
-
 
23
use core\activity_dates;
-
 
24
 
-
 
25
/**
-
 
26
 * Class for unit testing mod_chat\dates.
-
 
27
 *
32
use core\activity_dates;
28
 * @package   mod_chat
33
 
29
 * @category  test
Línea 34... Línea 30...
34
/**
30
 * @copyright 2021 Dongsheng Cai
35
 * Class for unit testing mod_chat\dates.
31
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
32
 */
37
class dates_test extends advanced_testcase {
33
final class dates_test extends advanced_testcase {
Línea 47... Línea 43...
47
 
43
 
48
    /**
44
    /**
49
     * Data provider for get_dates_for_module().
45
     * Data provider for get_dates_for_module().
50
     * @return array[]
46
     * @return array[]
51
     */
47
     */
52
    public function get_dates_for_module_provider(): array {
48
    public static function get_dates_for_module_provider(): array {
53
        global $CFG;
49
        global $CFG;
Línea 54... Línea 50...
54
        require_once($CFG->dirroot . '/mod/chat/lib.php');
50
        require_once($CFG->dirroot . '/mod/chat/lib.php');
55
 
51
 
Línea 59... Línea 55...
59
 
55
 
60
        $dailynextchattime = $past + 2 * DAYSECS;
56
        $dailynextchattime = $past + 2 * DAYSECS;
61
        $weeklynextchattime = $past + 7 * DAYSECS;
57
        $weeklynextchattime = $past + 7 * DAYSECS;
62
        $label = get_string('nextchattime', 'mod_chat');
58
        $label = get_string('nextchattime', 'mod_chat');
63
        return [
59
        return [
64
            'chattime in the past' => [
60
            'chattime in the past (no schedule)' => [
65
                $past, CHAT_SCHEDULE_NONE, []
61
                $past, CHAT_SCHEDULE_NONE, []
66
            ],
62
            ],
67
            'chattime in the past' => [
63
            'chattime in the past (single schedule)' => [
68
                $past, CHAT_SCHEDULE_SINGLE, []
64
                $past, CHAT_SCHEDULE_SINGLE, []
69
            ],
65
            ],
70
            'chattime in the future' => [
66
            'chattime in the future' => [
71
                $future, CHAT_SCHEDULE_SINGLE, [
67
                $future, CHAT_SCHEDULE_SINGLE, [
Línea 121... Línea 117...
121
     * @dataProvider get_dates_for_module_provider
117
     * @dataProvider get_dates_for_module_provider
122
     * @param int|null $chattime
118
     * @param int|null $chattime
123
     * @param int|null $schedule
119
     * @param int|null $schedule
124
     * @param array $expected The expected value of calling get_dates_for_module()
120
     * @param array $expected The expected value of calling get_dates_for_module()
125
     */
121
     */
126
    public function test_get_dates_for_module(?int $chattime, ?int $schedule, array $expected) {
122
    public function test_get_dates_for_module(?int $chattime, ?int $schedule, array $expected): void {
127
        $this->resetAfterTest();
123
        $this->resetAfterTest();
128
        $course = $this->getDataGenerator()->create_course();
124
        $course = $this->getDataGenerator()->create_course();
129
        $user = $this->getDataGenerator()->create_user();
125
        $user = $this->getDataGenerator()->create_user();
130
        $this->getDataGenerator()->enrol_user($user->id, $course->id);
126
        $this->getDataGenerator()->enrol_user($user->id, $course->id);
131
        $chat = ['course' => $course->id];
127
        $chat = ['course' => $course->id];