Fix undefined classes and functions [MAILPOET-2488]

This commit is contained in:
wxa
2019-12-26 18:48:57 +03:00
committed by amine-mp
parent 09a1411c81
commit 17b578a09f
13 changed files with 45 additions and 22 deletions

View File

@ -4,6 +4,7 @@ define('ABSPATH', getenv('WP_ROOT') . '/');
require_once ABSPATH . 'wp-load.php'; require_once ABSPATH . 'wp-load.php';
require_once ABSPATH . 'wp-admin/includes/admin.php'; require_once ABSPATH . 'wp-admin/includes/admin.php';
require_once(ABSPATH . 'wp-admin/includes/ms.php');
require_once ABSPATH . 'wp-includes/class-phpmailer.php'; require_once ABSPATH . 'wp-includes/class-phpmailer.php';
if (!class_exists('\MailPoet\Premium\DI\ContainerConfigurator')) { if (!class_exists('\MailPoet\Premium\DI\ContainerConfigurator')) {
@ -13,3 +14,5 @@ if (!class_exists('\MailPoet\Premium\DI\ContainerConfigurator')) {
if (!class_exists(WooCommerce::class)) { if (!class_exists(WooCommerce::class)) {
require_once __DIR__ . '/woocommerce.php'; require_once __DIR__ . '/woocommerce.php';
} }
require_once __DIR__ . '/function-stubs.php';

View File

@ -0,0 +1,6 @@
<?php
if (!function_exists('members_get_cap_group')) {
function members_get_cap_group($name) {
}
}

View File

@ -73,6 +73,8 @@ class WC_Order { // phpcs:ignore
* @method int get_product_id(string $context = 'view') * @method int get_product_id(string $context = 'view')
*/ */
class WC_Order_Item_Product { // phpcs:ignore class WC_Order_Item_Product { // phpcs:ignore
function get_product_id() { // phpcs:ignore
}
} }
/** /**
@ -80,3 +82,13 @@ class WC_Order_Item_Product { // phpcs:ignore
*/ */
class WC_Product { // phpcs:ignore class WC_Product { // phpcs:ignore
} }
class WC_Cart { // phpcs:ignore
}
class WC_Mailer { // phpcs:ignore
function email_header() { // phpcs:ignore
}
function email_footer() { // phpcs:ignore
}
}

View File

@ -32,7 +32,7 @@ class InstallerTest extends \MailPoetTest {
} }
public function testItGetsPluginInformation() { public function testItGetsPluginInformation() {
$args = new \StdClass; $args = new \stdClass;
$args->slug = $this->slug; $args->slug = $this->slug;
$installer = Stub::construct( $installer = Stub::construct(
$this->installer, $this->installer,
@ -69,11 +69,11 @@ class InstallerTest extends \MailPoetTest {
} }
public function testItIgnoresNonMatchingRequestsWhenGettingPluginInformation() { public function testItIgnoresNonMatchingRequestsWhenGettingPluginInformation() {
$data = new \StdClass; $data = new \stdClass;
$data->some_property = '123'; $data->some_property = '123';
$result = $this->installer->getPluginInformation($data, 'some_action', null); $result = $this->installer->getPluginInformation($data, 'some_action', null);
expect($result)->equals($data); expect($result)->equals($data);
$args = new \StdClass; $args = new \stdClass;
$args->slug = 'different-slug'; $args->slug = 'different-slug';
$result = $this->installer->getPluginInformation($data, 'plugin_information', $args); $result = $this->installer->getPluginInformation($data, 'plugin_information', $args);
expect($result)->equals($data); expect($result)->equals($data);

View File

@ -37,7 +37,7 @@ class UpdaterTest extends \MailPoetTest {
} }
public function testItChecksForUpdates() { public function testItChecksForUpdates() {
$update_transient = new \StdClass; $update_transient = new \stdClass;
$update_transient->last_checked = time(); $update_transient->last_checked = time();
$updater = Stub::construct( $updater = Stub::construct(
$this->updater, $this->updater,
@ -75,6 +75,6 @@ class UpdaterTest extends \MailPoetTest {
public function testItReturnsObjectIfPassedNonObjectWhenCheckingForUpdates() { public function testItReturnsObjectIfPassedNonObjectWhenCheckingForUpdates() {
$result = $this->updater->checkForUpdate(null); $result = $this->updater->checkForUpdate(null);
expect($result instanceof \StdClass)->true(); expect($result instanceof \stdClass)->true();
} }
} }

View File

@ -121,11 +121,8 @@ class NewsletterOptionFieldTest extends \MailPoetTest {
} }
public function _after() { public function _after() {
ORM::forTable(NewsletterOption::$_table) NewsletterOption::deleteMany();
->deleteMany(); NewsletterOptionField::deleteMany();
ORM::forTable(NewsletterOptionField::$_table) Newsletter::deleteMany();
->deleteMany();
ORM::forTable(Newsletter::$_table)
->deleteMany();
} }
} }

View File

@ -22,7 +22,6 @@ class NewsletterPostTest extends \MailPoetTest {
} }
public function _after() { public function _after() {
ORM::for_table(NewsletterPost::$_table) NewsletterPost::deleteMany();
->deleteMany();
} }
} }

View File

@ -104,7 +104,6 @@ class NewsletterTemplateTest extends \MailPoetTest {
} }
public function _after() { public function _after() {
ORM::for_table(NewsletterTemplate::$_table) NewsletterTemplate::deleteMany();
->deleteMany();
} }
} }

