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]
This commit is contained in:
Rostislav Wolny
2022-02-08 09:39:13 +01:00
committed by Jan Lysý
parent 07dde70d9f
commit 9f0bd98569

View File

@ -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);