Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdrasCaleb committed Apr 29, 2024
1 parent d6de891 commit b4e8df4
Showing 1 changed file with 40 additions and 19 deletions.
59 changes: 40 additions & 19 deletions tests/tool_deletemessage.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,59 @@
<?php
/**
* Delete Task.
*
* @package tool_deletemessage
* @author Esdras Caleb
* @copyright 2023 Esdras Caleb
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_deletemessage;



class auth_ldap_test extends \advanced_testcase {
/**
* Class test if this plugin is deleting things it should not delete
* @author Esdras Caleb
* @copyright 2023 Esdras Caleb
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_deletemessage_test extends \advanced_testcase {
/**
* Test if the hard delection function works
* @return void
*/
public function test_deleting() {
global $CFG,$DB;
global $CFG, $DB;
require_once($CFG->dirroot.'/admin/tool/deletemessage/locallib.php');
$user_from = $this->getDataGenerator()->create_user();
$user_to = $this->getDataGenerator()->create_user();
$userfrom = $this->getDataGenerator()->create_user();
$userto = $this->getDataGenerator()->create_user();

// Message text
$message_text = "hello";
// Message text.
$messagetext = "hello";

// Create message object
// Create message object.
$message = new \core\message\message();
$message->component = 'core';
$message->name = 'instantmessage';
$message->userfrom = $user_from;
$message->userto = $user_to;
$message->userfrom = $userfrom;
$message->userto = $userto;
$message->subject = '';
$message->fullmessage = $message_text;
$message->fullmessage = $messagetext;
$message->fullmessageformat = FORMAT_PLAIN;
$message->fullmessagehtml = $message_text;
$message->smallmessage = $message_text;
$message->fullmessagehtml = $messagetext;
$message->smallmessage = $messagetext;

// Send message
// Send message.
$messageid = message_send($message);
$this->assertNotEmpty($DB->get_records('message',['id'=>$messageid]));
$this->assertNotEmpty($DB->get_records('message', ['id' => $messageid]));
hard_delete_message($messageid);
$this->assertEmpty($DB->get_records('message',['id'=>$messageid]));
$this->assertEmpty($DB->get_records('message', ['id' => $messageid]));
}

/**
* Test taks of delection to not delete all messages
* @return void
*/
public function test_taks_isnotdeleting() {
global $CFG,$DB;
require_once($CFG->dirroot.'/admin/tool/deletemessage/locallib.php');
Expand All @@ -56,9 +77,9 @@ public function test_taks_isnotdeleting() {

// Send message
$messageid = message_send($message);
$this->assertNotEmpty($DB->get_records('message',['id'=>$messageid]));
$cron = new \tool_deletemessage\task\delete();
$cron->execute();
$this->assertNotEmpty($DB->get_records('message',['id'=>$messageid]));
$this->assertNotEmpty($DB->get_records('message', ['id' => $messageid]));
$this->assertNotEmpty($DB->get_records('message'));
}
}
}

0 comments on commit b4e8df4

Please sign in to comment.