public function testReadUnread()
 {
     $super = User::getByUsername('super');
     $billy = User::getByUsername('billy');
     Yii::app()->user->userModel = $super;
     $this->deleteAllNotifications();
     $createdNotification = $this->createAndSaveNewNotificationForUser($super);
     $this->assertEquals(1, $this->rules->getUnreadCountForCurrentUser(), 0);
     $savedNotification = Notification::getById($createdNotification->id);
     $savedNotification->ownerHasReadLatest = 0;
     $savedNotification->save();
     $this->assertEquals(1, $this->rules->getUnreadCountForCurrentUser(), 0);
     //Other users should have 0 unread notifications
     Yii::app()->user->userModel = $billy;
     $this->assertEquals(0, $this->rules->getUnreadCountForCurrentUser(), 0);
     //Mark notification as ready by super
     $this->rules->resolveMarkRead($createdNotification->id);
     Yii::app()->user->userModel = $super;
     $this->assertTrue((bool) $savedNotification->ownerHasReadLatest);
     $this->assertTrue((bool) $this->rules->hasCurrentUserReadLatest($createdNotification->id));
     $this->rules->resolveMarkUnread($createdNotification->id);
     $savedNotification = Notification::getById($createdNotification->id);
     $this->assertFalse((bool) $savedNotification->ownerHasReadLatest);
     $this->assertFalse((bool) $this->rules->hasCurrentUserReadLatest($createdNotification->id));
 }
 public static function resolveRowHtmlOptionsExpression($grid, $row, $data)
 {
     $notification = Notification::getById($data->id);
     if (!$notification->ownerHasReadLatest) {
         $params = array("class" => 'unread');
         return $params;
     }
 }
Example #3
0
 /**
  * @depends testGetCountByUser
  */
 public function testNotification()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $notification = new Notification();
     $notification->type = 'Simple';
     $notification->owner = Yii::app()->user->userModel;
     $this->assertTrue($notification->save());
     $this->assertTrue($notification->save());
     $notificationId = $notification->id;
     $notification->forget();
     //Retrieve again.
     $notification = Notification::getById($notificationId);
     $this->assertEquals('Simple', $notification->type);
     $notification->delete();
 }
 /**
  * @depends testRelationsBetweenNotificationAndNotificationMessage
  */
 public function testDeleteByTypeAndUser()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $joe = UserTestHelper::createBasicUser('joe');
     $sally = UserTestHelper::createBasicUser('sally');
     //Make sure the relations between Notification and NotificationMessage is working.
     $message = new NotificationMessage();
     $message->textContent = 'text content3';
     $message->htmlContent = 'html content3';
     $this->assertTrue($message->save());
     $notification1 = new Notification();
     $notification1->type = 'SimpleDTest';
     $notification1->owner = $joe;
     $notification1->notificationMessage = $message;
     $this->assertTrue($notification1->save());
     //And Billy can create a notification for super
     $notification2 = new Notification();
     $notification2->type = 'SimpleDTest';
     $notification2->owner = $sally;
     $notification2->notificationMessage = $message;
     $this->assertTrue($notification2->save());
     $this->assertEquals(2, $message->notifications->count());
     $messageId = $message->id;
     $notification1Id = $notification1->id;
     $notification2Id = $notification2->id;
     $message->forget();
     $notification1->forget();
     $notification2->forget();
     Notification::deleteByTypeAndUser('SimpleDTest', $joe);
     // Notification message should exist, because there is still notification point to it
     $message = NotificationMessage::getById($messageId);
     $this->assertTrue($message instanceof NotificationMessage);
     $notification2 = Notification::getById($notification2Id);
     $this->assertTrue($notification2 instanceof Notification);
     $notifications = Notification::getByNotificationMessageId($messageId);
     $this->assertEquals(1, count($notifications));
     $this->assertEquals($notification2Id, $notifications[0]->id);
     try {
         Notification::getById($notification1Id);
         $this->fail();
     } catch (NotFoundException $e) {
     }
     $message->forget();
     $notification2->forget();
     // Now delete second notification, this time notification message should be deleted too
     Notification::deleteByTypeAndUser('SimpleDTest', $sally);
     try {
         NotificationMessage::getById($messageId);
         $this->fail();
     } catch (NotFoundException $e) {
     }
     try {
         Notification::getById($notification2Id);
         $this->fail();
     } catch (NotFoundException $e) {
     }
 }