Fix the possibility of repeatedly submitting a form with an existing e-mail address [MAILPOET-1115]

This commit is contained in:
stoletniy
2017-09-28 12:38:37 +03:00
committed by pavel-mailpoet
parent e4ab928e82
commit 8a91eb46e6
2 changed files with 32 additions and 2 deletions

View File

@ -1,6 +1,7 @@
<?php
namespace MailPoet\Test\API\JSON\v1;
use Carbon\Carbon;
use Codeception\Util\Fixtures;
use MailPoet\API\JSON\v1\Subscribers;
use MailPoet\API\JSON\Response as APIResponse;
@ -519,6 +520,34 @@ class SubscribersTest extends \MailPoetTest {
}
}
function testItCannotMassResubscribe() {
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$router = new Subscribers();
$response = $router->subscribe(array(
$this->obfuscatedEmail => 'toto@mailpoet.com',
'form_id' => $this->form->id,
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
));
// Try to resubscribe an existing subscriber that was updated just now
$subscriber = Subscriber::findOne($response->data['id']);
$subscriber->created_at = Carbon::yesterday();
$subscriber->updated_at = Carbon::now();
$subscriber->save();
try {
$response = $router->subscribe(array(
$this->obfuscatedEmail => $subscriber->email,
'form_id' => $this->form->id,
$this->obfuscatedSegments => array($this->segment_1->id, $this->segment_2->id)
));
$this->fail('It should not be possible to resubscribe a second time so soon');
} catch(\Exception $e) {
expect($e->getMessage())->equals('You need to wait before subscribing again.');
}
}
function _after() {
Segment::deleteMany();
Subscriber::deleteMany();