|
|
@ -2,15 +2,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Mail;
|
|
|
|
namespace Engelsystem\Test\Unit\Mail;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Engelsystem\Helpers\Translation\Translator;
|
|
|
|
use Engelsystem\Mail\EngelsystemMailer;
|
|
|
|
use Engelsystem\Mail\EngelsystemMailer;
|
|
|
|
|
|
|
|
use Engelsystem\Models\User\Contact;
|
|
|
|
|
|
|
|
use Engelsystem\Models\User\Settings;
|
|
|
|
|
|
|
|
use Engelsystem\Models\User\User;
|
|
|
|
use Engelsystem\Renderer\Renderer;
|
|
|
|
use Engelsystem\Renderer\Renderer;
|
|
|
|
|
|
|
|
use Engelsystem\Test\Unit\HasDatabase;
|
|
|
|
|
|
|
|
use Engelsystem\Test\Unit\TestCase;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
use Swift_Mailer as SwiftMailer;
|
|
|
|
use Swift_Mailer as SwiftMailer;
|
|
|
|
use Swift_Message as SwiftMessage;
|
|
|
|
use Swift_Message as SwiftMessage;
|
|
|
|
|
|
|
|
|
|
|
|
class EngelsystemMailerTest extends TestCase
|
|
|
|
class EngelsystemMailerTest extends TestCase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
use HasDatabase;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::__construct
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::__construct
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::sendView
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::sendView
|
|
|
@ -24,21 +31,69 @@ class EngelsystemMailerTest extends TestCase
|
|
|
|
/** @var EngelsystemMailer|MockObject $mailer */
|
|
|
|
/** @var EngelsystemMailer|MockObject $mailer */
|
|
|
|
$mailer = $this->getMockBuilder(EngelsystemMailer::class)
|
|
|
|
$mailer = $this->getMockBuilder(EngelsystemMailer::class)
|
|
|
|
->setConstructorArgs(['mailer' => $swiftMailer, 'view' => $view])
|
|
|
|
->setConstructorArgs(['mailer' => $swiftMailer, 'view' => $view])
|
|
|
|
->setMethods(['send'])
|
|
|
|
->onlyMethods(['send'])
|
|
|
|
->getMock();
|
|
|
|
->getMock();
|
|
|
|
$mailer->expects($this->once())
|
|
|
|
$this->setExpects($mailer, 'send', ['foo@bar.baz', 'Lorem dolor', 'Rendered Stuff!'], 1);
|
|
|
|
->method('send')
|
|
|
|
$this->setExpects($view, 'render', ['test/template.tpl', ['dev' => true]], 'Rendered Stuff!');
|
|
|
|
->with('foo@bar.baz', 'Lorem dolor', 'Rendered Stuff!')
|
|
|
|
|
|
|
|
->willReturn(1);
|
|
|
|
|
|
|
|
$view->expects($this->once())
|
|
|
|
|
|
|
|
->method('render')
|
|
|
|
|
|
|
|
->with('test/template.tpl', ['dev' => true])
|
|
|
|
|
|
|
|
->willReturn('Rendered Stuff!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$return = $mailer->sendView('foo@bar.baz', 'Lorem dolor', 'test/template.tpl', ['dev' => true]);
|
|
|
|
$return = $mailer->sendView('foo@bar.baz', 'Lorem dolor', 'test/template.tpl', ['dev' => true]);
|
|
|
|
$this->equalTo(1, $return);
|
|
|
|
$this->equalTo(1, $return);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::sendViewTranslated
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function testSendViewTranslated()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$this->initDatabase();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$settings = new Settings([
|
|
|
|
|
|
|
|
'language' => 'de_DE',
|
|
|
|
|
|
|
|
'theme' => '',
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
$contact = new Contact(['email' => null]);
|
|
|
|
|
|
|
|
$user = new User([
|
|
|
|
|
|
|
|
'id' => 42,
|
|
|
|
|
|
|
|
'name' => 'username',
|
|
|
|
|
|
|
|
'email' => 'foo@bar.baz',
|
|
|
|
|
|
|
|
'password' => '',
|
|
|
|
|
|
|
|
'api_key' => '',
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
$settings->user()->associate($user)->save();
|
|
|
|
|
|
|
|
$contact->user()->associate($user)->save();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @var Renderer|MockObject $view */
|
|
|
|
|
|
|
|
$view = $this->createMock(Renderer::class);
|
|
|
|
|
|
|
|
/** @var SwiftMailer|MockObject $swiftMailer */
|
|
|
|
|
|
|
|
$swiftMailer = $this->createMock(SwiftMailer::class);
|
|
|
|
|
|
|
|
/** @var Translator|MockObject $translator */
|
|
|
|
|
|
|
|
$translator = $this->createMock(Translator::class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @var EngelsystemMailer|MockObject $mailer */
|
|
|
|
|
|
|
|
$mailer = $this->getMockBuilder(EngelsystemMailer::class)
|
|
|
|
|
|
|
|
->setConstructorArgs(['mailer' => $swiftMailer, 'view' => $view, 'translation' => $translator])
|
|
|
|
|
|
|
|
->onlyMethods(['sendView'])
|
|
|
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setExpects($mailer, 'sendView', ['foo@bar.baz', 'Lorem dolor', 'test/template.tpl', ['dev' => true]], 1);
|
|
|
|
|
|
|
|
$this->setExpects($translator, 'getLocales', null, ['de_DE' => 'de_DE', 'en_US' => 'en_US']);
|
|
|
|
|
|
|
|
$this->setExpects($translator, 'getLocale', null, 'en_US');
|
|
|
|
|
|
|
|
$this->setExpects($translator, 'translate', ['translatable.text'], 'Lorem dolor');
|
|
|
|
|
|
|
|
$translator->expects($this->exactly(2))
|
|
|
|
|
|
|
|
->method('setLocale')
|
|
|
|
|
|
|
|
->withConsecutive(['de_DE'], ['en_US']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$return = $mailer->sendViewTranslated(
|
|
|
|
|
|
|
|
$user,
|
|
|
|
|
|
|
|
'translatable.text',
|
|
|
|
|
|
|
|
'test/template.tpl',
|
|
|
|
|
|
|
|
['dev' => true],
|
|
|
|
|
|
|
|
'de_DE'
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->equalTo(1, $return);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::getSubjectPrefix
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::getSubjectPrefix
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::send
|
|
|
|
* @covers \Engelsystem\Mail\EngelsystemMailer::send
|
|
|
@ -50,32 +105,12 @@ class EngelsystemMailerTest extends TestCase
|
|
|
|
$message = $this->createMock(SwiftMessage::class);
|
|
|
|
$message = $this->createMock(SwiftMessage::class);
|
|
|
|
/** @var SwiftMailer|MockObject $swiftMailer */
|
|
|
|
/** @var SwiftMailer|MockObject $swiftMailer */
|
|
|
|
$swiftMailer = $this->createMock(SwiftMailer::class);
|
|
|
|
$swiftMailer = $this->createMock(SwiftMailer::class);
|
|
|
|
$swiftMailer->expects($this->once())
|
|
|
|
$this->setExpects($swiftMailer, 'createMessage', null, $message);
|
|
|
|
->method('createMessage')
|
|
|
|
$this->setExpects($swiftMailer, 'send', null, 1);
|
|
|
|
->willReturn($message);
|
|
|
|
$this->setExpects($message, 'setTo', [['to@xam.pel']], $message);
|
|
|
|
$swiftMailer->expects($this->once())
|
|
|
|
$this->setExpects($message, 'setFrom', ['foo@bar.baz', 'Lorem Ipsum'], $message);
|
|
|
|
->method('send')
|
|
|
|
$this->setExpects($message, 'setSubject', ['[Mail test] Foo Bar'], $message);
|
|
|
|
->willReturn(1);
|
|
|
|
$this->setExpects($message, 'setBody', ['Lorem Ipsum!'], $message);
|
|
|
|
|
|
|
|
|
|
|
|
$message->expects($this->once())
|
|
|
|
|
|
|
|
->method('setTo')
|
|
|
|
|
|
|
|
->with(['to@xam.pel'])
|
|
|
|
|
|
|
|
->willReturn($message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$message->expects($this->once())
|
|
|
|
|
|
|
|
->method('setFrom')
|
|
|
|
|
|
|
|
->with('foo@bar.baz', 'Lorem Ipsum')
|
|
|
|
|
|
|
|
->willReturn($message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$message->expects($this->once())
|
|
|
|
|
|
|
|
->method('setSubject')
|
|
|
|
|
|
|
|
->with('[Mail test] Foo Bar')
|
|
|
|
|
|
|
|
->willReturn($message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$message->expects($this->once())
|
|
|
|
|
|
|
|
->method('setBody')
|
|
|
|
|
|
|
|
->with('Lorem Ipsum!')
|
|
|
|
|
|
|
|
->willReturn($message);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$mailer = new EngelsystemMailer($swiftMailer);
|
|
|
|
$mailer = new EngelsystemMailer($swiftMailer);
|
|
|
|
$mailer->setFromAddress('foo@bar.baz');
|
|
|
|
$mailer->setFromAddress('foo@bar.baz');
|
|
|
|