diff --git a/message_subscribe.test b/message_subscribe.test index dc04f6a..1fa088c 100644 --- a/message_subscribe.test +++ b/message_subscribe.test @@ -471,4 +471,47 @@ class MessageSubscribeQueueTest extends DrupalWebTestCase { $this->cronRun(); $this->assertEqual($queue->numberOfItems(), 0, 'Message item 2 processed by cron.'); } + + /** + * Test that if we get a list of user IDs directly from the implementing module, + * the messages are sent respecting the range value. + * + * @see https://drupal.org/node/2256899 + */ + function testProvidedUserIdsAreSplitAccordingToRangeValue() { + + $user1 = $this->drupalCreateUser(); + $user2 = $this->drupalCreateUser(); + $user3 = $this->drupalCreateUser(); + + $message = message_create('foo', array()); + + $subscribe_options = array( + 'uids' => array( + $user1->uid => array('notifiers' => array('email')), + $user2->uid => array('notifiers' => array('email')), + $user3->uid => array('notifiers' => array('email')), + ), + 'skip context' => TRUE, + 'range' => 1 + ); + + message_subscribe_send_message('node', $this->node, $message, array(), $subscribe_options); + + // Run cron + $this->cronRun(); + + $captured_emails = variable_get('drupal_test_email_collector', array()); + $this->assertEqual(count($subscribe_options['uids']), count($captured_emails), 'The amount of recipients is the same as amount of emails captured.'); + + $recipients = array(); + foreach ($captured_emails as $captured_email) { + $recipients[] = $captured_email['to']; + } + + $this->assertTrue(in_array($user1->mail, $recipients), 'user1 mail is in the recipient list'); + $this->assertTrue(in_array($user2->mail, $recipients), 'user2 mail is in the recipient list'); + $this->assertTrue(in_array($user3->mail, $recipients), 'user3 mail is in the recipient list'); + } + }