Move automatic email acceptance tests from Premium plugin

[MAILPOET-2382]
This commit is contained in:
Jan Jakeš
2019-10-02 15:45:26 +02:00
committed by Jack Kitterhing
parent 33b243f787
commit d459baf9ba
7 changed files with 411 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
<?php
namespace MailPoet\Test\Acceptance;
use MailPoet\Features\FeaturesController;
use MailPoet\Test\DataFactories\Features;
class CreateWooCommerceNewsletterCest {
function createFirstPurchaseEmail(\AcceptanceTester $I) {
$I->wantTo('Create and configure a first purchase automatic email');
$newsletter_title = 'First Purchase Email Creation';
$I->activateWooCommerce();
$I->login();
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="new_email"]');
$I->dontSeeElement('[data-automation-id="woocommerce_premium_feature_notice"]');
$I->click('[data-automation-id="create_woocommerce"]');
$I->click('[data-automation-id="create_woocommerce_first_purchase"]');
$I->waitForText('Select WooCommerce events conditions');
$I->click('Next');
$template = '[data-automation-id="select_template_0"]';
$I->waitForElement($template);
$I->click($template);
$title_element = '[data-automation-id="newsletter_title"]';
$I->waitForElement($title_element);
$I->fillField($title_element, $newsletter_title);
$I->click('Next');
$I->waitForElement('[data-automation-id="newsletter_send_form"]');
$newsletter_listing_element = '[data-automation-id="listing_item_' . basename($I->getCurrentUrl()) . '"]';
$I->waitForElementClickable('[value="Activate"]');
$I->click('Activate');
$I->waitForElement($newsletter_listing_element);
$I->see($newsletter_title, $newsletter_listing_element);
$I->see('Email sent when a customer makes their first purchase.', $newsletter_listing_element);
}
function createAbandonedCartEmail(\AcceptanceTester $I) {
$I->wantTo('Create and configure an abandoned cart automatic email');
$newsletter_title = 'Abandoned Cart Email Creation';
$I->activateWooCommerce();
$I->login();
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="new_email"]');
$I->click('[data-automation-id="create_woocommerce"]');
$I->scrollToTop();
$I->click('[data-automation-id="create_woocommerce_abandoned_shopping_cart"]');
$I->waitForText('Abandoned Shopping Cart');
$I->click('Next');
$template = '[data-automation-id="select_template_0"]';
$I->waitForElement($template);
$I->click($template);
$title_element = '[data-automation-id="newsletter_title"]';
$I->waitForElement($title_element);
$I->fillField($title_element, $newsletter_title);
$I->click('Next');
$I->waitForElement('[data-automation-id="newsletter_send_form"]');
$newsletter_listing_element = '[data-automation-id="listing_item_' . basename($I->getCurrentUrl()) . '"]';
$I->waitForElementClickable('[value="Activate"]');
$I->click('Activate');
$I->waitForElement($newsletter_listing_element);
$I->see($newsletter_title, $newsletter_listing_element);
$I->see('Email sent when a customer abandons his cart', $newsletter_listing_element);
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace MailPoet\Test\Acceptance;
use MailPoet\Test\DataFactories\Newsletter;
class DeleteAutomaticWooCommerceEmailCest {
function _before(\AcceptanceTester $I) {
$I->activateWooCommerce();
}
function trashAutomaticWooCommerceEmail(\AcceptanceTester $I) {
$newsletter_name = 'Trash Automatic WooCommerce Email Test';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($newsletter_name)
->withAutomaticTypeWooCommerceFirstPurchase()
->create();
$I->wantTo('Trash automatic WooCommerce email');
$I->login();
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="tab-WooCommerce"]');
$I->waitForText($newsletter_name);
$I->clickItemRowActionByItemName($newsletter_name, 'Move to trash');
$I->waitForElement('[data-automation-id="filters_trash"]');
$I->click('[data-automation-id="filters_trash"]');
$I->waitForText($newsletter_name);
}
function restoreTrashedAutomaticWooCommerceEmail(\AcceptanceTester $I) {
$newsletter_name = 'Restore Trashed Automatic WooCommerce Email Test';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($newsletter_name)
->withAutomaticTypeWooCommerceFirstPurchase()
->withDeleted()
->create();
$I->wantTo('Restore trashed automatic WooCommerce email');
$I->login();
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="tab-WooCommerce"]');
$I->waitForElement('[data-automation-id="filters_trash"]');
$I->click('[data-automation-id="filters_trash"]');
$I->waitForText($newsletter_name);
$I->clickItemRowActionByItemName($newsletter_name, 'Restore');
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="tab-WooCommerce"]');
$I->waitForText($newsletter_name);
}
function deleteTrashedAutomaticWooCommerceEmail(\AcceptanceTester $I) {
$newsletter_name = 'Delete Trashed Automatic WooCommerce Email Test';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($newsletter_name)
->withAutomaticTypeWooCommerceFirstPurchase()
->withDeleted()
->create();
$I->wantTo('Delete trashed automatic WooCommerce email');
$I->login();
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="tab-WooCommerce"]');
$I->waitForElement('[data-automation-id="filters_trash"]');
$I->click('[data-automation-id="filters_trash"]');
$I->waitForText($newsletter_name);
$I->clickItemRowActionByItemName($newsletter_name, 'Delete Permanently');
$I->waitForText('permanently deleted.');
$I->waitForElementNotVisible($newsletter_name);
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace MailPoet\Test\Acceptance;
use MailPoet\Test\DataFactories\Newsletter;
class DuplicateAutomaticEmailCest {
function duplicateAutomaticEmail(\AcceptanceTester $I) {
$I->wantTo('Duplicate an automatic email');
$I->activateWooCommerce();
$email_subject = 'Duplicate Automatic Email Test';
$newsletter_factory = new Newsletter();
$newsletter_factory->withSubject($email_subject)->withAutomaticTypeWooCommerceFirstPurchase()->create();
$I->login();
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="tab-WooCommerce"]');
$I->waitForText($email_subject);
$I->clickItemRowActionByItemName($email_subject, 'Duplicate');
$I->waitForText('Email "Copy of ' . $email_subject . '" has been duplicated.', 20);
$I->waitForListingItemsToLoad();
$I->clickItemRowActionByItemName('Copy of ' . $email_subject, 'Edit');
$I->waitForElement('[data-automation-id="newsletter_title"]', 20);
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace MailPoet\Test\Acceptance;
use MailPoet\Test\DataFactories\Newsletter;
class EditAutomaticWooCommerceEmailCest {
function dontSeeWooCommerceTabWhenWooCommerceIsNotActive(\AcceptanceTester $I) {
$I->wantTo('Not see WooCommerce tab');
$I->deactivateWooCommerce();
$I->login();
$I->amOnMailpoetPage('Emails');
$I->dontSee('[data-automation-id="tab-WooCommerce"]');
}
function editAutomaticWooCommerceEmail(\AcceptanceTester $I) {
$newsletter_name = 'Edit Automatic WooCommerce Email Test';
$newsletter_edited_name = 'Edit Automatic WooCommerce Email Test Edited';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($newsletter_name)
->withAutomaticTypeWooCommerceFirstPurchase()
->create();
// open editation
$I->wantTo('Edit automatic WooCommerce email');
$I->activateWooCommerce();
$I->login();
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="tab-WooCommerce"]');
$I->waitForText($newsletter_name);
$I->clickItemRowActionByItemName($newsletter_name, 'Edit');
// edit subject
$title_element = '[data-automation-id="newsletter_title"]';
$I->waitForElement($title_element);
$I->seeInCurrentUrl('mailpoet-newsletter-editor');
$I->fillField($title_element, $newsletter_edited_name);
// edit sending
$I->click('Next');
$I->waitForElementVisible('#field_sender_name');
$I->fillField('#field_sender_name', 'Test sender');
$I->click('Save as draft and close');
// check update success
$I->waitForText('Email was updated successfully!');
$I->amOnMailpoetPage('Emails');
$I->click('[data-automation-id="tab-WooCommerce"]');
$I->waitForText($newsletter_edited_name);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace MailPoet\Test\Acceptance;
use Codeception\Util\Locator;
use MailPoet\Test\DataFactories\Newsletter;
use MailPoet\Test\DataFactories\Settings;
use MailPoet\Test\DataFactories\WooCommerceProduct;
use MailPoet\Util\Security;
class SendCategoryPurchaseEmailCest {
function _before(\AcceptanceTester $I) {
$I->activateWooCommerce();
$settings_factory = new Settings();
$settings_factory->withWooCommerceListImportPageDisplayed(true);
$settings_factory->withWooCommerceCheckoutOptinEnabled();
}
function sendCategoryPurchaseEmail(\AcceptanceTester $I) {
$I->wantTo('Buy a product in category and receive a "Purchased In This Category" email');
$product_name = 'Category Purchase Test Product';
$product_factory = new WooCommerceProduct($I);
$category_id = $product_factory->createCategory('Category 1');
$product = $product_factory
->withName($product_name)
->withCategoryIds([$category_id])
->create();
$email_subject = 'Product In Category Purchase Test';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($email_subject)
->withAutomaticTypeWooCommerceProductInCategoryPurchased([$product])
->withActiveStatus()
->create();
$user_email = Security::generateRandomString() . '-user@email.example';
$I->orderProduct($product, $user_email);
$I->amOnMailboxAppPage();
$I->waitForText($email_subject, 20);
$I->click(Locator::contains('span.subject', $email_subject));
$I->waitForText($user_email, 20);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace MailPoet\Test\Acceptance;
use Codeception\Util\Locator;
use MailPoet\Test\DataFactories\Newsletter;
use MailPoet\Test\DataFactories\Settings;
use MailPoet\Test\DataFactories\WooCommerceProduct;
class SendFirstPurchaseEmailCest {
function _before(\AcceptanceTester $I) {
$I->activateWooCommerce();
$this->settings_factory = new Settings();
$this->settings_factory->withWooCommerceListImportPageDisplayed(true);
$this->settings_factory->withWooCommerceCheckoutOptinEnabled();
}
function sendFirstPurchaseEmail(\AcceptanceTester $I) {
$I->wantTo('Send a "First purchase email"');
$product_name = 'First Purchase Product';
$product_factory = new WooCommerceProduct($I);
$product = $product_factory->withName($product_name)->create();
$email_subject = 'First Purchase Test';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($email_subject)
->withAutomaticTypeWooCommerceFirstPurchase()
->withActiveStatus()
->create();
$user_email = 'user@email.test';
$I->orderProduct($product, $user_email);
$I->amOnMailboxAppPage();
$I->waitForText($email_subject, 20);
$I->click(Locator::contains('span.subject', $email_subject));
$I->waitForText($user_email, 20);
}
function doNotSendFirstPurchaseEmailIfUserHasNotOptedIn(\AcceptanceTester $I) {
$I->wantTo('Buy a product, do not opt-in and don\'t receive a "First purchase email"');
$product_name = 'First Purchase Product';
$product_factory = new WooCommerceProduct($I);
$product = $product_factory->withName($product_name)->create();
$email_subject = 'First Purchase Test 2';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($email_subject)
->withAutomaticTypeWooCommerceFirstPurchase()
->withActiveStatus()
->create();
$user_email = 'user3@email.test';
$I->orderProduct($product, $user_email, true, false);
$I->amOnMailboxAppPage();
$I->dontSee($email_subject);
$I->dontSee($user_email);
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace MailPoet\Test\Acceptance;
use Codeception\Util\Locator;
use MailPoet\Test\DataFactories\Newsletter;
use MailPoet\Test\DataFactories\Settings;
use MailPoet\Test\DataFactories\WooCommerceProduct;
class SendProductPurchaseEmailCest {
function _before(\AcceptanceTester $I) {
$I->activateWooCommerce();
$this->settings_factory = new Settings();
$this->settings_factory->withWooCommerceListImportPageDisplayed(true);
$this->settings_factory->withWooCommerceCheckoutOptinEnabled();
}
function sendProductPurchaseEmail(\AcceptanceTester $I) {
$I->wantTo('Buy a product and receive a "Product Purchase" email');
$product_name = 'Product Purchase Test Product';
$product_factory = new WooCommerceProduct($I);
$product = $product_factory->withName($product_name)->create();
$email_subject = 'Product Purchase Test';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($email_subject)
->withAutomaticTypeWooCommerceProductPurchased([$product])
->withActiveStatus()
->create();
$user_email = 'user2@email.test';
$I->orderProduct($product, $user_email);
$I->amOnMailboxAppPage();
$I->waitForText($email_subject, 20);
$I->click(Locator::contains('span.subject', $email_subject));
$I->waitForText($user_email, 20);
}
function doNotSendProductPurchaseEmailIfUserHasNotOptedIn(\AcceptanceTester $I) {
$I->wantTo('Buy a product, do not opt-in and don\'t receive a "Product Purchase" email');
$product_name = 'Product Purchase Test Product';
$product_factory = new WooCommerceProduct($I);
$product = $product_factory->withName($product_name)->create();
$email_subject = 'Product Purchase Test 2';
$newsletter_factory = new Newsletter();
$newsletter_factory
->withSubject($email_subject)
->withAutomaticTypeWooCommerceProductPurchased([$product])
->withActiveStatus()
->create();
$user_email = 'user4@email.test';
$I->orderProduct($product, $user_email, true, false);
$I->amOnMailboxAppPage();
$I->dontSee($email_subject);
$I->dontSee($user_email);
}
}