mandrill_template.test in Mandrill 7.2
Test class and methods for the Mandrill Template module.
File
modules/mandrill_template/tests/mandrill_template.testView source
<?php
/**
* @file
* Test class and methods for the Mandrill Template module.
*/
class MandrillTemplateTestCase extends DrupalWebTestCase {
/**
* Returns info displayed in the test interface.
*
* @return array
* Formatted as specified by simpletest.
*/
public static function getInfo() {
// Note: getInfo() strings are not translated with t().
return array(
'name' => 'Mandrill Template Tests',
'description' => 'Tests Mandrill Template functionality.',
'group' => 'Mandrill',
);
}
/**
* Pre-test setup function.
*
* Enables dependencies.
* Sets the mandrill_api_key variable to the test key.
*/
protected function setUp() {
// Use a profile that contains required modules:
$prof = drupal_get_profile();
$this->profile = $prof;
// Enable modules required for the test.
$enabled_modules = array(
'libraries',
'mandrill',
'mandrill_template',
'entity',
);
parent::setUp($enabled_modules);
variable_set('mandrill_api_classname', 'DrupalMandrillTest');
variable_set('mandrill_api_key', 'MANDRILL_TEST_API_KEY');
}
/**
* Post-test function.
*
* Sets test mode to FALSE.
*/
protected function tearDown() {
parent::tearDown();
variable_del('mandrill_api_classname');
variable_del('mandrill_api_key');
}
/**
* Test sending a templated message to multiple recipients.
*/
public function testSendTemplatedMessage() {
$to = 'Recipient One <recipient.one@example.com>,' . 'Recipient Two <recipient.two@example.com>,' . 'Recipient Three <recipient.three@example.com>';
$message = $this
->getMessageTestData();
$message['to'] = $to;
$template_id = 'Test Template';
$template_content = array(
'name' => 'Recipient',
);
$response = mandrill_template_sender($message, $template_id, $template_content);
$this
->assertNotNull($response, 'Tested response from sending templated message.');
if (isset($response['status'])) {
$this
->assertNotEqual($response['status'], 'error', 'Tested response status: ' . $response['status'] . ', ' . $response['message']);
}
}
/**
* Test sending a templated message using an invalid template.
*/
public function testSendTemplatedMessageInvalidTemplate() {
$to = 'Recipient One <recipient.one@example.com>';
$message = $this
->getMessageTestData();
$message['to'] = $to;
$template_id = 'Invalid Template';
$template_content = array(
'name' => 'Recipient',
);
$response = mandrill_template_sender($message, $template_id, $template_content);
$this
->assertNotNull($response, 'Tested response from sending invalid templated message.');
if (isset($response['status'])) {
$this
->assertEqual($response['status'], 'error', 'Tested response status: ' . $response['status'] . ', ' . $response['message']);
}
}
/**
* Gets message data used in tests.
*/
protected function getMessageTestData() {
$message = array(
'id' => 1,
'body' => '<p>Mail content</p>',
'subject' => 'Mail Subject',
'from_email' => 'sender@example.com',
'from_name' => 'Test Sender',
);
return $message;
}
}
Classes
Name | Description |
---|---|
MandrillTemplateTestCase | @file Test class and methods for the Mandrill Template module. |