function NotificationsAnonymousTests::testAnonymousSubscriptions in Notifications 7
Same name and namespace in other branches
- 6.4 tests/notifications_anonymous.test \NotificationsAnonymousTests::testAnonymousSubscriptions()
File
- tests/
notifications_anonymous.test, line 27
Class
Code
function testAnonymousSubscriptions() {
// Create a new content-type for subscribing to
$ctype = $this
->drupalCreateContentType();
// Enable this content type for thread/author/type subscriptions
variable_set('notifications_content_type', array(
'thread',
'nodetype',
'author',
));
// Enable all UI pages
$this
->enableUIPages();
$this
->enableSubscriptionTypes();
// Create user and email address
$anonymous = drupal_anonymous_user();
$mail = $this
->createMail();
// Create a content type subscription
$subscription = $this
->anonymousCreateSubscription($mail, 'nodetype', array(
'type' => $ctype->type,
));
// Create a node and a comment and check the subscription has worked
$author = $this
->drupalCreateUser(array(
"create {$ctype->type} content",
'post comments',
));
$node = $this
->drupalCreateNode(array(
'type' => $ctype->type,
'uid' => $author->uid,
));
$comment = $this
->drupalCreateComment($node);
// There should be two queued notifications that will be gone after processing
$this
->assertUserRows('notifications_queue', 2, 0);
$this
->notificationsProcessQueue(2, 0);
// We should have two messages sent and queued using mail
$messages = messaging_store()
->get_messages(array(
'uid' => 0,
'method' => 'mail',
'queue' => 1,
), array(
'sent',
));
$this
->assertEqual(count($messages), 2, "Retrieved 2 queued messages from store.");
$message1 = array_shift($messages);
$message2 = array_shift($messages);
$this
->assertTrue(strpos($message1->body, $node->body), "One message sent for the node post.");
$this
->assertTrue(strpos($message2->body, $comment->subject), "One message sent for the comment.");
// Unsubscribe with a signed link
$link = notifications_subscription_get_link('unsubscribe', $subscription, array(
'absolute' => TRUE,
'destination' => '',
));
$this
->drupalGet(url($link['href'], $link['options']));
$this
->assertText('Are you sure you want to delete this subscription?');
$this
->drupalPost(NULL, array(), t('Unsubscribe'));
$this
->assertText('Your subscription has been removed.');
}