17 if (!defined(
'ANONYMOUS_USER_ID')) {
18 define(
'ANONYMOUS_USER_ID', 13);
32 $defaultTransport = $this->getMockBuilder(\ilMailMimeTransport::class)->getMock();
33 $defaultTransport->expects($this->never())->method(
'send');
35 $transport = $this->getMockBuilder(\ilMailMimeTransport::class)->getMock();
36 $transport->expects($this->
once())->method(
'send');
38 $transportFactory = $this->getMockBuilder(\ilMailMimeTransportFactory::class)->disableOriginalConstructor()->getMock();
39 $transportFactory->expects($this->any())->method(
'getTransport')->will($this->returnValue($defaultTransport));
42 $settings = $this->getMockBuilder(
'\ilSetting')->disableOriginalConstructor()->setMethods(array(
48 $mail = new \ilMimeMail();
49 $mail->send($transport);
57 $defaultTransport = $this->getMockBuilder(\ilMailMimeTransport::class)->getMock();
58 $defaultTransport->expects($this->
once())->method(
'send');
60 $transportFactory = $this->getMockBuilder(\ilMailMimeTransportFactory::class)->disableOriginalConstructor()->getMock();
61 $transportFactory->expects($this->any())->method(
'getTransport')->will($this->returnValue($defaultTransport));
64 $settings = $this->getMockBuilder(
'\ilSetting')->disableOriginalConstructor()->setMethods(array(
70 $mail = new \ilMimeMail();
79 $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
83 $settings->expects($this->any())->method(
'get')->will($this->returnCallback(
function (
$key) {
84 if (
'mail_allow_external' ==
$key) {
92 $eventHandler = $this->getMockBuilder(\ilAppEventHandler::class)->disableOriginalConstructor()->setMethods(array(
96 $factory = new \ilMailMimeTransportFactory($settings, $eventHandler);
97 $this->assertInstanceOf(
'\ilMailMimeTransportNull',
$factory->getTransport());
105 $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
109 $settings->expects($this->any())->method(
'get')->will($this->returnCallback(
function (
$key) {
110 if (
'mail_allow_external' ==
$key) {
115 if (
'mail_smtp_status' ==
$key) {
123 $eventHandler = $this->getMockBuilder(\ilAppEventHandler::class)->disableOriginalConstructor()->setMethods(array(
127 $factory = new \ilMailMimeTransportFactory($settings, $eventHandler);
128 $this->assertInstanceOf(
'\ilMailMimeTransportSmtp',
$factory->getTransport());
136 $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
141 $settings->expects($this->any())->method(
'get')->will($this->returnCallback(
function (
$key) {
142 if (
'mail_allow_external' ==
$key) {
147 if (
'mail_smtp_status' ==
$key) {
155 $eventHandler = $this->getMockBuilder(\ilAppEventHandler::class)->disableOriginalConstructor()->setMethods(array(
159 $factory = new \ilMailMimeTransportFactory($settings, $eventHandler);
160 $this->assertInstanceOf(
'\ilMailMimeTransportSendMail',
$factory->getTransport());
168 $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
173 $factory = new \ilMailMimeSenderFactory($settings);
174 $this->assertInstanceOf(
'\ilMailMimeSenderSystem',
$factory->getSenderByUsrId(\ANONYMOUS_USER_ID));
182 $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
187 $factory = new \ilMailMimeSenderFactory($settings);
188 $this->assertInstanceOf(
'\ilMailMimeSenderSystem',
$factory->system());
197 $user = $this->getMockBuilder(\ilObjUser::class)->disableOriginalConstructor()->setMethods(
200 $user->expects($this->any())->method(
'getId')->will($this->returnValue($usrId));
210 $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
215 $factory = new \ilMailMimeSenderFactory($settings);
216 $this->assertInstanceOf(
'\ilMailMimeSenderUser',
$factory->getSenderByUsrId(self::USER_ID));
224 $settings = $this->getMockBuilder(\ilSetting::class)->disableOriginalConstructor()->setMethods(array(
229 $factory = new \ilMailMimeSenderFactory($settings);
230 $this->assertInstanceOf(
'\ilMailMimeSenderUser',
$factory->user(self::USER_ID));
static setDefaultTransport($transport)
testFactoryWillReturnUserSenderForExistingUserId()
testTransportFactoryWillReturnSendmailTransportIfSmtpTransportIsDisabled()
testFactoryWillReturnSystemSenderForAnonymousUserId()
testFactoryWillReturnSystemSenderWhenExplicitlyRequested()
static addUserToCache($usrId, \ilObjUser $user)
testMimMailDelegatesEmailDeliveryToDefaultTransport()
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
testMimMailDelegatesEmailDeliveryToThePassedTransporter()
setGlobalVariable($name, $value)
testTransportFactoryWillReturnNullTransportIfExternalEmailDeliveryIsDisabled()
testFactoryWillReturnUserSenderWhenExplicitlyRequested()
testTransportFactoryWillReturnSmtpTransportIfEnabled()