View File

@ -27,7 +27,6 @@ class StatisticsUnsubscribesTest extends \MailPoetTest {
} }
public function _after() { public function _after() {
ORM::for_table(StatisticsUnsubscribes::$_table) StatisticsUnsubscribes::deleteMany();
->deleteMany();
} }
} }

View File

@ -77,7 +77,6 @@ class SubscriberCustomFieldTest extends \MailPoetTest {
} }
public function _after() { public function _after() {
ORM::forTable(SubscriberCustomField::$_table) SubscriberCustomField::deleteMany();
->deleteMany();
} }
} }

View File

@ -423,7 +423,7 @@ class SubscriberTest extends \MailPoetTest {
} }
public function testItCanCreateOrUpdateMultipleRecords() { public function testItCanCreateOrUpdateMultipleRecords() {
ORM::forTable(Subscriber::$_table)->deleteMany(); Subscriber::deleteMany();
$columns = [ $columns = [
'first_name', 'first_name',
'last_name', 'last_name',

View File

@ -0,0 +1,7 @@
<?php
namespace MailPoet\Test\Segments;
class WPUserWithExtraProps extends \WP_User {
public $order_id;
}

View File

@ -15,6 +15,8 @@ use MailPoet\Subscribers\Source;
use MailPoetVendor\Carbon\Carbon; use MailPoetVendor\Carbon\Carbon;
use MailPoetVendor\Idiorm\ORM; use MailPoetVendor\Idiorm\ORM;
require_once('WPUserWithExtraProps.php');
class WooCommerceTest extends \MailPoetTest { class WooCommerceTest extends \MailPoetTest {
public $customerRoleAdded; public $customerRoleAdded;
@ -585,7 +587,7 @@ class WooCommerceTest extends \MailPoetTest {
* Those tests are testing user synchronisation, so we need data in wp_users table which has not been synchronised to * Those tests are testing user synchronisation, so we need data in wp_users table which has not been synchronised to
* mailpoet database yet. We cannot use wp_insert_user functions because they would do the sync on insert. * mailpoet database yet. We cannot use wp_insert_user functions because they would do the sync on insert.
* *
* @return \WP_User * @return WPUserWithExtraProps
*/ */
private function insertRegisteredCustomer($number = null) { private function insertRegisteredCustomer($number = null) {
global $wpdb; global $wpdb;
@ -603,7 +605,7 @@ class WooCommerceTest extends \MailPoetTest {
)', $wpdb->users)); )', $wpdb->users));
$id = $db->lastInsertId(); $id = $db->lastInsertId();
// add customer role // add customer role
$user = new \WP_User($id); $user = new WPUserWithExtraProps($id);
$user->add_role('customer'); $user->add_role('customer');
$this->userEmails[] = $user->user_email; $this->userEmails[] = $user->user_email;
return $user; return $user;