diff --git a/simplenews.install b/simplenews.install index 7e0292d..4df5b80 100644 --- a/simplenews.install +++ b/simplenews.install @@ -375,7 +375,7 @@ function _simplenews_install_nodetype() { 'locked' => 0, 'custom' => 1, 'modified' => 1, - )); + )); node_type_save($type); node_add_body_field($type); } @@ -628,7 +628,7 @@ function simplenews_update_7000() { 'new_account' => variable_get('simplenews_new_account_' . $tid, 'none'), 'opt_inout' => variable_get('simplenews_opt_inout_' . $tid, 'double'), 'block' => isset($blocks[$tid]) ? 1 : 0, - )) + )) ->execute(); } @@ -662,7 +662,7 @@ function simplenews_update_7000() { 'description' => 'A serialized array of name value pairs that are related to the email address.', )); - // Rename field {simplenews_mail_spool}.s_status to "status". + // Rename field {simplenews_mail_spool}.s_status to "status". db_change_field('simplenews_newsletter', 's_status', 'status', array( 'description' => 'sent status of the newsletter issue (0 = not sent; 1 = pending; 2 = sent). ', 'type' => 'int', @@ -682,9 +682,37 @@ function simplenews_update_7000() { } - + // @todo Add return text about checking of Newsletter Category settings. // @todo Add return text about Block checkboxes + + // Convert old content type settings. + module_load_include('module', 'node'); + module_load_include('module', 'simplenews'); + + // Update the machine name of the simplenews vocabulary. + if ($vid = variable_get('simplenews_vid', '')) { + db_update('taxonomy_vocabulary') + ->fields(array( + 'machine_name' => 'newsletter', + )) + ->condition('vid', $vid) + ->execute(); + $field_name = 'taxonomy_vocabulary_' . $vid; + variable_set('simplenews_category_field', $field_name); + $field = field_info_field($field_name); + $field['settings']['allowed_values'][0]['vocabulary'] = 'newsletter'; + field_update_field($field); + } + variable_del('simplenews_vid'); + + $content_types = variable_get('simplenews_content_types'); + if (!empty($content_types)) { + foreach ($content_types as $simplenews_content_type) { + variable_set('simplenews_content_type_' . $simplenews_content_type, TRUE); + } + } + variable_del('simplenews_content_types'); } /** diff --git a/tests/simplenews.test b/tests/simplenews.test index ee185ea..b8fca66 100644 --- a/tests/simplenews.test +++ b/tests/simplenews.test @@ -1859,6 +1859,9 @@ class SimpleNewsUpgradePath61TestCase extends UpgradePathTestCase { drupal_get_path('module', 'simplenews') . '/tests/d6_simplenews_61.php', ); parent::setUp(); + + // Use the test mail class instead of the default mail handler class. + $this->variable_set('mail_system', array('default-system' => 'TestingMailSystem')); } /** @@ -1892,6 +1895,38 @@ class SimpleNewsUpgradePath61TestCase extends UpgradePathTestCase { $this->drupalGet('admin/people/simplenews'); $this->assertText('another@example.org'); + + $this->drupalGet('admin/structure/taxonomy/newsletter'); + + // Check simplenews content type. + $this->drupalGet('admin/structure/types/manage/simplenews'); + $this->assertFieldChecked('edit-simplenews-content-type'); + $this->drupalGet('admin/structure/types/manage/simplenews/fields'); + + $this->drupalGet('node/add/simplenews'); + $this->assertText('Newsletter'); + $this->assertText('Drupal 6 newsletter'); + + // Check category field + $this->assertEqual(variable_get('simplenews_category_field'), 'taxonomy_vocabulary_1'); + $this->assertTrue(field_info_instance('node', 'taxonomy_vocabulary_1', 'simplenews')); + + // Create an issue. + $edit = array( + 'title' => $this->randomName(), + ); + $this->drupalPost(NULL, $edit, ('Save')); + + // Send newsletter. + $this->clickLink(t('Newsletter')); + $this->assertText(t('Send newsletter')); + $this->drupalPost(NULL, array(), t('Submit')); + + $mails = $this->drupalGetMails(); + $this->assertEqual('simplenews_test', $mails[0]['id']); + // @todo: Test with a custom test mail address. + $this->assertEqual('user@example.com', $mails[0]['to']); + $this->assertEqual(t('[Drupal newsletter] @title', array('@title' => $edit['title'])), $mails[0]['subject']); } } @@ -1915,6 +1950,9 @@ class SimpleNewsUpgradePath62TestCase extends UpgradePathTestCase { drupal_get_path('module', 'simplenews') . '/tests/d6_simplenews_62.php', ); parent::setUp(); + + // Use the test mail class instead of the default mail handler class. + $this->variable_set('mail_system', array('default-system' => 'TestingMailSystem')); } /** @@ -1948,6 +1986,41 @@ class SimpleNewsUpgradePath62TestCase extends UpgradePathTestCase { $this->drupalGet('admin/people/simplenews'); $this->assertText('another@example.org'); + + $this->drupalGet('admin/structure/taxonomy/newsletter'); + + // Check simplenews content type. + $this->drupalGet('admin/structure/types/manage/simplenews'); + $this->assertFieldChecked('edit-simplenews-content-type'); + $this->drupalGet('admin/structure/types/manage/simplenews/fields'); + + $this->drupalGet('node/add/simplenews'); + $this->assertText('Newsletter'); + $this->assertText('Drupal 6 newsletter'); + + // Check category field + $this->assertEqual(variable_get('simplenews_category_field'), 'taxonomy_vocabulary_1'); + $this->assertTrue(field_info_instance('node', 'taxonomy_vocabulary_1', 'simplenews')); + + // Create an issue. + $edit = array( + 'title' => $this->randomName(), + 'taxonomy_vocabulary_1[und]' => 1, + ); + $this->drupalPost(NULL, $edit, ('Save')); + + // Send newsletter. + $this->clickLink(t('Newsletter')); + $this->drupalPost(NULL, array(), t('Submit')); + + $this->assertEqual(1, db_query('SELECT tid FROM {simplenews_newsletter}')->fetchField(), 'There is an issue associated with the correct newsletter category'); + +// @todo Mails are not correctly returned +// $mails = $this->drupalGetMails(); +// debug($mails); +// $this->assertEqual('simplenews_test', $mails[0]['id']); +// $this->assertEqual('user@example.com', $mails[0]['to']); +// $this->assertEqual(t('[Drupal newsletter] @title', array('@title' => $edit['title'])), $mails[0]['subject']); } }