This commit changes the behavior of the optin checkbox that MailPoet adds to the WooCommerce checkout. Now the checkbox is not checked by default for logged in users who already subscribed to a list. Also, users won't be unsubscribed anymore and have their global status change to unsubscribed if they uncheck the checkbox. The only action that is performed after this change is to subscribe users if they check the checkbox. This change was implemented both for the normal checkout and the block checkout. It was also necessary to remove the AutomateWoo integration that depended on subscribers being unsubscribed during checkout. [MAILPOET-4178]
87 lines
3.0 KiB
PHP
87 lines
3.0 KiB
PHP
<?php declare(strict_types = 1);
|
|
|
|
namespace MailPoet\WooCommerce\Integrations;
|
|
|
|
use Codeception\Stub\Expected;
|
|
use MailPoet\Entities\SubscriberEntity;
|
|
use MailPoet\Subscribers\SubscribersRepository;
|
|
use MailPoet\Test\DataFactories\Subscriber as SubscriberFactory;
|
|
use MailPoet\WP\Functions as WPFunctions;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
|
|
class AutomateWooHooksTest extends \MailPoetTest {
|
|
/** @var WPFunctions */
|
|
private $wp;
|
|
|
|
/** @var MockObject */
|
|
private $subscribersRepository;
|
|
|
|
/** @var SubscriberFactory */
|
|
private $subscriberFactory;
|
|
|
|
public function _before() {
|
|
parent::_before();
|
|
$this->wp = $this->make(new WPFunctions, [
|
|
'isPluginActive' => function($name) {
|
|
if ($name === 'automatewoo/automatewoo.php') {
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
]);
|
|
$this->subscribersRepository = $this->createMock(SubscribersRepository::class);
|
|
$this->subscriberFactory = new SubscriberFactory();
|
|
}
|
|
|
|
public function testSetup() {
|
|
$wp = $this->make(new WPFunctions, [
|
|
'isPluginActive' => function($name) {
|
|
if ($name === 'automatewoo/automatewoo.php') {
|
|
return true;
|
|
}
|
|
return false;
|
|
},
|
|
'addAction' => Expected::exactly(1),
|
|
]);
|
|
|
|
$automateWooHooksPartialMock = $this->getMockBuilder(AutomateWooHooks::class)
|
|
->setConstructorArgs([$this->subscribersRepository, $wp])
|
|
->onlyMethods(['areMethodsAvailable'])
|
|
->getMock();
|
|
$automateWooHooksPartialMock->expects($this->once())->method('areMethodsAvailable')->willReturn(true);
|
|
|
|
$automateWooHooksPartialMock->setup();
|
|
}
|
|
|
|
public function testOptsOutUnsubscribedSubscriber() {
|
|
$unsubscribedSubscriber = $this->subscriberFactory
|
|
->withEmail('unsubscribedUser@mailpoet.com')
|
|
->withStatus(SubscriberEntity::STATUS_UNSUBSCRIBED)->create();
|
|
$this->subscribersRepository->method('findOneById')->willReturn($unsubscribedSubscriber);
|
|
|
|
$automateWooHooksPartialMock = $this->getMockBuilder(AutomateWooHooks::class)
|
|
->setConstructorArgs([$this->subscribersRepository, $this->wp])
|
|
->onlyMethods(['optOutSubscriber'])
|
|
->getMock();
|
|
|
|
$automateWooHooksPartialMock->expects($this->once())->method('optOutSubscriber');
|
|
|
|
$automateWooHooksPartialMock->maybeOptOutSubscriber((int)$unsubscribedSubscriber->getId());
|
|
}
|
|
|
|
public function testDoesNotOptOutSubscribedSubscriber() {
|
|
$subscribedSubscriber = $this->subscriberFactory
|
|
->withEmail('subscribedUser@mailpoet.com')
|
|
->withStatus(SubscriberEntity::STATUS_SUBSCRIBED)->create();
|
|
$this->subscribersRepository->method('findOneById')->willReturn($subscribedSubscriber);
|
|
|
|
$automateWooHooksPartialMock = $this->getMockBuilder(AutomateWooHooks::class)
|
|
->setConstructorArgs([$this->subscribersRepository, $this->wp])
|
|
->onlyMethods(['optOutSubscriber'])
|
|
->getMock();
|
|
$automateWooHooksPartialMock->expects($this->never())->method('optOutSubscriber');
|
|
|
|
$automateWooHooksPartialMock->maybeOptOutSubscriber((int)$subscribedSubscriber->getId());
|
|
}
|
|
}
|