Commit Graph

248 Commits

Author SHA1 Message Date
Jan Jakes
a1632ea512 Satisfy PHPCS checks also in tests
[MAILPOET-6150]
2024-08-29 17:23:34 +02:00
Rostislav Wolny
5fdba0e170 Replace current_time usage in tests
[MAILPOET-6142]
2024-08-19 15:29:42 +02:00
Rostislav Wolny
33f4b2d729 Replace usage of WP's current_time without gmt parameter in libs
This commit replaces usages by Carbon::now or in case we need a timestamp it
keeps current_time but adds the gtm parameter as true.
[MAILPOET-6142]
2024-08-19 15:29:42 +02:00
Rostislav Wolny
c95cd1073b Improve SubscriberLifetieEmailCountTest to use saved entity
The test was using an empty entity which was not presisted. This may
potentially cause issues as in some places, an entity with a proper type might be expected.
It was already causing that an SQL query ran with WHERE type = null condition which is always false.
[MAILPOET-6142]
2024-08-19 15:29:42 +02:00
Rostislav Wolny
a7df6b496f Add logging for unexpected states when we reach the end of sending
[MAILPOET-5881]
2024-06-07 11:32:46 +02:00
Rostislav Wolny
9dd808a070 Set as invalid only for non-campaign email types
For non-campaign emails, we use scheduled tasks to display processed stats.
The invalid tasks are no longer processed, and they don't block the queue
and are not counted in the stats.
For campaign emails (bulk emails), we just mark them as sent to zero recipients.
[MAILPOET-5881]
2024-06-07 11:32:46 +02:00
Rostislav Wolny
e4cff6c14f Remove an unnecessary condition in the batch processing loop
The batch will be continued anyway because of the next condition
if (!$queue->getCountToProcess()) {
  continue;
}
The newsletter entity will be marked as sent (plus other stuff related to finished sending)
after the loop in $this->endSending.
2024-06-07 11:32:46 +02:00
Jan Jakes
4c1b2e46c8 Trigger automation email sent hook for automation emails
[MAILPOET-4977]
2024-05-06 12:39:00 +02:00
Jan Jakes
b188add536 Fix PHP 8.1 error: Implicit incompatible float to int conversion is deprecated
[MAILPOET-6003]
2024-04-19 09:15:55 +02:00
Mike Jolley
0d6fe6e5eb Apply rules to tests and tasks 2024-03-21 16:57:59 +01:00
David Remer
4abe0f0564 Remove flaky assesment
[MAILPOET-5941]
2024-03-13 10:51:14 +01:00
David Remer
c557f27ce9 Check for initial limit before initializing.
[MAILPOET-5941]
2024-03-11 15:01:10 +01:00
Rostislav Wolny
749c4e5e43 Prevent deleting and further changes in detached tasks during sending
When a post notification history is deleted in
MailPoet\Cron\Workers\SendingQueue\Tasks\Newsletter::preProcessNewsletter
it is also detached from EntityManager.

Any further attempt to manipulate the entity via EntityManager (remove or flush) causes
errors like "ERROR: A new entity was found through the relationship 'MailPoet\Entities\ScheduledTaskEntity#sendingQueue'"

In this commit we prevent doing such changes.
[MAILPOET-5880]
2024-02-05 15:16:11 +01:00
Rostislav Wolny
6a86dfc7c0 Throw an exception when preprocessing a newsletter without a queue
The goal of this commit is to change the preProcessNewsletter method
to return false only in case when it deleted the newsletter and
all associated entities. So that we know for sure that false means all was deleted.
[MAILPOET-5880]
2024-02-05 15:16:11 +01:00
Jan Jakes
8450e1bb1b Clear entity manager for every cron run
This avoids using stale data and prevents memory leaks.

[MAILPOET-5845]
2024-02-02 12:48:40 +01:00
David Remer
7defccd834 Test that the beamer background task does not run when 3rd parties are not enabled
[MAILPOET-5826]
2024-01-22 12:11:47 +01:00
Brezo Cordero
e7aa261828 Process Soft error for domain authorization
Pause the task and do not update counts.

[MAILPOET-5832]
2024-01-20 13:39:23 +05:00
Brezo Cordero
42618ab15c Pause sending task if sender address not valid
[MAILPOET-5832]
2024-01-20 13:39:23 +05:00
Jan Jakes
0872edba99 Fix multisite tests failing on trunk
The fix for single-site was done in 895c2ad3e1,
this commit adds a fix for multisite.

