Improve a deletion test to handle multiple queues, fix comments [MAILPOET-830]
This commit is contained in:
@@ -114,7 +114,7 @@ class Newsletter extends Model {
|
|||||||
function delete() {
|
function delete() {
|
||||||
// delete segment associations
|
// delete segment associations
|
||||||
$this->segmentRelations()->deleteMany();
|
$this->segmentRelations()->deleteMany();
|
||||||
// delete queue association
|
// delete queue associations
|
||||||
$this->queue()->deleteMany();
|
$this->queue()->deleteMany();
|
||||||
|
|
||||||
return parent::delete();
|
return parent::delete();
|
||||||
@@ -137,7 +137,7 @@ class Newsletter extends Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function restore() {
|
function restore() {
|
||||||
// trash queue associations
|
// restore trashed queue associations
|
||||||
SendingQueue::rawExecute(
|
SendingQueue::rawExecute(
|
||||||
'UPDATE `' . SendingQueue::$_table . '` ' .
|
'UPDATE `' . SendingQueue::$_table . '` ' .
|
||||||
'SET `deleted_at` = null ' .
|
'SET `deleted_at` = null ' .
|
||||||
|
@@ -424,17 +424,23 @@ class NewsletterTest extends MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testItDeletesSegmentAndQueueAssociationsWhenNewsletterIsDeleted() {
|
function testItDeletesSegmentAndQueueAssociationsWhenNewsletterIsDeleted() {
|
||||||
// make sure relations exist
|
|
||||||
$newsletter = $this->newsletter;
|
$newsletter = $this->newsletter;
|
||||||
$sending_queue = SendingQueue::where('newsletter_id', $newsletter->id)->findOne();
|
|
||||||
expect($sending_queue)->notEmpty();
|
// create multiple sending queues
|
||||||
|
for($i = 1; $i <= 5; $i++) {
|
||||||
|
$sending_queue = SendingQueue::create();
|
||||||
|
$sending_queue->newsletter_id = $newsletter->id;
|
||||||
|
$sending_queue->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
// make sure relations exist
|
||||||
|
expect(SendingQueue::where('newsletter_id', $newsletter->id)->findArray())->count(6);
|
||||||
$newsletter_segments = NewsletterSegment::where('newsletter_id', $newsletter->id)->findArray();
|
$newsletter_segments = NewsletterSegment::where('newsletter_id', $newsletter->id)->findArray();
|
||||||
expect($newsletter_segments)->count(2);
|
expect($newsletter_segments)->count(2);
|
||||||
|
|
||||||
// delete newsletter and check that relations no longer exist
|
// delete newsletter and check that relations no longer exist
|
||||||
$newsletter->delete();
|
$newsletter->delete();
|
||||||
$sending_queue = SendingQueue::where('newsletter_id', $newsletter->id)->findOne();
|
expect(SendingQueue::where('newsletter_id', $newsletter->id)->findArray())->isEmpty();
|
||||||
expect($sending_queue)->isEmpty();
|
|
||||||
$newsletter_segments = NewsletterSegment::where('newsletter_id', $newsletter->id)->findArray();
|
$newsletter_segments = NewsletterSegment::where('newsletter_id', $newsletter->id)->findArray();
|
||||||
expect($newsletter_segments)->isEmpty();
|
expect($newsletter_segments)->isEmpty();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user