|
37 | 37 | use CommonITILActor;
|
38 | 38 | use CommonITILObject;
|
39 | 39 | use DbTestCase;
|
| 40 | +use Glpi\RichText\UserMention; |
40 | 41 | use Notification;
|
41 | 42 | use Notification_NotificationTemplate;
|
42 | 43 | use NotificationTarget;
|
43 | 44 | use NotificationTemplate;
|
44 | 45 | use NotificationTemplateTranslation;
|
45 | 46 | use PHPUnit\Framework\Attributes\DataProvider;
|
| 47 | +use Profile; |
46 | 48 | use Session;
|
47 | 49 | use Ticket;
|
48 | 50 | use Ticket_User;
|
@@ -610,4 +612,91 @@ private function createNotification(string $itemtype): void
|
610 | 612 | );
|
611 | 613 | $this->assertGreaterThan(0, $target_id);
|
612 | 614 | }
|
| 615 | + |
| 616 | + public function testDisableMentions() |
| 617 | + { |
| 618 | + global $CFG_GLPI; |
| 619 | + $CFG_GLPI['use_notifications'] = 1; |
| 620 | + $CFG_GLPI['notifications_mailing'] = 1; |
| 621 | + |
| 622 | + $this->login(); |
| 623 | + $profiles_id = $_SESSION['glpiactiveprofile']['id']; |
| 624 | + $profile = new Profile(); |
| 625 | + $profile->update([ |
| 626 | + 'id' => $profiles_id, |
| 627 | + 'use_mentions' => UserMention::USER_MENTION_DISABLED, |
| 628 | + ]); |
| 629 | + |
| 630 | + $ticket = new Ticket(); |
| 631 | + $ticket->add([ |
| 632 | + 'name' => __FUNCTION__, |
| 633 | + 'content' => __FUNCTION__, |
| 634 | + 'entities_id' => $this->getTestRootEntity(true), |
| 635 | + ]); |
| 636 | + |
| 637 | + $options = UserMention::getMentionOptions($ticket); |
| 638 | + $this->assertEmpty($options['users']); |
| 639 | + $this->assertFalse($options['full']); |
| 640 | + } |
| 641 | + |
| 642 | + public function testRestrictMentions() |
| 643 | + { |
| 644 | + global $CFG_GLPI; |
| 645 | + $CFG_GLPI['use_notifications'] = 1; |
| 646 | + $CFG_GLPI['notifications_mailing'] = 1; |
| 647 | + |
| 648 | + $this->login(); |
| 649 | + $profiles_id = $_SESSION['glpiactiveprofile']['id']; |
| 650 | + $profile = new Profile(); |
| 651 | + $profile->update([ |
| 652 | + 'id' => $profiles_id, |
| 653 | + 'use_mentions' => UserMention::USER_MENTION_RESTRICTED, |
| 654 | + ]); |
| 655 | + |
| 656 | + $ticket = new Ticket(); |
| 657 | + $ticket->add([ |
| 658 | + 'name' => __FUNCTION__, |
| 659 | + 'content' => __FUNCTION__, |
| 660 | + 'entities_id' => $this->getTestRootEntity(true), |
| 661 | + ]); |
| 662 | + $options = UserMention::getMentionOptions($ticket); |
| 663 | + $this->assertEmpty($options['users']); |
| 664 | + $this->assertFalse($options['full']); |
| 665 | + |
| 666 | + $ticket_user = new Ticket_User(); |
| 667 | + $ticket_user->add([ |
| 668 | + 'tickets_id' => $ticket->getID(), |
| 669 | + 'users_id' => Session::getLoginUserID(), |
| 670 | + 'type' => 2, |
| 671 | + ]); |
| 672 | + |
| 673 | + $options = UserMention::getMentionOptions($ticket); |
| 674 | + $this->assertCount(1, $options['users']); |
| 675 | + $this->assertFalse($options['full']); |
| 676 | + } |
| 677 | + |
| 678 | + public function testFullMentions() |
| 679 | + { |
| 680 | + global $CFG_GLPI; |
| 681 | + $CFG_GLPI['use_notifications'] = 1; |
| 682 | + $CFG_GLPI['notifications_mailing'] = 1; |
| 683 | + |
| 684 | + $this->login(); |
| 685 | + $profiles_id = $_SESSION['glpiactiveprofile']['id']; |
| 686 | + $profile = new Profile(); |
| 687 | + $profile->update([ |
| 688 | + 'id' => $profiles_id, |
| 689 | + 'use_mentions' => UserMention::USER_MENTION_FULL, |
| 690 | + ]); |
| 691 | + |
| 692 | + $ticket = new Ticket(); |
| 693 | + $ticket->add([ |
| 694 | + 'name' => __FUNCTION__, |
| 695 | + 'content' => __FUNCTION__, |
| 696 | + 'entities_id' => $this->getTestRootEntity(true), |
| 697 | + ]); |
| 698 | + $options = UserMention::getMentionOptions($ticket); |
| 699 | + $this->assertEmpty($options['users']); |
| 700 | + $this->assertTrue($options['full']); |
| 701 | + } |
613 | 702 | }
|
0 commit comments