[MAILPOET-5835]
2024-01-17 13:02:48 -06:00
Rodrigo Primo
895c2ad3e1 Make sure WP user is deleted after each test
Doing this to avoid causing problems in other tests from other classes.
Without removing the WP user here we were getting the following failure
in CircleCI:

```
1) MailerTest: It can prepare subscriber for sending
 Test  tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php:testItCanPrepareSubscriberForSending
  [MailPoetVendor\Doctrine\DBAL\Exception\UniqueConstraintViolationException] An exception occurred while executing 'INSERT INTO mp_mailpoet_subscribers (wp_user_id, is_woocommerce_user, first_name, last_name, email, status, subscribed_ip, confirmed_ip, confirmed_at, last_subscribed_at, unconfirmed_data, source, count_confirmations, unsubscribe_token, link_token, engagement_score, engagement_score_updated_at, last_engagement_at, last_sending_at, last_open_at, last_click_at, last_purchase_at, last_page_view_at, woocommerce_synced_at, email_count, created_at, updated_at, deleted_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, 0, "John", "Doe", "test@example.com", "subscribed", null, null, null, "2023-11-23 19:31:34", null, "unknown", 0, null, null, null, null, null, null, null, null, null, null, null, 0, "2023-11-23 19:31:34", "2023-11-23 19:31:34", null]:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'test@example.com' for key 'email'
```

https://app.circleci.com/pipelines/github/mailpoet/mailpoet/16312/workflows/c241bba8-27b9-411e-aa60-ab51af4efc58/jobs/276761?invite=true#step-105-405846_52

