You are here

function NotificationsUserTestCase::testNotificationDelivery in Notifications 7

File

notifications_user/notifications_user.test, line 51

Class

NotificationsUserTestCase
Notifications User test case suite.

Code

function testNotificationDelivery() {

  // Log the subscriber in..
  $this
    ->drupalLogin($this->subscriber);

  // Subscribe to the publisher..
  $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'));

  // Validate subscription..
  $this
    ->drupalGet('user/' . $this->subscriber->uid . '/notifications');
  $this
    ->assertText('You have 1 active subscriptions.', t('Subscription addition has been verified.'));

  // A.
  // Publish on behalf of the publisher..
  $this
    ->drupalCreateNode(array(
    'type' => 'simple',
    'title' => t('First published node'),
    'uid' => $this->publisher->uid,
  ));

  // Ensure notifications has been received by the subscriber..
  $this
    ->drupalGet('user/' . $this->subscriber->uid . '/messages');
  $this
    ->assertText(t('First published node'), t('Notification has been received by the subscriber'));

  // B.
  $draft = $this
    ->drupalCreateNode(array(
    'type' => 'simple',
    'title' => t('Second unpublished node'),
    'uid' => $this->publisher->uid,
    'status' => 0,
  ));

  // Ensure notifications has not been received by the subscriber..
  $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);

  // Ensure notifications has been received by the subscriber..
  $this
    ->drupalGet('user/' . $this->subscriber->uid . '/messages');
  $this
    ->assertText(t('Second published node'), t('Notification has been received by the subscriber'));

  // C. Ensure notifications skipping is respected..
  $this
    ->drupalCreateNode(array(
    'type' => 'simple',
    'title' => t('Third published node'),
    'uid' => $this->publisher->uid,
    'status' => NODE_PUBLISHED,
    'notifications_content_disable' => TRUE,
  ));

  // Ensure notifications has not been received by the subscriber..
  $this
    ->drupalGet('user/' . $this->subscriber->uid . '/messages');
  $this
    ->assertNoText(t('Third published node'), t('Notification has not been received by the subscriber'));

  // Log the subscriber out..
  $this
    ->drupalLogout();
}