newsletter.test 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /**
  3. * @file
  4. * Tests for Newsletter module.
  5. */
  6. /**
  7. * The NewsletterTemplateTestCase tests CUD actions through Web UI
  8. * for newsletter templates.
  9. */
  10. class NewsletterTemplateTestCase extends TaxonomyWebTestCase {
  11. protected $privileged_user;
  12. public static function getInfo() {
  13. return array(
  14. 'name' => 'Newsletter Template',
  15. 'description' => 'Ensure that template CUD is operating properly.',
  16. 'group' => 'Newsletter',
  17. );
  18. }
  19. public function setUp() {
  20. parent::setUp(array('taxonomy', 'entityreference', 'token', 'newsletter'));
  21. $this->privileged_user = $this->drupalCreateUser(array(
  22. 'access administration pages',
  23. 'administer newsletters',
  24. 'subscribe newsletters',
  25. 'access newsletter statistics',
  26. ));
  27. $this->drupalLogin($this->privileged_user);
  28. }
  29. public function testNewsletterTemplateCreate() {
  30. // Create a vocabulary with a term in it first.
  31. $vocabulary = $this->createVocabulary();
  32. $term = $this->createTerm($vocabulary);
  33. // Create a template.
  34. $create = array();
  35. $create['subject'] = $this->randomName(8);
  36. $create['field_newsletter_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomString(1000);
  37. $create['field_' . $vocabulary->machine_name . '[' . LANGUAGE_NONE . '][]'] = $term->tid;
  38. $this->drupalPost('admin/config/media/newsletter/templates/mail/add', $create, t('Save'));
  39. $this->assertText(t('Template updated successfully'));
  40. }
  41. public function testNewsletterTemplateEdit() {
  42. // Create a vocabulary with a term in it.
  43. $vocabulary = $this->createVocabulary();
  44. $term = $this->createTerm($vocabulary);
  45. // Edit the Default template.
  46. $edit = array();
  47. $edit['subject'] = $this->randomName(8);
  48. $edit['field_newsletter_body[' . LANGUAGE_NONE . '][0][value]'] = $this->randomString(1000);
  49. $edit['field_' . $vocabulary->machine_name . '[' . LANGUAGE_NONE . '][]'] = $term->tid;
  50. $edit['exposed'] = 1;
  51. $this->drupalPost('admin/config/media/newsletter/templates/edit/4', $edit, t('Update'));
  52. $this->assertText(t('Template updated successfully'));
  53. }
  54. public function testNewsletterTemplateDelete() {
  55. // Delete the Default template.
  56. $this->drupalPost('admin/config/media/newsletter/templates/delete/4', NULL, t('Confirm'));
  57. $this->assertText(t('Template deleted successfully'));
  58. }
  59. public function testNewsletterTemplateDeleteMass() {
  60. // Create some templates.
  61. for ($i = 5; $i < 10; $i++) {
  62. $this->testNewsletterTemplateCreate();
  63. $delete["template[$i]"] = $i;
  64. }
  65. $delete['operation'] = 'delete';
  66. $this->drupalPost('admin/config/media/newsletter/templates', $delete, t('Update'));
  67. $this->drupalPost(NULL, NULL, t('Confirm'));
  68. $this->assertText(t('Templates deleted successfully'));
  69. }
  70. }
  71. /**
  72. * The NewsletterListTestCase tests CUD actions through Web UI
  73. * for newsletter lists.
  74. */
  75. class NewsletterListTestCase extends DrupalWebTestCase {
  76. protected $privileged_user;
  77. public static function getInfo() {
  78. return array(
  79. 'name' => 'Newsletter List',
  80. 'description' => 'Ensure that list CUD is operating properly.',
  81. 'group' => 'Newsletter',
  82. );
  83. }
  84. public function setUp() {
  85. parent::setUp(array('taxonomy', 'entityreference', 'token', 'newsletter'));
  86. $this->privileged_user = $this->drupalCreateUser(array(
  87. 'access administration pages',
  88. 'administer newsletters',
  89. 'subscribe newsletters',
  90. 'access newsletter statistics',
  91. ));
  92. $this->drupalLogin($this->privileged_user);
  93. }
  94. public function testNewsletterListCreate() {
  95. $create = array();
  96. $create['title'] = $this->randomName(8);
  97. $create['field_list_description[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName(15);
  98. $create['field_newsletter_categories[' . LANGUAGE_NONE . ']'] = $this->randomName(8);
  99. $create['field_newsletter_template[' . LANGUAGE_NONE . ']'] = 4;
  100. $create['send_rate'] = 'Daily';
  101. $this->drupalPost('admin/config/media/newsletter/lists/add', $create, t('Save'));
  102. $this->assertText(t('List updated successfully'));
  103. }
  104. public function testNewsletterListEdit() {
  105. $edit = array();
  106. $edit['title'] = $this->randomName(8);
  107. $edit['field_list_description[' . LANGUAGE_NONE . '][0][value]'] = $this->randomName(15);
  108. $edit['field_newsletter_categories[' . LANGUAGE_NONE . ']'] = $this->randomName(8);
  109. $edit['field_newsletter_template[' . LANGUAGE_NONE . ']'] = 4;
  110. $edit['send_rate'] = 'Custom';
  111. $edit['send_rate_custom'] = rand(0 , 10);
  112. $this->drupalPost('admin/config/media/newsletter/lists/edit/1', $edit, t('Update'));
  113. $this->assertText(t('List updated successfully'));
  114. }
  115. public function testNewsletterListDelete() {
  116. // Delete the Default list.
  117. $this->drupalPost('admin/config/media/newsletter/lists/delete/1', NULL, t('Confirm'));
  118. $this->assertText(t('List deleted successfully'));
  119. }
  120. public function testNewsletterListDeleteMass() {
  121. // Create some lists.
  122. for ($i = 2; $i < 7; $i++) {
  123. $this->testNewsletterListCreate();
  124. $delete["list[$i]"] = $i;
  125. }
  126. $delete['operation'] = 'delete';
  127. $this->drupalPost('admin/config/media/newsletter/lists', $delete, t('Update'));
  128. $this->drupalPost(NULL, NULL, t('Confirm'));
  129. $this->assertText(t('Lists deleted successfully'));
  130. }
  131. }