[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
1a1f48eb15 Replace SendingQueue model with Doctrine in SendingQueueTest
I opted to remove testItDeletesQueueWhenNewsletterIsNotFound() as I
wasn't sure how to recreate this test using Doctrine and I found out
that it was actually not working. The call to
$this->newslettersRepository->bulkDelete() was deleting the sending
queue entry and not SendingQueue::deleteTaskIfNewsletterDoesNotExist().

[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
33769e703c Replace StatisticsNewsletters model with Doctrine in SendingQueue
[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
4fe642916e Replace Newsletter model with Doctrine in SendingQueue
[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
83826b3f65 Replace Subscriber model with Doctrine in SendingQueue and SendingQueueTest
[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
5ac874c713 Replace Newsletter and NewsletterSegment models with Doctrine
[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
9725e300f3 Fix bug in testItCanProcessWelcomeNewsletters() test
This test was checking that the status of a welcome email is set to
`sent` after it is processed. Turns out this is not what should happen
and also not what is actually happen. The code only changes the status
of emails of the types standard and notification history:

7d43059f15/mailpoet/lib/Cron/Workers/SendingQueue/Tasks/Newsletter.php (L285-L286)

The test changes the type of the email to welcome
using Paris and never persists it to the database. The code mentioned
above that changes the status of the email uses Doctrine, so it was
still acting as if this was an standard email and not a welcome email.

To fix this problem, I updated the test to check if the status of the
welcome email is `active` and also made sure to persist the change to
the database and refresh the Doctrine entity.

[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
4f333e3ae8 Replace StatisticsNewsletters model with Doctrine
[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
a9952cf394 Replace Segment model with Doctrine in SendingQueueTest
[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
abd19a6e6e Replace SubscriberSegment model with Doctrine in SendingQueueTest
[MAILPOET-5737]
2024-01-17 22:32:37 +05:00
Rodrigo Primo
e96251db7e Fix bug when changing ScheduledTask in_progress field
In 3394568, SendingQueue::stopProgress() was refactored to use Doctrine
but a typo introduced a bug causing this method to set
ScheduledTaskEntity::inProgress to true instead of false:

3394568792 (diff-3a26b2d8faf9cc01efd5aef47b058c088c0de01b8074c3be7cefd9adb77fbaaaR551)

This luckly was caught by the
EditorCouponCest.php:seeNoticeWhenCouponCantGenerateAndResumeSending
acceptance test.

This commit fixes the problem and also adds two integration tests to
protect against similar regressions in the future.

[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
0604d97212 Improve test coverage for SendingQueue::processSending()
While working on the previous commit, I noticed that we had a test to
check removing subscribers that are not part of a segment associated
with a newsletter when sending
(testItRemovesSubscribersFromProcessingListWhenNewsletterHasSegmentAndSubscriberIsNotPartOfIt()).
But SendingQueue::processSending() also handles removing subscribers
when sending newsletters without segments. And there was not test to
cover this part of the code.

[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
876a9489a4 Replace \MailPoet\Tasks\Sending with Doctrine in SendingQueueTest
This commit also removes Sending::getSendingQueueEntity() as the last
calls to this method were removed when refactoring SendingQueueTest.

[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
75f7ea24a9 Rename createQueueWithTaskAndSegment() to createQueueWithTask()
Removed `AndSegment` from test helper method to better reflect what it does as it does not create a segment.

[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
7bb40664cc Replace ScheduledTask model with Doctrine in SendingQueueTest
[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
5891e09418 Replace simple uses of Newsletter and Subscriber models with Doctrine
[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
90b56d3aa8 Replace model ScheduledTaskSubscriber with Doctrine in SendingQueueTest
[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
d2e226a932 Fix SendingQueueTests after Doctrine refactor
[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
3b38b3034a Update calls to SendingQueue worker constructor in SendingQueueTest
[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
9c0eea54f8 Rewrite NewsletterTest using Doctrine
testItLogsErrorWhenExistingRenderedNewsletterBodyIsInvalid() was removed
because since 0e13cd02c31baef706f852664570e3ddb014f56d,
preProcessNewsletter() doesn't throw an exception anymore for an invalid
newsletter body:

0e13cd02c3 (diff-449c06813489ce1e60006fdd40b4f23eb3a0cf290ff84b703dcee44b04435eadL142)

Presumably, this is because Doctrine won't allow the code to save an
invalid body.

testItLogsErrorWhenNewlyRenderedNewsletterBodyIsInvalid() was removed
because it doesn't seem to test what it was supposed to test and it is
not trivial to make it work. Even on trunk this test was passing because
`self::fail('Sending error exception was not thrown.')` throwns an
exception and not because preProcessNewsletter() was throwing an
exception.

[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
70085c40bb Rewrite SendingErrorHandlerTest using Doctrine
[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Rodrigo Primo
cd7a5c7943 Rewrite LinksTest using Doctrine
[MAILPOET-5682]
2024-01-12 13:25:46 +01:00
Oluwaseun Olorunsola
c76c8f2abb Save the correct datetime value for newsletter sentAt column
We don't need to use the value from `processedAt` here since we can rightfully use the current datetime value

Also, I found out `processedAt` is usually null here for standard newsletters which cause new Carbon to use the server datetime settings

MAILPOET-5795
2023-12-25 21:38:02 +01:00
Jan Lysý
41a55262fe Fix PHPStan warnings in tests
[MAILPOET-5751]
2023-12-13 11:48:14 +01:00
John Oleksowicz
1b31ad11d4 Update UnsubscribeTokens to use DI
MAILPOET-5710
2023-11-13 10:35:54 +01:00
Jan Jakes
2a1245bd8a Remove SendingQueueEntity::$subscribers
This doesn't seem to be used anywhere. For scheduled task subscribers, we have
ScheduledTaskEntity::$subscribers collection.

[MAILPOET-4375]
2023-11-02 12:53:36 +01:00
Jan Jakes
8cbccf5b7b Remove unnecessary code from SchedulerTest
[MAILPOET-4375]
2023-11-02 12:53:36 +01:00
Jan Jakes
434b76e4f4 Extract creating scheduler mock to a method
[MAILPOET-4375]
2023-11-02 12:53:36 +01:00
Jan Jakes
258e92e804 Simplify SchedulerTest::testItDeletesQueueDuringProcessingWhenNewsletterIsSoftDeleted()
[MAILPOET-4375]
2023-11-02 12:53:36 +01:00
Jan Jakes
90f1b6ccae Simplify SchedulerTest::testItFailsToProcessPostNotificationNewsletterWhenSubscribersNotInSegment()
There is no need to mock "deleteQueueOrUpdateNextRunDate" to make the subscriber-segment check work.

[MAILPOET-4375]
2023-11-02 12:53:36 +01:00
Jan Jakes
5ddbca3eb3 Improve SchedulerTest::testItProcessesScheduledStandardNewsletter()
Added NewsletterEntity::TYPE_STANDARD to make it correspond better to the fucntion name.

[MAILPOET-4375]
2023-11-02 12:53:36 +01:00