ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailMimeTest.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
9 {
10  const USER_ID = 6;
11 
15  protected function setUp()
16  {
17  if (!defined('ANONYMOUS_USER_ID')) {
18  define('ANONYMOUS_USER_ID', 13);
19  }
20 
22  \ilMailMimeSenderUser::addUserToCache(self::USER_ID, $this->getUserById(self::USER_ID));
23 
24  parent::setUp();
25  }
26 
31  {
32  $defaultTransport = $this->getMockBuilder(\ilMailMimeTransport::class)->getMock();
33  $defaultTransport->expects($this->never())->method('send');
34 
35  $transport = $this->getMockBuilder(\ilMailMimeTransport::class)->getMock();
36  $transport->expects($this->once())->method('send');
37 
38  $transportFactory = $this->getMockBuilder(\ilMailMimeTransportFactory::class)->disableOriginalConstructor()->getMock();
39  $transportFactory->expects($this->any())->method('getTransport')->will($this->returnValue($defaultTransport));
40  $this->setGlobalVariable('mail.mime.transport.factory', $transportFactory);
41 
42  $settings = $this->getMockBuilder('\ilSetting')->disableOriginalConstructor()->setMethods(array(
43  'set',
44  'get'
45  ))->getMock();
46  $this->setGlobalVariable('ilSetting', $settings);
47 
48  $mail = new \ilMimeMail();
49  $mail->send($transport);
50  }
51 
56  {
57  $defaultTransport = $this->getMockBuilder(\ilMailMimeTransport::class)->getMock();
58  $defaultTransport->expects($this->once())->method('send');
59 
60  $transportFactory = $this->getMockBuilder(\ilMailMimeTransportFactory::class)->disableOriginalConstructor()->getMock();
61  $transportFactory->expects($this->any())->method('getTransport')->will($this->returnValue($defaultTransport));
62  $this->setGlobalVariable('mail.mime.transport.factory', $transportFactory);
63 
64  $settings = $this->getMockBuilder('\ilSetting')->disableOriginalConstructor()->setMethods(array(
65  'set',
66  'get'
67  ))->getMock();
68  $this->setGlobalVariable('ilSetting', $settings);
69 
70  $mail = new \ilMimeMail();
71  $mail->send();
72  }
73 
78  {
79  $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
80  'set',
81  'get'
82  ))->getMock();
83  $settings->expects($this->any())->method('get')->will($this->returnCallback(function ($key) {
84  if ('mail_allow_external' == $key) {
85  return false;
86  }
87 
88  return true;
89  }));
90  $this->setGlobalVariable('ilSetting', $settings);
91 
92  $eventHandler = $this->getMockBuilder(\ilAppEventHandler::class)->disableOriginalConstructor()->setMethods(array(
93  'raise',
94  ))->getMock();
95 
96  $factory = new \ilMailMimeTransportFactory($settings, $eventHandler);
97  $this->assertInstanceOf('\ilMailMimeTransportNull', $factory->getTransport());
98  }
99 
104  {
105  $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
106  'set',
107  'get'
108  ))->getMock();
109  $settings->expects($this->any())->method('get')->will($this->returnCallback(function ($key) {
110  if ('mail_allow_external' == $key) {
111  return true;
112  }
113 
114 
115  if ('mail_smtp_status' == $key) {
116  return true;
117  }
118 
119  return true;
120  }));
121  $this->setGlobalVariable('ilSetting', $settings);
122 
123  $eventHandler = $this->getMockBuilder(\ilAppEventHandler::class)->disableOriginalConstructor()->setMethods(array(
124  'raise',
125  ))->getMock();
126 
127  $factory = new \ilMailMimeTransportFactory($settings, $eventHandler);
128  $this->assertInstanceOf('\ilMailMimeTransportSmtp', $factory->getTransport());
129  }
130 
135  {
136  $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
137  'set',
138  'get'
139  ))->getMock();
140 
141  $settings->expects($this->any())->method('get')->will($this->returnCallback(function ($key) {
142  if ('mail_allow_external' == $key) {
143  return true;
144  }
145 
146 
147  if ('mail_smtp_status' == $key) {
148  return false;
149  }
150 
151  return true;
152  }));
153  $this->setGlobalVariable('ilSetting', $settings);
154 
155  $eventHandler = $this->getMockBuilder(\ilAppEventHandler::class)->disableOriginalConstructor()->setMethods(array(
156  'raise',
157  ))->getMock();
158 
159  $factory = new \ilMailMimeTransportFactory($settings, $eventHandler);
160  $this->assertInstanceOf('\ilMailMimeTransportSendMail', $factory->getTransport());
161  }
162 
167  {
168  $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
169  'set',
170  'get'
171  ))->getMock();
172 
173  $factory = new \ilMailMimeSenderFactory($settings);
174  $this->assertInstanceOf('\ilMailMimeSenderSystem', $factory->getSenderByUsrId(\ANONYMOUS_USER_ID));
175  }
176 
181  {
182  $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
183  'set',
184  'get'
185  ))->getMock();
186 
187  $factory = new \ilMailMimeSenderFactory($settings);
188  $this->assertInstanceOf('\ilMailMimeSenderSystem', $factory->system());
189  }
190 
195  protected function getUserById($usrId)
196  {
197  $user = $this->getMockBuilder(\ilObjUser::class)->disableOriginalConstructor()->setMethods(
198  array()
199  )->getMock();
200  $user->expects($this->any())->method('getId')->will($this->returnValue($usrId));
201 
202  return $user;
203  }
204 
209  {
210  $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
211  'set',
212  'get'
213  ))->getMock();
214 
215  $factory = new \ilMailMimeSenderFactory($settings);
216  $this->assertInstanceOf('\ilMailMimeSenderUser', $factory->getSenderByUsrId(self::USER_ID));
217  }
218 
223  {
224  $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
225  'set',
226  'get'
227  ))->getMock();
228 
229  $factory = new \ilMailMimeSenderFactory($settings);
230  $this->assertInstanceOf('\ilMailMimeSenderUser', $factory->user(self::USER_ID));
231  }
232 }
static setDefaultTransport($transport)
testFactoryWillReturnUserSenderForExistingUserId()
$factory
Definition: metadata.php:43
testTransportFactoryWillReturnSendmailTransportIfSmtpTransportIsDisabled()
testFactoryWillReturnSystemSenderForAnonymousUserId()
testFactoryWillReturnSystemSenderWhenExplicitlyRequested()
static addUserToCache($usrId, \ilObjUser $user)
Class ilMailBaseTest.
testMimMailDelegatesEmailDeliveryToDefaultTransport()
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
testMimMailDelegatesEmailDeliveryToThePassedTransporter()
$user
Definition: migrateto20.php:57
setGlobalVariable($name, $value)
testTransportFactoryWillReturnNullTransportIfExternalEmailDeliveryIsDisabled()
testFactoryWillReturnUserSenderWhenExplicitlyRequested()
testTransportFactoryWillReturnSmtpTransportIfEnabled()
$key
Definition: croninfo.php:18
Class ilMailMimeTest.