Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 30... Línea 30...
30
 *
30
 *
31
 * @package    mod_forum
31
 * @package    mod_forum
32
 * @copyright  2013 Frédéric Massart
32
 * @copyright  2013 Frédéric Massart
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34
 */
34
 */
35
class lib_test extends \advanced_testcase {
35
final class lib_test extends \advanced_testcase {
Línea 36... Línea 36...
36
 
36
 
-
 
37
    public function setUp(): void {
37
    public function setUp(): void {
38
        parent::setUp();
38
        // We must clear the subscription caches. This has to be done both before each test, and after in case of other
39
        // We must clear the subscription caches. This has to be done both before each test, and after in case of other
39
        // tests using these functions.
40
        // tests using these functions.
40
        \mod_forum\subscriptions::reset_forum_cache();
41
        \mod_forum\subscriptions::reset_forum_cache();
Línea 41... Línea 42...
41
    }
42
    }
42
 
43
 
43
    public function tearDown(): void {
44
    public function tearDown(): void {
44
        // We must clear the subscription caches. This has to be done both before each test, and after in case of other
45
        // We must clear the subscription caches. This has to be done both before each test, and after in case of other
-
 
46
        // tests using these functions.
45
        // tests using these functions.
47
        \mod_forum\subscriptions::reset_forum_cache();
Línea 46... Línea 48...
46
        \mod_forum\subscriptions::reset_forum_cache();
48
        parent::tearDown();
47
    }
49
    }
Línea 3267... Línea 3269...
3267
    /**
3269
    /**
3268
     * Dataprovider for forum_discussion_is_locked tests.
3270
     * Dataprovider for forum_discussion_is_locked tests.
3269
     *
3271
     *
3270
     * @return  array
3272
     * @return  array
3271
     */
3273
     */
3272
    public function forum_discussion_is_locked_provider() {
3274
    public static function forum_discussion_is_locked_provider(): array {
3273
        return [
3275
        return [
3274
            'Unlocked: lockdiscussionafter is false' => [
3276
            'Unlocked: lockdiscussionafter is false' => [
3275
                ['lockdiscussionafter' => false],
3277
                ['lockdiscussionafter' => false],
3276
                [],
3278
                [],
3277
                false
3279
                false
Línea 3321... Línea 3323...
3321
    /**
3323
    /**
3322
     * Dataprovider for forum_is_cutoff_date_reached tests.
3324
     * Dataprovider for forum_is_cutoff_date_reached tests.
3323
     *
3325
     *
3324
     * @return  array
3326
     * @return  array
3325
     */
3327
     */
3326
    public function forum_is_cutoff_date_reached_provider() {
3328
    public static function forum_is_cutoff_date_reached_provider(): array {
3327
        $now = time();
3329
        $now = time();
3328
        return [
3330
        return [
3329
            'cutoffdate is unset' => [
3331
            'cutoffdate is unset' => [
3330
                [],
3332
                [],
3331
                false
3333
                false
Línea 3369... Línea 3371...
3369
    /**
3371
    /**
3370
     * Dataprovider for forum_is_due_date_reached tests.
3372
     * Dataprovider for forum_is_due_date_reached tests.
3371
     *
3373
     *
3372
     * @return  array
3374
     * @return  array
3373
     */
3375
     */
3374
    public function forum_is_due_date_reached_provider() {
3376
    public static function forum_is_due_date_reached_provider(): array {
3375
        $now = time();
3377
        $now = time();
3376
        return [
3378
        return [
3377
            'duedate is unset' => [
3379
            'duedate is unset' => [
3378
                [],
3380
                [],
3379
                false
3381
                false
Línea 4116... Línea 4118...
4116
    /**
4118
    /**
4117
     * Provides data for tests that cause forum_check_throttling to return early.
4119
     * Provides data for tests that cause forum_check_throttling to return early.
4118
     *
4120
     *
4119
     * @return array
4121
     * @return array
4120
     */
4122
     */
4121
    public function forum_check_throttling_early_returns_provider() {
4123
    public static function forum_check_throttling_early_returns_provider(): array {
4122
        return [
4124
        return [
4123
            'Empty blockafter' => [(object)['id' => 1, 'course' => SITEID, 'blockafter' => 0]],
4125
            'Empty blockafter' => [(object)['id' => 1, 'course' => SITEID, 'blockafter' => 0]],
4124
            'Empty blockperiod' => [(object)['id' => 1, 'course' => SITEID, 'blockafter' => DAYSECS, 'blockperiod' => 0]],
4126
            'Empty blockperiod' => [(object)['id' => 1, 'course' => SITEID, 'blockafter' => DAYSECS, 'blockperiod' => 0]],
4125
        ];
4127
        ];
4126
    }
4128
    }
Línea 4139... Línea 4141...
4139
    /**
4141
    /**
4140
     * Provides data for tests that cause forum_check_throttling to throw exceptions early.
4142
     * Provides data for tests that cause forum_check_throttling to throw exceptions early.
4141
     *
4143
     *
4142
     * @return array
4144
     * @return array
4143
     */
4145
     */
4144
    public function forum_check_throttling_early_exceptions_provider() {
4146
    public static function forum_check_throttling_early_exceptions_provider(): array {
4145
        return [
4147
        return [
4146
            'Non-object forum' => ['a'],
4148
            'Non-object forum' => ['a'],
4147
            'Forum ID not set' => [(object)['id' => false]],
4149
            'Forum ID not set' => [(object)['id' => false]],
4148
            'Course ID not set' => [(object)['id' => 1]],
4150
            'Course ID not set' => [(object)['id' => 1]],
4149
        ];
4151
        ];
Línea 4369... Línea 4371...
4369
 
4371
 
4370
        // Make sure there are no discussions.
4372
        // Make sure there are no discussions.
4371
        $f3discussionscount = forum_count_discussions($forum3, $forum3cm, $course2);
4373
        $f3discussionscount = forum_count_discussions($forum3, $forum3cm, $course2);
4372
        $this->assertEquals(0, $f3discussionscount);
4374
        $this->assertEquals(0, $f3discussionscount);
-
 
4375
    }
-
 
4376
 
-
 
4377
    /**
-
 
4378
     * @covers ::forum_reset_userdata
-
 
4379
     */
-
 
4380
    public function test_forum_reset_userdata(): void {
-
 
4381
        global $DB;
-
 
4382
 
-
 
4383
        $this->resetAfterTest();
-
 
4384
        $this->setAdminUser();
-
 
4385
 
-
 
4386
        $now = time();
-
 
4387
 
-
 
4388
        $course = $this->getDataGenerator()->create_course();
-
 
4389
        $forum = $this->getDataGenerator()->create_module('forum', [
-
 
4390
            'course' => $course->id,
-
 
4391
            'duedate' => $now + HOURSECS,
-
 
4392
            'cutoffdate' => $now + DAYSECS,
-
 
4393
        ]);
-
 
4394
 
-
 
4395
        forum_reset_userdata((object) [
-
 
4396
            'courseid' => $course->id,
-
 
4397
            'timeshift' => DAYSECS * 2,
-
 
4398
        ]);
-
 
4399
 
-
 
4400
        // Reload the instance data.
-
 
4401
        $instance = $DB->get_record('forum', ['id' => $forum->id]);
-
 
4402
 
-
 
4403
        $this->assertEquals($forum->duedate + (DAYSECS * 2), $instance->duedate);
-
 
4404
        $this->assertEquals($forum->cutoffdate + (DAYSECS * 2), $instance->cutoffdate);
4373
    }
4405
    }