From 9f0bd98569cfadf67d62d98f1a45544e3ffb4727 Mon Sep 17 00:00:00 2001 From: Rostislav Wolny Date: Tue, 8 Feb 2022 09:39:13 +0100 Subject: [PATCH] Fix subscriber activity tracker test wp_create_user function was failing when creating the same user for the second time. This commit fixes the issue by adding a cleanup before the test creates the user. [MAILPOET-4123] --- .../Statistics/Track/SubscriberActivityTrackerTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mailpoet/tests/integration/Statistics/Track/SubscriberActivityTrackerTest.php b/mailpoet/tests/integration/Statistics/Track/SubscriberActivityTrackerTest.php index 3cac627a98..89574082fb 100644 --- a/mailpoet/tests/integration/Statistics/Track/SubscriberActivityTrackerTest.php +++ b/mailpoet/tests/integration/Statistics/Track/SubscriberActivityTrackerTest.php @@ -88,7 +88,9 @@ class SubscriberActivityTrackerTest extends \MailPoetTest { public function testItUpdatesPageViewCookieAndSubscriberEngagementForWpUser() { $this->diContainer->get(SettingsController::class)->set('tracking.level', TrackingConfig::LEVEL_FULL); - $user = (new User())->createUser('name', 'editor', 'editoruser@test.com'); + $wpUserEmail = 'pageview_track_user@test.com'; + $this->tester->deleteWordPressUser($wpUserEmail); + $user = (new User())->createUser('tracking_enabled', 'editor', $wpUserEmail); $this->wp->wpSetCurrentUser($user->ID); $oldPageViewTimestamp = $this->wp->currentTime('timestamp') - 180; // 3 minutes ago $this->setPageViewCookieTimestamp($oldPageViewTimestamp); @@ -106,7 +108,9 @@ class SubscriberActivityTrackerTest extends \MailPoetTest { public function testItUpdatesSubscriberEngagementForWpUserEvenWithDisabledCookieTracking() { $this->diContainer->get(SettingsController::class)->set('tracking.level', TrackingConfig::LEVEL_PARTIAL); - $user = (new User())->createUser('name', 'editor', 'editoruser@test.com'); + $wpUserEmail = 'pageview_track_user@test.com'; + $this->tester->deleteWordPressUser($wpUserEmail); + $user = (new User())->createUser('no_tracking', 'editor', $wpUserEmail); $this->wp->wpSetCurrentUser($user->ID); $subscriber = $this->entityManager->getRepository(SubscriberEntity::class)->findOneBy(['wpUserId' => $user->ID]); $this->assertInstanceOf(SubscriberEntity::class, $subscriber);