Updated Import & MailChimp tests
This commit is contained in:
@@ -125,10 +125,10 @@ class MailChimp {
|
|||||||
$errorMessage = __('Invalid API Key.');
|
$errorMessage = __('Invalid API Key.');
|
||||||
break;
|
break;
|
||||||
case 'connection':
|
case 'connection':
|
||||||
$errorMessage = __('Could not connect to your MailChimp account');
|
$errorMessage = __('Could not connect to your MailChimp account.');
|
||||||
break;
|
break;
|
||||||
case 'headers':
|
case 'headers':
|
||||||
$errorMessage = __('The selected lists do not have matching columns (headers)');
|
$errorMessage = __('The selected lists do not have matching columns (headers).');
|
||||||
break;
|
break;
|
||||||
case 'size':
|
case 'size':
|
||||||
$errorMessage = __('The information received from MailChimp is too large for processing. Please limit the number of lists!');
|
$errorMessage = __('The information received from MailChimp is too large for processing. Please limit the number of lists!');
|
||||||
@@ -137,7 +137,7 @@ class MailChimp {
|
|||||||
$errorMessage = __('Did not find any active subscribers.');
|
$errorMessage = __('Did not find any active subscribers.');
|
||||||
break;
|
break;
|
||||||
case 'lists':
|
case 'lists':
|
||||||
$errorMessage = __('Did not find any valid lists');
|
$errorMessage = __('Did not find any valid lists.');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw new \Exception($errorMessage);
|
throw new \Exception($errorMessage);
|
||||||
|
@@ -326,17 +326,17 @@ class ImportTest extends MailPoetTest {
|
|||||||
|
|
||||||
function testItCanUpdateSubscribers() {
|
function testItCanUpdateSubscribers() {
|
||||||
$result = $this->import->process();
|
$result = $this->import->process();
|
||||||
expect($result['data']['updated'])->equals(0);
|
expect($result['updated'])->equals(0);
|
||||||
$result = $this->import->process();
|
$result = $this->import->process();
|
||||||
expect($result['data']['updated'])->equals(2);
|
expect($result['updated'])->equals(2);
|
||||||
$this->import->update_subscribers = false;
|
$this->import->update_subscribers = false;
|
||||||
$result = $this->import->process();
|
$result = $this->import->process();
|
||||||
expect($result['data']['updated'])->equals(0);
|
expect($result['updated'])->equals(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanProcess() {
|
function testItCanProcess() {
|
||||||
$result = $this->import->process();
|
$result = $this->import->process();
|
||||||
expect($result['data']['created'])->equals(2);
|
expect($result['created'])->equals(2);
|
||||||
Subscriber::where('email', 'mary@jane.com')
|
Subscriber::where('email', 'mary@jane.com')
|
||||||
->findOne()
|
->findOne()
|
||||||
->delete();
|
->delete();
|
||||||
@@ -344,7 +344,7 @@ class ImportTest extends MailPoetTest {
|
|||||||
$this->import->created_at = date('Y-m-d H:i:s', $timestamp);
|
$this->import->created_at = date('Y-m-d H:i:s', $timestamp);
|
||||||
$this->import->updated_at = date('Y-m-d H:i:s', $timestamp + 1);
|
$this->import->updated_at = date('Y-m-d H:i:s', $timestamp + 1);
|
||||||
$result = $this->import->process();
|
$result = $this->import->process();
|
||||||
expect($result['data']['created'])->equals(1);
|
expect($result['created'])->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after() {
|
function _after() {
|
||||||
|
@@ -25,59 +25,86 @@ class MailChimpTest extends MailPoetTest {
|
|||||||
|
|
||||||
function testItFailsWithIncorrectAPIKey() {
|
function testItFailsWithIncorrectAPIKey() {
|
||||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$mailchimp = clone($this->mailchimp);
|
|
||||||
$mailchimp->api_key = false;
|
try {
|
||||||
$lists = $mailchimp->getLists();
|
$mailchimp = clone($this->mailchimp);
|
||||||
expect($lists['result'])->false();
|
$mailchimp->api_key = false;
|
||||||
expect($lists['errors'][0])->contains('API');
|
$lists = $mailchimp->getLists();
|
||||||
$subscribers = $mailchimp->getLists();
|
$this->fail('MailChimp getLists() did not throw an exception');
|
||||||
expect($subscribers['result'])->false();
|
} catch(\Exception $e) {
|
||||||
expect($subscribers['errors'][0])->contains('API');
|
expect($e->getMessage())->contains('Invalid API Key');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanGetLists() {
|
function testItCanGetLists() {
|
||||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$lists = $this->mailchimp->getLists();
|
try {
|
||||||
expect($lists['result'])->true();
|
$lists = $this->mailchimp->getLists();
|
||||||
expect(count($lists['data']))->equals(2);
|
} catch(\Exception $e) {
|
||||||
expect(isset($lists['data'][0]['id']))->true();
|
$this->fail('MailChimp getLists() threw an exception');
|
||||||
expect(isset($lists['data'][0]['name']))->true();
|
}
|
||||||
|
expect($lists)->count(2);
|
||||||
|
expect($lists[0]['id'])->notEmpty();
|
||||||
|
expect($lists[0]['name'])->notEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItFailsWithIncorrectLists() {
|
function testItFailsWithIncorrectLists() {
|
||||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$subscribers = $this->mailchimp->getSubscribers();
|
|
||||||
expect($subscribers['result'])->false();
|
try {
|
||||||
expect($subscribers['errors'][0])->contains('lists');
|
$subscribers = $this->mailchimp->getSubscribers();
|
||||||
$subscribers = $this->mailchimp->getSubscribers(array(12));
|
$this->fail('MailChimp getSubscribers() did not throw an exception');
|
||||||
expect($subscribers['result'])->false();
|
} catch(\Exception $e) {
|
||||||
expect($subscribers['errors'][0])->contains('lists');
|
expect($e->getMessage())->contains('Did not find any valid lists');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$subscribers = $this->mailchimp->getSubscribers(array(12));
|
||||||
|
$this->fail('MailChimp getSubscribers() did not throw an exception');
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
expect($e->getMessage())->contains('Did not find any valid lists');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCanGetSubscribers() {
|
function testItCanGetSubscribers() {
|
||||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$subscribers = $this->mailchimp->getSubscribers(array($this->lists[0]));
|
|
||||||
expect($subscribers['result'])->true();
|
try {
|
||||||
expect(isset($subscribers['data']['invalid']))->true();
|
$subscribers = $this->mailchimp->getSubscribers(array($this->lists[0]));
|
||||||
expect(isset($subscribers['data']['duplicate']))->true();
|
} catch(\Exception $e) {
|
||||||
expect(isset($subscribers['data']['header']))->true();
|
$this->fail('MailChimp getSubscribers() threw an exception');
|
||||||
expect(count($subscribers['data']['subscribers']))->equals(1);
|
}
|
||||||
expect($subscribers['data']['subscribersCount'])->equals(1);
|
|
||||||
|
expect($subscribers)->hasKey('invalid');
|
||||||
|
expect($subscribers)->hasKey('duplicate');
|
||||||
|
expect($subscribers['header'])->notEmpty();
|
||||||
|
expect($subscribers['subscribers'])->count(1);
|
||||||
|
expect($subscribers['subscribersCount'])->equals(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItFailsWhenListHeadersDontMatch() {
|
function testItFailsWhenListHeadersDontMatch() {
|
||||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$subscribers = $this->mailchimp->getSubscribers($this->lists);
|
|
||||||
expect($subscribers['result'])->false();
|
try {
|
||||||
expect($subscribers['errors'][0])->contains('header');
|
$subscribers = $this->mailchimp->getSubscribers($this->lists);
|
||||||
|
$this->fail('MailChimp getSubscribers() did not throw an exception');
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
expect($e->getMessage())
|
||||||
|
->contains('The selected lists do not have matching columns (headers)');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItFailsWhenSubscribersDataTooLarge() {
|
function testItFailsWhenSubscribersDataTooLarge() {
|
||||||
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
if(getenv('WP_TEST_ENABLE_NETWORK_TESTS') !== 'true') return;
|
||||||
$mailchimp = clone($this->mailchimp);
|
$mailchimp = clone($this->mailchimp);
|
||||||
$mailchimp->max_post_size = 10;
|
$mailchimp->max_post_size = 10;
|
||||||
$subscribers = $mailchimp->getSubscribers($this->lists);
|
|
||||||
expect($subscribers['result'])->false();
|
try {
|
||||||
expect($subscribers['errors'][0])->contains('large');
|
$subscribers = $mailchimp->getSubscribers($this->lists);
|
||||||
|
$this->fail('MailChimp getSubscribers() did not throw an exception');
|
||||||
|
} catch(\Exception $e) {
|
||||||
|
expect($e->getMessage())
|
||||||
|
->contains('The information received from MailChimp is too large for processing');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user