View source
<?php
class NotificationsUserTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Notifications User',
'description' => 'Verifies that users can subscribe to and be notified of posts by a given author of a given content type.',
'group' => 'Notifications',
);
}
function setUp() {
parent::setUp('notifications_user', 'messaging_simple', 'messaging_mail', 'notifications_ui', 'notifications_account');
$this
->drupalCreateContentType(array(
'type' => 'simple',
'name' => 'Simple Content Type',
'description' => 'A really simple content type',
));
$this->publisher = $this
->drupalCreateUser(array(
'access content',
'create simple content',
'skip notifications',
));
$this->subscriber = $this
->drupalCreateUser(array(
'access content',
'create subscriptions',
'subscribe to content type',
'subscribe to author',
'maintain own subscriptions',
));
variable_set('notifications_content_type', array(
'simple',
));
variable_set('notifications_content_per_type', FALSE);
$record1 = array(
'hook' => 'node_insert',
'aid' => 'notifications_content_node_post_action',
);
drupal_write_record('trigger_assignments', $record1);
}
function testNotificationDelivery() {
$this
->drupalLogin($this->subscriber);
$query = array(
$this->publisher->uid,
);
$this
->drupalGet('notifications/subscribe/user_content', array(
'query' => $query,
));
$edit = array();
$edit['send_method'] = 'simple';
$this
->drupalPost(NULL, $edit, t('Create subscription'));
$this
->drupalGet('user/' . $this->subscriber->uid . '/notifications');
$this
->assertText('You have 1 active subscriptions.', t('Subscription addition has been verified.'));
$this
->drupalCreateNode(array(
'type' => 'simple',
'title' => t('First published node'),
'uid' => $this->publisher->uid,
));
$this
->drupalGet('user/' . $this->subscriber->uid . '/messages');
$this
->assertText(t('First published node'), t('Notification has been received by the subscriber'));
$draft = $this
->drupalCreateNode(array(
'type' => 'simple',
'title' => t('Second unpublished node'),
'uid' => $this->publisher->uid,
'status' => 0,
));
$this
->drupalGet('user/' . $this->subscriber->uid . '/messages');
$this
->assertNoText(t('Second unpublished node'), t('Notification has not been received by the subscriber'));
$draft->title = t('Second published node');
$draft->notifications_status = TRUE;
$draft->notifications_content_disable = FALSE;
$draft->status = NODE_PUBLISHED;
node_save($draft);
$this
->drupalGet('user/' . $this->subscriber->uid . '/messages');
$this
->assertText(t('Second published node'), t('Notification has been received by the subscriber'));
$this
->drupalCreateNode(array(
'type' => 'simple',
'title' => t('Third published node'),
'uid' => $this->publisher->uid,
'status' => NODE_PUBLISHED,
'notifications_content_disable' => TRUE,
));
$this
->drupalGet('user/' . $this->subscriber->uid . '/messages');
$this
->assertNoText(t('Third published node'), t('Notification has not been received by the subscriber'));
$this
->drupalLogout();
}
}