Updated export unit test

This commit is contained in:
Jonathan Labreuille
2016-08-17 12:51:50 +02:00
parent 876e386966
commit 916ae97f73
2 changed files with 28 additions and 13 deletions

View File

@ -27,7 +27,7 @@ class ImportExport extends APIEndpoint {
$mailChimp = new MailChimp($data['api_key']);
$subscribers = $mailChimp->getSubscribers($data['lists']);
return $this->successResponse($subscribers);
} catch(\Exception $e) {
} catch(\Exception $e) {
return $this->errorResponse(array(
$e->getCode() => $e->getMessage()
));

View File

@ -222,21 +222,36 @@ class ExportTest extends MailPoetTest {
}
function testItRequiresWritableExportFile() {
$this->export->export_path = '/fake_folder';
$result = $this->export->process();
expect($result['errors'][0])
->equals("Couldn't save export file on the server");
try {
$this->export->export_path = '/fake_folder';
$this->export->process();
$this->fail('Export did not throw an exception');
} catch(\Exception $e) {
expect($e->getMessage())
->equals("Couldn't save export file on the server");
}
}
function testItCanProcess() {
$this->export->export_file = $this->export->getExportFile('csv');
$this->export->export_format_option = 'csv';
$result = $this->export->process();
expect($result['result'])->true();
$this->export->export_file = $this->export->getExportFile('xlsx');
$this->export->export_format_option = 'xlsx';
$result = $this->export->process();
expect($result['result'])->true();
try {
$this->export->export_file = $this->export->getExportFile('csv');
$this->export->export_format_option = 'csv';
$result = $this->export->process();
} catch(\Exception $e) {
$this->fail('Export to .csv process threw an exception');
}
expect($result['totalExported'])->equals(3);
expect($result['exportFileURL'])->notEmpty();
try {
$this->export->export_file = $this->export->getExportFile('xlsx');
$this->export->export_format_option = 'xlsx';
$result = $this->export->process();
} catch(\Exception $e) {
$this->fail('Export to .xlsx process threw an exception');
}
expect($result['totalExported'])->equals(3);
expect($result['exportFileURL'])->notEmpty();
}
function _after() {