Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Jan 14, 2025
1 parent 4ed00a3 commit e3da24d
Showing 1 changed file with 165 additions and 0 deletions.
165 changes: 165 additions & 0 deletions phpunit/functional/PendingReasonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@
use CommonITILObject;
use DbTestCase;
use ITILFollowup;
use Notification;
use Notification_NotificationTemplate;
use NotificationTemplate;
use NotificationTemplateTranslation;
use PendingReason;
use PendingReason_Item;
use PHPUnit\Framework\Attributes\DataProvider;
use Problem;
use ProblemTask;
use SolutionTemplate;
use Ticket;
use TicketTask;

Expand Down Expand Up @@ -894,4 +900,163 @@ public function testHandlePendingReasonUpdateFromNewTimelineItem(): void
}
}
}

public function testNotificationEvents(): void
{
/** @var array $CFG_GLPI */
global $CFG_GLPI;

$notification = new Notification();
$entities_id = $this->getTestRootEntity(true);

$add_notifications_id = $notification->add([
'name' => 'Add PendingReason',
'entities_id' => $entities_id,
'itemtype' => 'Ticket',
'event' => 'pendingreason_add',
'is_active' => 1
]);

$remove_notifications_id = $notification->add([
'name' => 'Remove PendingReason',
'entities_id' => $entities_id,
'itemtype' => 'Ticket',
'event' => 'pendingreason_del',
'is_active' => 1
]);

$autoclose_notifications_id = $notification->add([
'name' => 'Auto close PendingReason',
'entities_id' => $entities_id,
'itemtype' => 'Ticket',
'event' => 'pendingreason_close',
'is_active' => 1
]);

$notification_template = new NotificationTemplate();
$notification_notification_template = new Notification_NotificationTemplate();

$add_template_id = $notification_template->add([
'name' => 'PendingReason Add',
'itemtype' => 'Ticket',
]);

$remove_template_id = $notification_template->add([
'name' => 'PendingReason Remove',
'itemtype' => 'Ticket',
]);

$autoclose_template_id = $notification_template->add([
'name' => 'PendingReason Auto close',
'itemtype' => 'Ticket',
]);

$notification_notification_template->add([
'notifications_id' => $add_notifications_id,
'mode' => 'mailing',
'notificationtemplates_id' => $add_template_id,
]);
$notification_notification_template->add([
'notifications_id' => $remove_notifications_id,
'mode' => 'mailing',
'notificationtemplates_id' => $remove_template_id,
]);
$notification_notification_template->add([
'notifications_id' => $autoclose_notifications_id,
'mode' => 'mailing',
'notificationtemplates_id' => $autoclose_template_id,
]);

$translation = new NotificationTemplateTranslation();
$translation->add([
'notificationtemplates_id' => $add_template_id,
'language' => '',
'subject' => 'PendingReason Add',
'content_text' => 'PendingReason Add',
'content_html' => 'PendingReason Add',
]);
$translation->add([
'notificationtemplates_id' => $remove_template_id,
'language' => '',
'subject' => 'PendingReason Remove',
'content_text' => 'PendingReason Remove',
'content_html' => 'PendingReason Remove',
]);
$translation->add([
'notificationtemplates_id' => $autoclose_template_id,
'language' => '',
'subject' => 'PendingReason Auto close',
'content_text' => 'PendingReason Auto close',
'content_html' => 'PendingReason Auto close',
]);

$target = new \NotificationTarget();
$target->add([
'notifications_id' => $add_notifications_id,
'type' => 1, // User
'items_id' => 7 // Writer
]);
$target->add([
'notifications_id' => $remove_notifications_id,
'type' => 1, // User
'items_id' => 7 // Writer
]);
$target->add([
'notifications_id' => $autoclose_notifications_id,
'type' => 1, // User
'items_id' => 7 // Writer
]);

$solutiontemplate = new SolutionTemplate();
$solutiontemplates_id = $solutiontemplate->add([
'name' => __FUNCTION__,
'content' => __FUNCTION__,
'entities_id' => $entities_id,
]);
$pending_reason = new PendingReason();
$pending_reason->add([
'name' => __FUNCTION__,
'entities_id' => $entities_id,
'followup_frequency' => DAY_TIMESTAMP,
'followups_before_resolution' => 3,
'solutiontemplates_id' => $solutiontemplates_id,
]);

$this->login();
$ticket = new Ticket();

$ticket->add([
'name' => __FUNCTION__,
'content' => __FUNCTION__,
'entities_id' => $entities_id,
'status' => CommonITILObject::WAITING,
]);

$CFG_GLPI['use_notifications'] = 1;
$CFG_GLPI['notifications_mailing'] = 1;

$this->assertTrue(PendingReason_Item::createForItem($ticket, [
'pendingreasons_id' => $pending_reason->getID(),
'followup_frequency' => DAY_TIMESTAMP,
'followups_before_resolution' => 3,
]));
$this->assertCount(1, getAllDataFromTable('glpi_queuednotifications', ['notificationtemplates_id' => $add_template_id]));

$pri = new PendingReason_Item();
$this->assertTrue($pri->getFromDBByCrit([
'items_id' => $ticket->getID(),
'itemtype' => $ticket::getType(),
]));
$this->assertTrue($pri->update([
'id' => $pri->getID(),
'bump_count' => 3,
'last_bump_date' => date('Y-m-d H:i:s', time() - (2 * DAY_TIMESTAMP)),
]));

\PendingReasonCron::cronPendingreason_autobump_autosolve(new \CronTask());
$this->assertCount(1, getAllDataFromTable('glpi_queuednotifications', ['notificationtemplates_id' => $autoclose_template_id]));

PendingReason_Item::deleteForItem($ticket);
$this->assertCount(1, getAllDataFromTable('glpi_queuednotifications', ['notificationtemplates_id' => $remove_template_id]));
}
}

0 comments on commit e3da24d

Please sign in to comment.