ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RecipientTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25
27{
28 public function testCreate(): void
29 {
30 $user_id = 10;
31 $user = $this->createMock(ilObjUser::class);
32 $mail_options = $this->createMock(ilMailOptions::class);
33 $recipient = new Recipient($user_id, $user, $mail_options, $this->createMock(Conductor::class));
34 $this->assertEquals($user_id, $recipient->getUserId());
35 $this->assertSame($mail_options, $recipient->getMailOptions());
36
37 $recipient = new Recipient($user_id, null, $mail_options, $this->createMock(Conductor::class));
38 $this->assertEquals($user_id, $recipient->getUserId());
39 $this->assertSame($mail_options, $recipient->getMailOptions());
40 }
41
42 public function testCheckProperties(): void
43 {
44 $user_id = 10;
45 $mail = "mail@test.de";
46 $mail_2 = "mail2@test.de";
47 $external_mails = [$mail, $mail_2];
48
49 $result = $this->createMock(Result::class);
50
51 $transformation = $this->createMock(Transformation::class);
52 $transformation->expects(self::once())->method('applyTo')->willReturn($result);
53
54 $legal_documents = $this->createMock(Conductor::class);
55 $legal_documents->expects(self::once())->method('userCanReadInternalMail')->willReturn($transformation);
56
57 $user = $this->createMock(ilObjUser::class);
58 $user->expects($this->once())
59 ->method("getActive")
60 ->willReturn(true);
61 $user->expects($this->once())
62 ->method("checkTimeLimit")
63 ->willReturn(true);
64
65 $mail_options = $this->createMock(ilMailOptions::class);
66 $mail_options->expects($this->exactly(3))
67 ->method("getIncomingType")
68 ->willReturn(2);
69
70 $mail_options->expects($this->atLeastOnce())
71 ->method("getExternalEmailAddresses")
72 ->willReturn($external_mails);
73
74 $recipient = new Recipient($user_id, $user, $mail_options, $legal_documents);
75 $this->assertEquals($user_id, $recipient->getUserId());
76 $this->assertTrue($recipient->isUser());
77 $this->assertSame($result, $recipient->evaluateInternalMailReadability());
78 $this->assertTrue($recipient->isUserActive());
79
80 $this->assertSame($mail_options, $recipient->getMailOptions());
81 $this->assertTrue($recipient->userWantsToReceiveExternalMails());
82 $this->assertFalse($recipient->onlyToExternalMailAddress());
83 $this->assertIsArray($recipient->getExternalMailAddress());
84 $this->assertCount(2, $recipient->getExternalMailAddress());
85 $this->assertContainsOnly('string', $recipient->getExternalMailAddress());
86 }
87
88 public function testPropertiesPart2(): void
89 {
90 $user_id = 133;
91 $mail = "mails@test.de";
92 $mail_2 = "mails2@test.de";
93 $external_mails = [$mail, $mail_2];
94
95 $legal_documents = $this->createMock(Conductor::class);
96 $legal_documents->expects(self::never())->method('userCanReadInternalMail');
97
98 $user = $this->createMock(ilObjUser::class);
99 $user->expects($this->once())
100 ->method("getActive")
101 ->willReturn(false);
102 $user->expects($this->once())
103 ->method("checkTimeLimit")
104 ->willReturn(false);
105
106 $mail_options = $this->createMock(ilMailOptions::class);
107 $mail_options->expects($this->exactly(3))
108 ->method("getIncomingType")
109 ->willReturn(0);
110
111 $mail_options->expects($this->atLeastOnce())
112 ->method("getExternalEmailAddresses")
113 ->willReturn($external_mails);
114
115 $recipient = new Recipient($user_id, $user, $mail_options, $legal_documents);
116 $this->assertEquals($user_id, $recipient->getUserId());
117 $this->assertTrue($recipient->isUser());
118 $result = $recipient->evaluateInternalMailReadability();
119 $this->assertFalse($result->isOk());
120 $this->assertSame('Account expired.', $result->error());
121 $this->assertFalse($recipient->isUserActive());
122
123 $this->assertSame($mail_options, $recipient->getMailOptions());
124 $this->assertFalse($recipient->userWantsToReceiveExternalMails());
125 $this->assertFalse($recipient->onlyToExternalMailAddress());
126 $this->assertIsArray($recipient->getExternalMailAddress());
127 $this->assertCount(2, $recipient->getExternalMailAddress());
128 $this->assertContainsOnly('string', $recipient->getExternalMailAddress());
129 }
130}
A transformation is a function from one datatype to another.