/** * Test the method get_eventobject_for_processor(). */ public function test_get_eventobject_for_processor() { global $USER; $this->resetAfterTest(); $this->setAdminUser(); $user = $this->getDataGenerator()->create_user(); $message = new \core\message\message(); $message->courseid = SITEID; $message->component = 'moodle'; $message->name = 'instantmessage'; $message->userfrom = $USER; $message->userto = $user; $message->subject = 'message subject 1'; $message->fullmessage = 'message body'; $message->fullmessageformat = FORMAT_MARKDOWN; $message->fullmessagehtml = '<p>message body</p>'; $message->smallmessage = 'small message'; $message->notification = '0'; $message->contexturl = 'http://GalaxyFarFarAway.com'; $message->contexturlname = 'Context name'; $message->replyto = "*****@*****.**"; $message->attachname = 'attachment'; $content = array('*' => array('header' => ' test ', 'footer' => ' test ')); // Extra content for all types of messages. $message->set_additional_content('test', $content); // Create a file instance. $usercontext = context_user::instance($user->id); $file = new stdClass(); $file->contextid = $usercontext->id; $file->component = 'user'; $file->filearea = 'private'; $file->itemid = 0; $file->filepath = '/'; $file->filename = '1.txt'; $file->source = 'test'; $fs = get_file_storage(); $file = $fs->create_file_from_string($file, 'file1 content'); $message->attachment = $file; $stdclass = $message->get_eventobject_for_processor('test'); $this->assertSame($message->courseid, $stdclass->courseid); $this->assertSame($message->component, $stdclass->component); $this->assertSame($message->name, $stdclass->name); $this->assertSame($message->userfrom, $stdclass->userfrom); $this->assertSame($message->userto, $stdclass->userto); $this->assertSame($message->subject, $stdclass->subject); $this->assertSame(' test ' . $message->fullmessage . ' test ', $stdclass->fullmessage); $this->assertSame(' test ' . $message->fullmessagehtml . ' test ', $stdclass->fullmessagehtml); $this->assertSame(' test ' . $message->smallmessage . ' test ', $stdclass->smallmessage); $this->assertSame($message->notification, $stdclass->notification); $this->assertSame($message->contexturl, $stdclass->contexturl); $this->assertSame($message->contexturlname, $stdclass->contexturlname); $this->assertSame($message->replyto, $stdclass->replyto); $this->assertSame($message->attachname, $stdclass->attachname); // Extra content for fullmessage only. $content = array('fullmessage' => array('header' => ' test ', 'footer' => ' test ')); $message->set_additional_content('test', $content); $stdclass = $message->get_eventobject_for_processor('test'); $this->assertSame(' test ' . $message->fullmessage . ' test ', $stdclass->fullmessage); $this->assertSame($message->fullmessagehtml, $stdclass->fullmessagehtml); $this->assertSame($message->smallmessage, $stdclass->smallmessage); // Extra content for fullmessagehtml and smallmessage only. $content = array('fullmessagehtml' => array('header' => ' test ', 'footer' => ' test '), 'smallmessage' => array('header' => ' testsmall ', 'footer' => ' testsmall ')); $message->set_additional_content('test', $content); $stdclass = $message->get_eventobject_for_processor('test'); $this->assertSame($message->fullmessage, $stdclass->fullmessage); $this->assertSame(' test ' . $message->fullmessagehtml . ' test ', $stdclass->fullmessagehtml); $this->assertSame(' testsmall ' . $message->smallmessage . ' testsmall ', $stdclass->smallmessage); // Extra content for * and smallmessage. $content = array('*' => array('header' => ' test ', 'footer' => ' test '), 'smallmessage' => array('header' => ' testsmall ', 'footer' => ' testsmall ')); $message->set_additional_content('test', $content); $stdclass = $message->get_eventobject_for_processor('test'); $this->assertSame(' test ' . $message->fullmessage . ' test ', $stdclass->fullmessage); $this->assertSame(' test ' . $message->fullmessagehtml . ' test ', $stdclass->fullmessagehtml); $this->assertSame(' testsmall ' . ' test ' . $message->smallmessage . ' test ' . ' testsmall ', $stdclass->smallmessage); }