- Adds unit test for unsubscribe statistics
This commit is contained in:
@@ -126,7 +126,7 @@ class Link {
|
||||
// track unsubscribe event
|
||||
if((boolean) Setting::getValue('tracking.enabled')) {
|
||||
$unsubscribe = new Unsubscribes();
|
||||
$unsubscribe->track($subscriber['id'], $queue['id'], $newsletter['id']);
|
||||
$unsubscribe->track($newsletter['id'], $subscriber['id'], $queue['id']);
|
||||
}
|
||||
$url = SubscriptionUrl::getUnsubscribeUrl($subscriber);
|
||||
break;
|
||||
|
@@ -6,7 +6,7 @@ use MailPoet\Models\StatisticsUnsubscribes;
|
||||
if(!defined('ABSPATH')) exit;
|
||||
|
||||
class Unsubscribes {
|
||||
function track($subscriber_id, $queue_id, $newsletter_id) {
|
||||
function track($newsletter_id, $subscriber_id, $queue_id) {
|
||||
$statistics = StatisticsUnsubscribes::where('subscriber_id', $subscriber_id)
|
||||
->where('newsletter_id', $newsletter_id)
|
||||
->where('queue_id', $queue_id)
|
||||
|
54
tests/unit/Statistics/Track/UnsubscribesTest.php
Normal file
54
tests/unit/Statistics/Track/UnsubscribesTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Codeception\Util\Stub;
|
||||
use MailPoet\Models\Newsletter;
|
||||
use MailPoet\Models\SendingQueue;
|
||||
use MailPoet\Models\StatisticsOpens;
|
||||
use MailPoet\Models\StatisticsUnsubscribes;
|
||||
use MailPoet\Models\Subscriber;
|
||||
use MailPoet\Statistics\Track\Opens;
|
||||
use MailPoet\Statistics\Track\Unsubscribes;
|
||||
|
||||
class UnsubscribesTest extends MailPoetTest {
|
||||
function _before() {
|
||||
// create newsletter
|
||||
$newsletter = Newsletter::create();
|
||||
$newsletter->type = 'type';
|
||||
$this->newsletter = $newsletter->save();
|
||||
// create subscriber
|
||||
$subscriber = Subscriber::create();
|
||||
$subscriber->email = 'test@example.com';
|
||||
$this->subscriber = $subscriber->save();
|
||||
// create queue
|
||||
$queue = SendingQueue::create();
|
||||
$queue->newsletter_id = $newsletter->id;
|
||||
$this->queue = $queue->save();
|
||||
// instantiate class
|
||||
$this->unsubscribes = new Unsubscribes();
|
||||
}
|
||||
|
||||
function testItCanUniqueTrack() {
|
||||
$unsubscribe_events = StatisticsUnsubscribes::findArray();
|
||||
expect(count($unsubscribe_events))->equals(0);
|
||||
// only 1 unique unsubscribe event should be recorded
|
||||
$unsubscribes = $this->unsubscribes->track(
|
||||
$this->newsletter->id,
|
||||
$this->subscriber->id,
|
||||
$this->queue->id
|
||||
);
|
||||
$unsubscribes = $this->unsubscribes->track(
|
||||
$this->newsletter->id,
|
||||
$this->subscriber->id,
|
||||
$this->queue->id
|
||||
);
|
||||
$unsubscribe_events = StatisticsUnsubscribes::findArray();
|
||||
expect(count($unsubscribe_events))->equals(1);
|
||||
}
|
||||
|
||||
function _after() {
|
||||
ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table);
|
||||
ORM::raw_execute('TRUNCATE ' . StatisticsUnsubscribes::$_table);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user