From f588ea50082aa9a3f20499331edb4325b6e0c5d8 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Mon, 6 Jan 2014 10:20:23 +0100 Subject: [PATCH] MDL-42995 mod_assign: Extended tests for update_calendar method --- mod/assign/tests/locallib_test.php | 38 ++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 766f8514668..c7512201959 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -296,15 +296,45 @@ class mod_assign_locallib_testcase extends mod_assign_base_testcase { public function test_update_calendar() { global $DB; - $now = time(); $this->setUser($this->editingteachers[0]); - $assign = $this->create_instance(array('duedate'=>$now)); + $userctx = context_user::instance($this->editingteachers[0]->id)->id; + + // Hack to pretend that there was an editor involved. We need both $_POST and $_REQUEST, and a sesskey. + $draftid = file_get_unused_draft_itemid(); + $_REQUEST['introeditor'] = $draftid; + $_POST['introeditor'] = $draftid; + $_POST['sesskey'] = sesskey(); + + // Write links to a draft area. + $fakearealink1 = file_rewrite_pluginfile_urls('link', 'draftfile.php', $userctx, + 'user', 'draft', $draftid); + $fakearealink2 = file_rewrite_pluginfile_urls('new', 'draftfile.php', $userctx, + 'user', 'draft', $draftid); + + // Create a new assignment with links to a draft area. + $now = time(); + $assign = $this->create_instance(array( + 'duedate' => $now, + 'intro' => $fakearealink1, + 'introformat' => FORMAT_HTML + )); // See if there is an event in the calendar. $params = array('modulename'=>'assign', 'instance'=>$assign->get_instance()->id); - $id = $DB->get_field('event', 'id', $params); + $event = $DB->get_record('event', $params); + $this->assertNotEmpty($event); + $this->assertSame('link', $event->description); // The pluginfile links are removed. - $this->assertEquals(false, empty($id)); + // Make sure the same works when updating the assignment. + $instance = $assign->get_instance(); + $instance->instance = $instance->id; + $instance->intro = $fakearealink2; + $instance->introformat = FORMAT_HTML; + $assign->update_instance($instance); + $params = array('modulename' => 'assign', 'instance' => $assign->get_instance()->id); + $event = $DB->get_record('event', $params); + $this->assertNotEmpty($event); + $this->assertSame('new', $event->description); // The pluginfile links are removed. } public function test_update_instance() { -- 2.43.0