Send a confirmation email when a user is added to a website
[MAILPOET-2567]
This commit is contained in:
committed by
Jack Kitterhing
parent
de9c151fe4
commit
4c5155132a
@@ -13,6 +13,7 @@ use MailPoet\WP\Functions as WPFunctions;
|
|||||||
* @property string $name
|
* @property string $name
|
||||||
* @property string $type
|
* @property string $type
|
||||||
* @property string $description
|
* @property string $description
|
||||||
|
* @property string $countConfirmations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Segment extends Model {
|
class Segment extends Model {
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace MailPoet\Segments;
|
namespace MailPoet\Segments;
|
||||||
|
|
||||||
|
use MailPoet\DI\ContainerWrapper;
|
||||||
use MailPoet\Models\ModelValidator;
|
use MailPoet\Models\ModelValidator;
|
||||||
use MailPoet\Models\Segment;
|
use MailPoet\Models\Segment;
|
||||||
use MailPoet\Models\StatisticsClicks;
|
use MailPoet\Models\StatisticsClicks;
|
||||||
@@ -10,6 +11,7 @@ use MailPoet\Models\Subscriber;
|
|||||||
use MailPoet\Models\SubscriberSegment;
|
use MailPoet\Models\SubscriberSegment;
|
||||||
use MailPoet\Newsletter\Scheduler\WelcomeScheduler;
|
use MailPoet\Newsletter\Scheduler\WelcomeScheduler;
|
||||||
use MailPoet\Settings\SettingsController;
|
use MailPoet\Settings\SettingsController;
|
||||||
|
use MailPoet\Subscribers\ConfirmationEmailMailer;
|
||||||
use MailPoet\Subscribers\Source;
|
use MailPoet\Subscribers\Source;
|
||||||
use MailPoetVendor\Idiorm\ORM;
|
use MailPoetVendor\Idiorm\ORM;
|
||||||
|
|
||||||
@@ -70,6 +72,10 @@ class WP {
|
|||||||
$subscriber,
|
$subscriber,
|
||||||
[$wpSegment->id]
|
[$wpSegment->id]
|
||||||
);
|
);
|
||||||
|
if ($subscriber->status === Subscriber::STATUS_UNCONFIRMED) {
|
||||||
|
$confirmationEmailMailer = ContainerWrapper::getInstance()->get(ConfirmationEmailMailer::class);
|
||||||
|
$confirmationEmailMailer->sendConfirmationEmail($subscriber);
|
||||||
|
}
|
||||||
|
|
||||||
// welcome email
|
// welcome email
|
||||||
if ($scheduleWelcomeNewsletter === true) {
|
if ($scheduleWelcomeNewsletter === true) {
|
||||||
|
@@ -45,7 +45,6 @@ class ConfirmationEmailMailer {
|
|||||||
if ((bool)$signupConfirmation['enabled'] === false) {
|
if ((bool)$signupConfirmation['enabled'] === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->wp->isUserLoggedIn() && $subscriber->countConfirmations >= self::MAX_CONFIRMATION_EMAILS) {
|
if (!$this->wp->isUserLoggedIn() && $subscriber->countConfirmations >= self::MAX_CONFIRMATION_EMAILS) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
32
tests/acceptance/CreateNewWordPressUserCest.php
Normal file
32
tests/acceptance/CreateNewWordPressUserCest.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace MailPoet\Test\Acceptance;
|
||||||
|
|
||||||
|
use Codeception\Util\Locator;
|
||||||
|
use MailPoet\Test\DataFactories\Settings;
|
||||||
|
|
||||||
|
class CreateNewWordPressUserCest {
|
||||||
|
|
||||||
|
/** @var Settings */
|
||||||
|
private $settings;
|
||||||
|
|
||||||
|
protected function _inject(Settings $settings) {
|
||||||
|
$this->settings = $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendConfirmationEmail(\AcceptanceTester $i) {
|
||||||
|
$i->wantTo('Create a new wordpress user and check if the confirmation email is sent');
|
||||||
|
$this->settings->withConfirmationEmailEnabled();
|
||||||
|
//create a wp user with wp role subscriber
|
||||||
|
$i->cli(['user', 'create', 'narwhal', 'standardtest@example.com', '--role=subscriber']);
|
||||||
|
$i->amOnMailboxAppPage();
|
||||||
|
$i->waitForElement(Locator::contains('span.subject', 'Confirm your subscription'));
|
||||||
|
$i->click(Locator::contains('span.subject', 'Confirm your subscription'));
|
||||||
|
$i->switchToIframe('preview-html');
|
||||||
|
$i->click('I confirm my subscription!');
|
||||||
|
$i->switchToNextTab();
|
||||||
|
$i->see('You have subscribed');
|
||||||
|
$i->seeNoJSErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -43,12 +43,17 @@ class WPTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testSynchronizeUserStatusIsUnconfirmedForNewUserWithSignUpConfirmationEnabled() {
|
public function testSynchronizeUserStatusIsUnconfirmedForNewUserWithSignUpConfirmationEnabled() {
|
||||||
|
$this->settings->set('sender', [
|
||||||
|
'address' => 'sender@mailpoet.com',
|
||||||
|
'name' => 'Sender',
|
||||||
|
]);
|
||||||
$this->settings->set('signup_confirmation', ['enabled' => '1']);
|
$this->settings->set('signup_confirmation', ['enabled' => '1']);
|
||||||
$randomNumber = rand();
|
$randomNumber = rand();
|
||||||
$id = $this->insertUser($randomNumber);
|
$id = $this->insertUser($randomNumber);
|
||||||
WP::synchronizeUser($id);
|
WP::synchronizeUser($id);
|
||||||
$wpSubscriber = Segment::getWPSegment()->subscribers()->where('wp_user_id', $id)->findOne();
|
$wpSubscriber = Segment::getWPSegment()->subscribers()->where('wp_user_id', $id)->findOne();
|
||||||
expect($wpSubscriber->status)->equals(Subscriber::STATUS_UNCONFIRMED);
|
expect($wpSubscriber->status)->equals(Subscriber::STATUS_UNCONFIRMED);
|
||||||
|
expect($wpSubscriber->countConfirmations)->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSynchronizeUsersStatusIsSubscribedForNewUsersWithSignUpConfirmationDisabled() {
|
public function testSynchronizeUsersStatusIsSubscribedForNewUsersWithSignUpConfirmationDisabled() {
|
||||||
|
Reference in New Issue
Block a user