Add new testcase with all scenarios for segments
MAILPOET-3047
This commit is contained in:
committed by
Rostislav Wolný
parent
5a7c58999c
commit
b1bf4f396e
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Test\DataFactories\Newsletter;
|
||||
|
||||
class CreateNewSegmentCest {
|
||||
public function createUserRoleSegment(\AcceptanceTester $i) {
|
||||
$i->wantTo('Create a new WP user role segment');
|
||||
$segmentTitle = 'Create User Role Segment Test';
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->click('[data-automation-id="new-segment"]');
|
||||
$i->fillField(['name' => 'name'], $segmentTitle);
|
||||
$i->fillField(['name' => 'description'], 'Lorem ipsum dolor amed');
|
||||
$i->selectOption('form select[name=segmentType]', 'WordPress user roles');
|
||||
$i->selectOption('form select[name=wordpressRole]', 'Editor');
|
||||
$i->click('Save');
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->waitForText($segmentTitle);
|
||||
}
|
||||
|
||||
public function createEmailSegment(\AcceptanceTester $i) {
|
||||
$i->wantTo('Create a new email segment');
|
||||
$emailSubject = 'Segment Email Test';
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletterFactory->withSubject($emailSubject)->create();
|
||||
$segmentTitle = 'Create Email Segment Test';
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->click('[data-automation-id="new-segment"]');
|
||||
$i->fillField(['name' => 'name'], $segmentTitle);
|
||||
$i->fillField(['name' => 'description'], 'Lorem ipsum dolor amed');
|
||||
$i->selectOption('form select[name=segmentType]', 'Email');
|
||||
$i->selectOption('form select[name=action]', 'opened');
|
||||
$i->click('#select2-newsletter_id-container');
|
||||
$i->selectOptionInSelect2($emailSubject);
|
||||
$i->click('Save');
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->waitForText($segmentTitle, 20);
|
||||
}
|
||||
}
|
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Test\DataFactories\DynamicSegment;
|
||||
|
||||
class DeleteTrashedSegmentCest {
|
||||
public function deleteSegmentFromTrash(\AcceptanceTester $i) {
|
||||
$i->wantTo('Delete a segment from trash');
|
||||
|
||||
$segmentTitle = 'Delete Segment From Trash Test';
|
||||
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle)
|
||||
->withUserRoleFilter('Administrator')
|
||||
->withDeleted()
|
||||
->create();
|
||||
$segmentFactory
|
||||
->withName($segmentTitle . '2')
|
||||
->withUserRoleFilter('Administrator')
|
||||
->withDeleted()
|
||||
->create();
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->waitForElement('[data-automation-id="filters_trash"]');
|
||||
$i->click('[data-automation-id="filters_trash"]');
|
||||
$i->waitForText($segmentTitle, 20, $listingAutomationSelector);
|
||||
$i->clickItemRowActionByItemName($segmentTitle, 'Delete permanently');
|
||||
$i->waitForText('1 segment was permanently deleted.');
|
||||
$i->dontSeeElement($listingAutomationSelector);
|
||||
$i->seeNoJSErrors();
|
||||
$i->waitForText($segmentTitle . '2', 20);
|
||||
}
|
||||
|
||||
public function emptyTrash(\AcceptanceTester $i) {
|
||||
$i->wantTo('Empty a trash on Segment page');
|
||||
|
||||
$segmentTitle = 'Empty Trash';
|
||||
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle)
|
||||
->withUserRoleFilter('Administrator')
|
||||
->withDeleted()
|
||||
->create();
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segmentFactory
|
||||
->withName($segmentTitle . '2')
|
||||
->withUserRoleFilter('Administrator')
|
||||
->create();
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->waitForElement('[data-automation-id="filters_trash"]');
|
||||
$i->click('[data-automation-id="filters_trash"]');
|
||||
$i->waitForText($segmentTitle, 20, $listingAutomationSelector);
|
||||
|
||||
$i->click('[data-automation-id="empty_trash"]');
|
||||
$i->waitForText('1 segment was permanently deleted.');
|
||||
$i->dontSeeElement($listingAutomationSelector);
|
||||
$i->seeNoJSErrors();
|
||||
|
||||
$i->click('[data-automation-id="filters_all"]');
|
||||
$i->waitForText($segmentTitle . '2', 20);
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Test\DataFactories\DynamicSegment;
|
||||
|
||||
class EditExistingSegmentCest {
|
||||
public function editUserRoleSegment(\AcceptanceTester $i) {
|
||||
$i->wantTo('Edit an existing WP user role segment');
|
||||
|
||||
$segmentTitle = 'Edit User Role Segment Test';
|
||||
$segmentEditedTitle = 'Edit User Role Segment Test Edited';
|
||||
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle)
|
||||
->withUserRoleFilter('Administrator')
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
$i->waitForText($segmentTitle, 10, $listingAutomationSelector);
|
||||
$i->clickItemRowActionByItemName($segmentTitle, 'Edit');
|
||||
|
||||
$i->waitForElementNotVisible('.mailpoet_form_loading');
|
||||
$i->fillField(['name' => 'name'], $segmentEditedTitle);
|
||||
$i->fillField(['name' => 'description'], 'Lorem ipsum dolor amed edited');
|
||||
$i->selectOption('form select[name=segmentType]', 'WordPress user roles');
|
||||
$i->selectOption('form select[name=wordpressRole]', 'Editor');
|
||||
$i->click('Save');
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
|
||||
$i->waitForText($segmentEditedTitle, 20, $listingAutomationSelector);
|
||||
$i->seeNoJSErrors();
|
||||
}
|
||||
}
|
164
tests/acceptance/ManageSegmentsCest.php
Normal file
164
tests/acceptance/ManageSegmentsCest.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Test\DataFactories\DynamicSegment;
|
||||
use MailPoet\Test\DataFactories\Settings;
|
||||
use MailPoet\Test\DataFactories\Newsletter;
|
||||
|
||||
class ViewSegmentSubscribersCest {
|
||||
public function _before() {
|
||||
(new Settings())->withWooCommerceListImportPageDisplayed(true);
|
||||
(new Settings())->withCookieRevenueTrackingDisabled();
|
||||
}
|
||||
|
||||
public function viewUserRoleSegmentSubscribers(\AcceptanceTester $i) {
|
||||
$i->wantTo('View WP user role segment subscribers');
|
||||
|
||||
$wpAdminEmail = 'test-admin@example.com';
|
||||
$wpEditorEmail = 'test-editor@example.com';
|
||||
$wpAuthorEmail = 'test-author@example.com';
|
||||
$segmentTitle = 'User Role Segment Test';
|
||||
|
||||
$this->createUser('Test Admin', 'admin', $wpAdminEmail);
|
||||
$this->createUser('Test Editor', 'editor', $wpEditorEmail);
|
||||
$this->createUser('Test Author', 'author', $wpAuthorEmail);
|
||||
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle)
|
||||
->withUserRoleFilter('Editor')
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
$i->waitForText($segmentTitle, 10, $listingAutomationSelector);
|
||||
$i->clickItemRowActionByItemName($segmentTitle, 'View Subscribers');
|
||||
$i->seeInCurrentUrl('mailpoet-subscribers#');
|
||||
$i->seeInCurrentUrl('segment=' . $segment->id);
|
||||
$i->waitForText($wpEditorEmail, 20);
|
||||
$i->see($segmentTitle, ['css' => 'select[name=segment]']);
|
||||
$i->dontSee($wpAdminEmail);
|
||||
$i->dontSee($wpAuthorEmail);
|
||||
$i->seeNoJSErrors();
|
||||
}
|
||||
|
||||
public function createEditTrashRestoreAndDeleteExistingSegment(\AcceptanceTester $i) {
|
||||
$i->wantTo('Create, edit, trash, restore and delete existing segment');
|
||||
$segmentTitle = 'User Segment';
|
||||
$segmentEditedTitle = 'User Segment EDITED';
|
||||
$segmentDesc = 'Lorem ipsum dolor sit amet';
|
||||
$segmentEditedDesc = 'Lorem ipsum dolor sit amet EDITED';
|
||||
|
||||
// Prepare (2) additional segments for the test
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle . ' TRASHED 1')
|
||||
->withUserRoleFilter('Administrator')
|
||||
->withDeleted()
|
||||
->create();
|
||||
$segmentFactory
|
||||
->withName($segmentTitle . ' TRASHED 2')
|
||||
->withUserRoleFilter('Administrator')
|
||||
->withDeleted()
|
||||
->create();
|
||||
|
||||
// Create a new segment
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="new-segment"]');
|
||||
$i->fillField(['name' => 'name'], $segmentTitle);
|
||||
$i->fillField(['name' => 'description'], $segmentDesc);
|
||||
$i->selectOption('form select[name=segmentType]', 'WordPress user roles');
|
||||
$i->selectOption('form select[name=wordpressRole]', 'Subscriber');
|
||||
$i->click('Save');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->waitForText($segmentTitle);
|
||||
|
||||
// Edit existing segment
|
||||
$i->clickItemRowActionByItemName($segmentTitle, 'Edit');
|
||||
$i->waitForElementNotVisible('.mailpoet_form_loading');
|
||||
$i->fillField(['name' => 'name'], $segmentEditedTitle);
|
||||
$i->fillField(['name' => 'description'], $segmentEditedDesc);
|
||||
$i->selectOption('form select[name=segmentType]', 'WordPress user roles');
|
||||
$i->selectOption('form select[name=wordpressRole]', 'Editor');
|
||||
$i->click('Save');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->waitForText($segmentEditedTitle);
|
||||
$i->seeNoJSErrors();
|
||||
|
||||
// Trash existing segment
|
||||
$i->clickItemRowActionByItemName($segmentEditedTitle, 'Move to trash');
|
||||
$i->waitForText('1 segment was moved to the trash.');
|
||||
$i->click('[data-automation-id="filters_trash"]');
|
||||
$i->waitForText($segmentEditedTitle);
|
||||
$i->seeNoJSErrors();
|
||||
|
||||
// Restore trashed segment
|
||||
$i->clickItemRowActionByItemName($segmentEditedTitle, 'Restore');
|
||||
$i->waitForText('1 segment has been restored from the Trash.');
|
||||
$i->seeInCurrentURL(urlencode('group[trash]'));
|
||||
$i->click('[data-automation-id="filters_all"]');
|
||||
$i->waitForText($segmentEditedTitle);
|
||||
$i->seeNoJSErrors();
|
||||
|
||||
// Trash and delete existing segment
|
||||
$i->clickItemRowActionByItemName($segmentEditedTitle, 'Move to trash');
|
||||
$i->waitForText('1 segment was moved to the trash.');
|
||||
$i->click('[data-automation-id="filters_trash"]');
|
||||
$i->waitForText($segmentEditedTitle);
|
||||
$i->clickItemRowActionByItemName($segmentEditedTitle, 'Delete permanently');
|
||||
$i->waitForText('1 segment was permanently deleted.');
|
||||
$i->seeNoJSErrors();
|
||||
$i->waitForText($segmentTitle . ' TRASHED 1');
|
||||
$i->waitForText($segmentTitle . ' TRASHED 2');
|
||||
|
||||
// Empty trash from other (2) segments
|
||||
$i->click('[data-automation-id="empty_trash"]');
|
||||
$i->waitForText('2 segments were permanently deleted.');
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
$i->dontSeeElement($listingAutomationSelector);
|
||||
$i->seeInCurrentURL(urlencode('group[all]'));
|
||||
$i->seeNoJSErrors();
|
||||
}
|
||||
|
||||
public function createEmailSegment(\AcceptanceTester $i) {
|
||||
$i->wantTo('Create a new email segment');
|
||||
$emailSubject = 'Segment Email Test';
|
||||
$newsletterFactory = new Newsletter();
|
||||
$newsletterFactory->withSubject($emailSubject)->create();
|
||||
$segmentTitle = 'Create Email Segment Test';
|
||||
$segmentDesc = 'Lorem ipsum dolor sit amet';
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->click('[data-automation-id="new-segment"]');
|
||||
$i->fillField(['name' => 'name'], $segmentTitle);
|
||||
$i->fillField(['name' => 'description'], $segmentDesc);
|
||||
$i->selectOption('form select[name=segmentType]', 'Email');
|
||||
$i->selectOption('form select[name=action]', 'opened');
|
||||
$i->click('#select2-newsletter_id-container');
|
||||
$i->selectOptionInSelect2($emailSubject);
|
||||
$i->click('Save');
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->waitForText($segmentTitle, 20);
|
||||
}
|
||||
|
||||
private function createUser($name, $role, $email) {
|
||||
$userId = wp_create_user($name, "$name-password", $email);
|
||||
$user = get_user_by('ID', $userId);
|
||||
foreach ($user->roles as $defaultRole) {
|
||||
$user->remove_role($defaultRole);
|
||||
}
|
||||
$user->add_role($role);
|
||||
return $user;
|
||||
}
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Test\DataFactories\DynamicSegment;
|
||||
|
||||
class RestoreTrashedSegmentCest {
|
||||
public function restoreSegmentFromTrash(\AcceptanceTester $i) {
|
||||
$i->wantTo('Restore a segment from trash');
|
||||
|
||||
$segmentTitle = 'Restore Segment From Trash Test';
|
||||
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle)
|
||||
->withUserRoleFilter('Administrator')
|
||||
->withDeleted()
|
||||
->create();
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
|
||||
$i->waitForElement('[data-automation-id="filters_trash"]', 10);
|
||||
$i->click('[data-automation-id="filters_trash"]');
|
||||
$i->waitForText($segmentTitle, 10, $listingAutomationSelector);
|
||||
$i->clickItemRowActionByItemName($segmentTitle, 'Restore');
|
||||
$i->waitForText('1 segment has been restored from the Trash.', 10);
|
||||
$i->seeInCurrentURL(urlencode('group[all]'));
|
||||
$i->waitForText($segmentTitle, 20, $listingAutomationSelector);
|
||||
$i->seeNoJSErrors();
|
||||
}
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Test\DataFactories\DynamicSegment;
|
||||
use MailPoet\Test\DataFactories\Settings;
|
||||
|
||||
class TrashExistingSegmentCest {
|
||||
public function _before() {
|
||||
(new Settings())->withWooCommerceListImportPageDisplayed(true);
|
||||
(new Settings())->withCookieRevenueTrackingDisabled();
|
||||
}
|
||||
|
||||
public function moveSegmentToTrash(\AcceptanceTester $i) {
|
||||
$i->wantTo('Move an existing segment to trash');
|
||||
|
||||
$segmentTitle = 'Move Segment To Trash Test';
|
||||
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle)
|
||||
->withUserRoleFilter('Administrator')
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
$i->waitForText($segmentTitle, 10, $listingAutomationSelector);
|
||||
$i->clickItemRowActionByItemName($segmentTitle, 'Move to trash');
|
||||
$i->waitForText('1 segment was moved to the trash.', 10);
|
||||
$i->click('[data-automation-id="filters_trash"]');
|
||||
$i->waitForText($segmentTitle, 20, $listingAutomationSelector);
|
||||
$i->seeNoJSErrors();
|
||||
}
|
||||
}
|
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace MailPoet\Test\Acceptance;
|
||||
|
||||
use MailPoet\Test\DataFactories\DynamicSegment;
|
||||
use MailPoet\Test\DataFactories\Settings;
|
||||
|
||||
class ViewSegmentSubscribersCest {
|
||||
public function _before() {
|
||||
(new Settings())->withWooCommerceListImportPageDisplayed(true);
|
||||
(new Settings())->withCookieRevenueTrackingDisabled();
|
||||
}
|
||||
|
||||
public function viewUserRoleSegmentSubscribers(\AcceptanceTester $i) {
|
||||
$i->wantTo('View WP user role segment subscribers');
|
||||
|
||||
$wpAdminEmail = 'test-admin@example.com';
|
||||
$wpEditorEmail = 'test-editor@example.com';
|
||||
$wpAuthorEmail = 'test-author@example.com';
|
||||
$segmentTitle = 'User Role Segment Test';
|
||||
|
||||
$this->createUser('Test Admin', 'admin', $wpAdminEmail);
|
||||
$this->createUser('Test Editor', 'editor', $wpEditorEmail);
|
||||
$this->createUser('Test Author', 'author', $wpAuthorEmail);
|
||||
|
||||
$segmentFactory = new DynamicSegment();
|
||||
$segment = $segmentFactory
|
||||
->withName($segmentTitle)
|
||||
->withUserRoleFilter('Editor')
|
||||
->create();
|
||||
|
||||
$i->login();
|
||||
$i->amOnMailpoetPage('Lists');
|
||||
$i->waitForElement('[data-automation-id="dynamic-segments-tab"]');
|
||||
$i->click('[data-automation-id="dynamic-segments-tab"]');
|
||||
$listingAutomationSelector = '[data-automation-id="listing_item_' . $segment->id . '"]';
|
||||
$i->waitForText($segmentTitle, 10, $listingAutomationSelector);
|
||||
$i->clickItemRowActionByItemName($segmentTitle, 'View Subscribers');
|
||||
$i->seeInCurrentUrl('mailpoet-subscribers#');
|
||||
$i->seeInCurrentUrl('segment=' . $segment->id);
|
||||
$i->waitForText($wpEditorEmail, 20);
|
||||
$i->see($segmentTitle, ['css' => 'select[name=segment]']);
|
||||
$i->dontSee($wpAdminEmail);
|
||||
$i->dontSee($wpAuthorEmail);
|
||||
$i->seeNoJSErrors();
|
||||
}
|
||||
|
||||
private function createUser($name, $role, $email) {
|
||||
$userId = wp_create_user($name, "$name-password", $email);
|
||||
$user = get_user_by('ID', $userId);
|
||||
foreach ($user->roles as $defaultRole) {
|
||||
$user->remove_role($defaultRole);
|
||||
}
|
||||
$user->add_role($role);
|
||||
return $user;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user