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..1a5ac80 100644 --- a/tests/simplenews.test +++ b/tests/simplenews.test @@ -1840,31 +1840,16 @@ class SimpleNewsI18nTestCase extends SimplenewsTestCase { } -/** - * Upgrade test from 6.x-1.x - */ -class SimpleNewsUpgradePath61TestCase extends UpgradePathTestCase { - - public static function getInfo() { - return array( - 'name' => 'Simplenews 6.x-1.x upgrade path', - 'description' => 'Simplenews 6.x-1.x upgrade path tests.', - 'group' => 'Simplenews', - ); - } +class SimpleNewsUpgradePathTestCase extends UpgradePathTestCase { public function setUp() { - // Path to the database dump files. - $this->databaseDumpFiles = array( - 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')); } - /** - * Test a successful upgrade. - */ - public function testSimplenewsUpgrade() { + public function prepareUpgradePath() { // Delete everything except taxnomy and simplenews from system to // prevent their update functions to be run. $this->uninstallModulesExcept(array('taxonomy', 'simplenews')); @@ -1876,9 +1861,9 @@ class SimpleNewsUpgradePath61TestCase extends UpgradePathTestCase { )) ->condition('name', 'simplenews') ->execute(); + } - $this->assertTrue($this->performUpgrade(), t('Upgraded successfully.')); - + public function assertUpgradePath() { // Enable simplenews. $edit = array( 'modules[Mail][simplenews][enable]' => 1, @@ -1892,19 +1877,55 @@ 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(), + 'taxonomy_vocabulary_1[und]' => 1, + ); + $this->drupalPost(NULL, $edit, ('Save')); + + // Send newsletter. + $this->clickLink(t('Newsletter')); + $this->drupalPost(NULL, array(), t('Submit')); + +// TODO: Maybe it would be bether to retreive the nid of the created node instead of hard code it. + $this->assertEqual(1, db_query('SELECT tid FROM {simplenews_newsletter} WHERE nid = :nid', array(':nid' => 2))->fetchField(), 'There is an issue associated to 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']); } } /** - * Upgrade test from 6.x-2.x + * Upgrade test from 6.x-1.x */ -class SimpleNewsUpgradePath62TestCase extends UpgradePathTestCase { +class SimpleNewsUpgradePath61TestCase extends SimpleNewsUpgradePathTestCase { public static function getInfo() { return array( - 'name' => 'Simplenews 6.x-2.x upgrade path', - 'description' => 'Simplenews 6.x-2.x upgrade path tests.', + 'name' => 'Simplenews 6.x-1.x upgrade path', + 'description' => 'Simplenews 6.x-1.x upgrade path tests.', 'group' => 'Simplenews', ); } @@ -1912,7 +1933,7 @@ class SimpleNewsUpgradePath62TestCase extends UpgradePathTestCase { public function setUp() { // Path to the database dump files. $this->databaseDumpFiles = array( - drupal_get_path('module', 'simplenews') . '/tests/d6_simplenews_62.php', + drupal_get_path('module', 'simplenews') . '/tests/d6_simplenews_61.php', ); parent::setUp(); } @@ -1921,33 +1942,48 @@ class SimpleNewsUpgradePath62TestCase extends UpgradePathTestCase { * Test a successful upgrade. */ public function testSimplenewsUpgrade() { - // Delete everything except taxnomy and simplenews from system to - // prevent their update functions to be run. - $this->uninstallModulesExcept(array('taxonomy', 'simplenews')); - - // Disable simplenews, the update hooks will be executed anyway. - db_update('system') - ->fields(array( - 'status' => 0, - )) - ->condition('name', 'simplenews') - ->execute(); + $this->prepareUpgradePath(); $this->assertTrue($this->performUpgrade(), t('Upgraded successfully.')); - // Enable simplenews. - $edit = array( - 'modules[Mail][simplenews][enable]' => 1, + $this->assertUpgradePath(); + } + +} + +/** + * Upgrade test from 6.x-2.x + */ +class SimpleNewsUpgradePath62TestCase extends SimpleNewsUpgradePathTestCase { + + public static function getInfo() { + return array( + 'name' => 'Simplenews 6.x-2.x upgrade path', + 'description' => 'Simplenews 6.x-2.x upgrade path tests.', + 'group' => 'Simplenews', ); - $this->drupalPost('admin/modules', $edit, t('Save configuration')); + } + public function setUp() { + // Path to the database dump files. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'simplenews') . '/tests/d6_simplenews_62.php', + ); + parent::setUp(); - $this->drupalGet('admin/config/services/simplenews'); - $this->assertText('Drupal 6 newsletter'); - $this->assertText('Test'); + // Use the test mail class instead of the default mail handler class. + $this->variable_set('mail_system', array('default-system' => 'TestingMailSystem')); + } - $this->drupalGet('admin/people/simplenews'); - $this->assertText('another@example.org'); + /** + * Test a successful upgrade. + */ + public function testSimplenewsUpgrade() { + $this->prepareUpgradePath(); + + $this->assertTrue($this->performUpgrade(), t('Upgraded successfully.')); + + $this->assertUpgradePath(); } }