Refactor confirmation email sending
Aspect mock stopped working for me so I had to create a separate service for sending confirmation emails. [MAILPOET-1522]
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace MailPoet\Test\Models;
|
||||
|
||||
use AspectMock\Test as Mock;
|
||||
use Carbon\Carbon;
|
||||
use Codeception\Util\Fixtures;
|
||||
use MailPoet\Models\CustomField;
|
||||
@@ -1120,48 +1119,6 @@ class SubscriberTest extends \MailPoetTest {
|
||||
);
|
||||
}
|
||||
|
||||
function testItSendsConfirmationEmail() {
|
||||
Mock::double('MailPoet\Mailer\Mailer', [
|
||||
'__construct' => null,
|
||||
'send' => function($email) {
|
||||
return $email;
|
||||
}
|
||||
]);
|
||||
Mock::double('MailPoet\Subscription\Url', [
|
||||
'getConfirmationUrl' => 'http://example.com'
|
||||
]);
|
||||
|
||||
$segment = Segment::createOrUpdate(
|
||||
array(
|
||||
'name' => 'Test segment'
|
||||
)
|
||||
);
|
||||
SubscriberSegment::subscribeToSegments(
|
||||
$this->subscriber,
|
||||
array($segment->id)
|
||||
);
|
||||
|
||||
$result = $this->subscriber->sendConfirmationEmail();
|
||||
|
||||
// email contains subscriber's lists
|
||||
expect($result['body']['html'])->contains('<strong>Test segment</strong>');
|
||||
// email contains activation link
|
||||
expect($result['body']['html'])->contains('<a target="_blank" href="http://example.com">Click here to confirm your subscription.</a>');
|
||||
}
|
||||
|
||||
function testItSetsErrorsWhenConfirmationEmailCannotBeSent() {
|
||||
Mock::double('MailPoet\Mailer\Mailer', [
|
||||
'__construct' => null,
|
||||
'send' => function() {
|
||||
throw new \Exception('send error');
|
||||
}
|
||||
]);
|
||||
|
||||
$this->subscriber->sendConfirmationEmail();
|
||||
// error is set on the subscriber model object
|
||||
expect($this->subscriber->getErrors()[0])->equals('send error');
|
||||
}
|
||||
|
||||
function _after() {
|
||||
\ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
\ORM::raw_execute('TRUNCATE ' . Segment::$_table);
|
||||
|
Reference in New Issue
Block a user