summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVladimir Mitrovic2012-10-05 07:25:59 (GMT)
committer Vladimir Mitrovic2012-10-05 07:25:59 (GMT)
commit13bef60e17a9580dacc3460fd64d439796f812ea (patch)
tree6b20f426773c653687b38feaa8cfc82358688989
parent607066efcc677cdaa61299b61ae03ed0311573ba (diff)
Unsubscribe page module - tests.
-rw-r--r--includes/salsa_entity.mock.inc83
-rw-r--r--salsa_unsubscribe_page/salsa_unsubscribe_page.info3
-rw-r--r--salsa_unsubscribe_page/salsa_unsubscribe_page.module2
-rw-r--r--salsa_unsubscribe_page/tests/salsa_unsubscribe_page.test194
4 files changed, 275 insertions, 7 deletions
diff --git a/includes/salsa_entity.mock.inc b/includes/salsa_entity.mock.inc
index 2de86f0..809ab22 100644
--- a/includes/salsa_entity.mock.inc
+++ b/includes/salsa_entity.mock.inc
@@ -115,7 +115,7 @@ EOF;
<Automatically_add_to_Groups>false</Automatically_add_to_Groups>
<PreInterest_Text>Pre-tag text - Text to display before the checkboxes for optional tags</PreInterest_Text>
<interest_KEYS/>
- <tag_KEYS>0,,173908,173912,173909</tag_KEYS>
+ <tag_KEYS>1,2,3</tag_KEYS>
<event_KEY>0</event_KEY>
<Request_Volunteer_Availability_BOOLVALUE>false</Request_Volunteer_Availability_BOOLVALUE>
<Request_Volunteer_Availability>false</Request_Volunteer_Availability>
@@ -149,7 +149,7 @@ EOF;
<organization_KEY>11111</organization_KEY>
<chapter_KEY>0</chapter_KEY>
<Last_Modified>Fri Aug 31 2012 00:00:00 GMT-0400 (EDT)</Last_Modified>
- <Date_Created>Fri Aug 31 2012 00:00:00 GMT-0400 (EDT))</Date_Created>
+ <Date_Created>Fri Aug 31 2012 00:00:00 GMT-0400 (EDT)</Date_Created>
<Group_Name>Group 1</Group_Name>
<Reference_Name/>
<parent_KEY/>
@@ -338,6 +338,38 @@ EOF;
</data>
EOF;
}
+ elseif ($query[0] == 'object=tag_data') {
+ $response = <<<EOF
+<?xml version="1.0"?>
+<data organization_KEY="11111">
+ <tag_data>
+ <item>
+ <tag_data_KEY>1</tag_data_KEY>
+ <organization_KEY>11111</organization_KEY>
+ <chapter_KEY>0</chapter_KEY>
+ <Last_Modified>Fri Aug 31 2012 00:00:00 GMT-0400 (EDT)</Last_Modified>
+ <database_table_KEY>142</database_table_KEY>
+ <table_key>999</table_key>
+ <tag_KEY>1</tag_KEY>
+ <key>1</key>
+ <object>tag_data</object>
+ </item>
+ <item>
+ <tag_data_KEY>2</tag_data_KEY>
+ <organization_KEY>11111</organization_KEY>
+ <chapter_KEY>0</chapter_KEY>
+ <Last_Modified>Fri Aug 31 2012 00:00:00 GMT-0400 (EDT)</Last_Modified>
+ <database_table_KEY>142</database_table_KEY>
+ <table_key>999</table_key>
+ <tag_KEY>2</tag_KEY>
+ <key>2</key>
+ <object>tag_data</object>
+ </item>
+ <count>2</count>
+ </tag_data>
+</data>
+EOF;
+ }
elseif ($query[0] == 'object=donate_page') {
$response = <<<EOF
<?xml version="1.0"?>
@@ -2272,6 +2304,50 @@ EOF;
</data>
EOF;
}
+ elseif ($script == '/api/describe2.sjs' && $query[0] == 'object=tag_data') {
+ $response = <<<EOF
+<?xml version="1.0"?>
+<data organization_KEY="11111">
+ <tag_data>
+ <item>
+ <name>tag_data_KEY</name>
+ <nullable>1</nullable>
+ <type>int</type>
+ <defaultValue/>
+ <label>tag data KEY</label>
+ </item>
+ <item>
+ <name>Last_Modified</name>
+ <nullable>1</nullable>
+ <type>timestamp</type>
+ <defaultValue>CURRENT_TIMESTAMP</defaultValue>
+ <label>Last Modified</label>
+ </item>
+ <item>
+ <name>database_table_KEY</name>
+ <nullable>0</nullable>
+ <type>int</type>
+ <defaultValue/>
+ <label>database table KEY</label>
+ </item>
+ <item>
+ <name>table_key</name>
+ <nullable>0</nullable>
+ <type>int</type>
+ <defaultValue/>
+ <label>table key</label>
+ </item>
+ <item>
+ <name>tag_KEY</name>
+ <nullable>0</nullable>
+ <type>int</type>
+ <defaultValue/>
+ <label>tag KEY</label>
+ </item>
+ </tag_data>
+</data>
+EOF;
+ }
elseif ($script == '/api/describe2.sjs' && $query[0] == 'object=supporter_groups') {
$response = <<<EOF
<?xml version="1.0"?>
@@ -2839,10 +2915,7 @@ EOF;
<data organization_KEY="11111">
<$object>
<item>
- <organization_KEY>11111</organization_KEY>
<chapter_KEY/>
- <Last_Modified>Mon May 21 2012 11:56:46 GMT-0400 (EDT)</Last_Modified>
- <Date_Created>Mon May 20 2012 16:48:23 GMT-0400 (EDT)</Date_Created>
EOF;
foreach ($saved[$object][$key] as $name => $value) {
diff --git a/salsa_unsubscribe_page/salsa_unsubscribe_page.info b/salsa_unsubscribe_page/salsa_unsubscribe_page.info
index c6e71ef..e6835a5 100644
--- a/salsa_unsubscribe_page/salsa_unsubscribe_page.info
+++ b/salsa_unsubscribe_page/salsa_unsubscribe_page.info
@@ -4,4 +4,5 @@ package = Salsa
core = 7.x
dependencies[] = salsa_entity
-files[] = includes/salsa_unsubscribe_page.entity.inc \ No newline at end of file
+files[] = includes/salsa_unsubscribe_page.entity.inc
+files[] = tests/salsa_unsubscribe_page.test
diff --git a/salsa_unsubscribe_page/salsa_unsubscribe_page.module b/salsa_unsubscribe_page/salsa_unsubscribe_page.module
index 696841e..6304172 100644
--- a/salsa_unsubscribe_page/salsa_unsubscribe_page.module
+++ b/salsa_unsubscribe_page/salsa_unsubscribe_page.module
@@ -215,7 +215,7 @@ function salsa_unsubscribe_page_form_validate($form, &$form_state) {
else {
// Is subscribed?
$supporter = entity_load_single('salsa_supporter', $form_state['user']->field_salsa_supporter_key[LANGUAGE_NONE][0]['value']);
- if ($supporter->Receive_Email != 1) {
+ if (isset($supporter->Receive_Email) && $supporter->Receive_Email != 1) {
form_set_error('Email', t('No supporters with the specified email address were subscribed.'));
}
}
diff --git a/salsa_unsubscribe_page/tests/salsa_unsubscribe_page.test b/salsa_unsubscribe_page/tests/salsa_unsubscribe_page.test
new file mode 100644
index 0000000..839af47
--- /dev/null
+++ b/salsa_unsubscribe_page/tests/salsa_unsubscribe_page.test
@@ -0,0 +1,194 @@
+<?php
+
+/**
+ * @file
+ * Salsa API test methods.
+ */
+
+
+class SalsaUnsubscribePageTestCase extends DrupalWebTestCase {
+ public function setUp() {
+ parent::setUp(
+ 'entity',
+ 'salsa_entity',
+ 'salsa_api',
+ 'salsa_profile',
+ 'salsa_signup_page',
+ 'salsa_unsubscribe_page'
+ );
+
+ variable_set('salsa_api_class', 'SalsaAPIMock');
+ variable_set('salsa_entity_enabled_objects', array(
+ 'supporter' => 'supporter',
+ 'supporter_groups' => 'supporter_groups',
+ 'signup_page' => 'signup_page',
+ 'groups' => 'groups',
+ 'tag' => 'tag',
+ 'tag_data' => 'tag_data',
+ 'database_table' => 'database_table',
+ 'custom_column' => 'custom_column',
+ 'unsubscribe_page' => 'unsubscribe_page',
+ 'unsubscribe' => 'unsubscribe',
+ ));
+
+ drupal_flush_all_caches();
+ }
+}
+
+class SalsaUnsubscribePageWhenNotLoggedInTestCase extends SalsaUnsubscribePageTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => t('Unsubscribe page - not logged in.'),
+ 'description' => t('This test covers the unsubscribe process when the user is not logged in.'),
+ 'group' => t('Salsa API'),
+ );
+ }
+
+ /**
+ * Check if the supporter data loaded correctly.
+ */
+ function testUnsubscribePageNotLoggedIn() {
+ // Create an admin user.
+ $permissions = array(
+ 'access administration pages',
+ 'administer users',
+ 'administer salsa',
+ 'administer permissions',
+ );
+
+ $admin_user = $this->drupalCreateUser($permissions);
+ $this->drupalLogin($admin_user);
+
+ // Select signup page to be integrated with Drupal registration form.
+ $signup_page_settings = array(
+ 'signup_page_registration_form' => 1,
+ );
+ $this->drupalPost('admin/config/services/salsa/signup_page', $signup_page_settings, t('Save configuration'));
+
+ // Select custom field to store Drupal UID.
+ $profile_settings = array(
+ 'salsa_profile_custom_field' => 'uid',
+ );
+ $this->drupalPost('admin/config/services/salsa/profile', $profile_settings, t('Save configuration'));
+
+ // Disable email verification.
+ $verification_settings = array(
+ 'user_register' => 1,
+ 'user_email_verification' => FALSE,
+ );
+ $this->drupalPost('admin/config/people/accounts', $verification_settings, t('Save configuration'));
+
+ // Set perimissions.
+ $permissions = array(
+ '1[view salsa_unsubscribe_page]' => TRUE,
+ '2[view salsa_unsubscribe_page]' => TRUE,
+ );
+ $this->drupalPost('admin/people/permissions', $permissions, t('Save permissions'));
+ $this->drupalLogout();
+
+ // Register a new user.
+ $registration_form_fields = array(
+ 'name' => 'signup',
+ 'mail' => 'example@example.com',
+ 'pass[pass1]' => '123456789',
+ 'pass[pass2]' => '123456789',
+ 'Supporter_Info[First_Name]' => 'First Name',
+ 'Supporter_Info[Last_Name]' => 'Last Name',
+ 'Supporter_Info[Zip]' => 1000,
+ 'Supporter_Info[Receive_Email]' => 1,
+ );
+ $this->drupalPost('user/register', $registration_form_fields, t('Create new account'));
+ $this->drupalLogout();
+
+ // Verify email address.
+ $unsubscribe = array('Email' => 'example@example.com');
+ $this->drupalPost('salsa/unsubscribe_page/1', $unsubscribe, t('Verify My E-mail Address'));
+
+ // Get mails.
+ $mails = $this->drupalGetMails();
+
+ // Permanently unsubscribe user from all lists.
+ $unsubscribe = array('remove' => TRUE);
+ $this->drupalPost($mails[1]['params']['unsubscribe_link'], $unsubscribe, t('Unsubscribe'));
+
+ // Check that Receive_Email property is -3.
+ $saved = variable_get('salsa_entity_mock_saved', array());
+ $supporter_KEY = user_load_by_mail($registration_form_fields['mail'])->field_salsa_supporter_key[LANGUAGE_NONE][0]['value'];
+ $this->assertTrue($saved['supporter'][$supporter_KEY]['Receive_Email'], -3, t('The user is permanently unsubscribed.'));
+ }
+}
+
+class SalsaUnsubscribePageWhenLoggedInTestCase extends SalsaUnsubscribePageTestCase {
+ public static function getInfo() {
+ return array(
+ 'name' => t('Unsubscribe page - logged in.'),
+ 'description' => t('This test covers the unsubscribe process when the user is logged in.'),
+ 'group' => t('Salsa API'),
+ );
+ }
+
+ /**
+ * Check if the supporter data loaded correctly.
+ */
+ function testUnsubscribePageWhenLoggedIn() {
+ // Create an admin user.
+ $permissions = array(
+ 'access administration pages',
+ 'administer users',
+ 'administer salsa',
+ 'administer permissions',
+ );
+
+ $admin_user = $this->drupalCreateUser($permissions);
+ $this->drupalLogin($admin_user);
+
+ // Select signup page to be integrated with Drupal registration form.
+ $signup_page_settings = array(
+ 'signup_page_registration_form' => 1,
+ );
+ $this->drupalPost('admin/config/services/salsa/signup_page', $signup_page_settings, t('Save configuration'));
+
+ // Select custom field to store Drupal UID.
+ $profile_settings = array(
+ 'salsa_profile_custom_field' => 'uid',
+ );
+ $this->drupalPost('admin/config/services/salsa/profile', $profile_settings, t('Save configuration'));
+
+ // Disable email verification.
+ $verification_settings = array(
+ 'user_register' => 1,
+ 'user_email_verification' => FALSE,
+ );
+ $this->drupalPost('admin/config/people/accounts', $verification_settings, t('Save configuration'));
+
+ // Set perimissions.
+ $permissions = array(
+ '1[view salsa_unsubscribe_page]' => TRUE,
+ '2[view salsa_unsubscribe_page]' => TRUE,
+ );
+ $this->drupalPost('admin/people/permissions', $permissions, t('Save permissions'));
+ $this->drupalLogout();
+
+ // Register a new user.
+ $registration_form_fields = array(
+ 'name' => 'signup',
+ 'mail' => 'example@example.com',
+ 'pass[pass1]' => '123456789',
+ 'pass[pass2]' => '123456789',
+ 'Supporter_Info[First_Name]' => 'First Name',
+ 'Supporter_Info[Last_Name]' => 'Last Name',
+ 'Supporter_Info[Zip]' => 1000,
+ 'Supporter_Info[Receive_Email]' => 1,
+ );
+ $this->drupalPost('user/register', $registration_form_fields, t('Create new account'));
+
+ // Permanently unsubscribe user from all lists.
+ $unsubscribe = array('remove' => TRUE);
+ $this->drupalPost('salsa/unsubscribe_page/1', $unsubscribe, t('Unsubscribe'));
+
+ // Check that Receive_Email property is -3.
+ $saved = variable_get('salsa_entity_mock_saved', array());
+ $supporter_KEY = user_load_by_mail($registration_form_fields['mail'])->field_salsa_supporter_key[LANGUAGE_NONE][0]['value'];
+ $this->assertTrue($saved['supporter'][$supporter_KEY]['Receive_Email'], -3, t('The user is permanently unsubscribed.'));
+ }
+}