/** * @depends testResolveConversationParticipantsForExplicitModelPermissions */ public function testGetUnreadConversationCount() { $super = User::getByUsername('super'); $mary = User::getByUsername('mary'); $count = Conversation::getUnreadCountByUser($super); $account2 = AccountTestHelper::createAccountByNameForOwner('anAccount2', $super); $conversation = new Conversation(); $conversation->owner = $super; $conversation->subject = 'My test subject2'; $conversation->description = 'My test description2'; $conversation->conversationItems->add($account2); $this->assertTrue($conversation->save()); //when super adds a comment, it should remain same count $comment = new Comment(); $comment->description = 'This is my first comment'; $conversation->comments->add($comment); $this->assertTrue($conversation->save()); $count = Conversation::getUnreadCountByUser($super); $this->assertEquals(1, $count); //Add mary as a participant $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($conversation); $postData = array(); $postData['itemIds'] = $super->getClassId('Item') . ',' . $mary->getClassId('Item'); // Not Coding Standard ConversationParticipantsUtil::resolveConversationHasManyParticipantsFromPost($conversation, $postData, $explicitReadWriteModelPermissions); $success = ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($conversation, $explicitReadWriteModelPermissions); $this->assertTrue($success); $conversation->save(); //when mary adds a comment, super's count should go up (assumming count was previously 0) Yii::app()->user->userModel = $mary; $comment = new Comment(); $comment->description = 'This is mary\'s first comment'; $conversation->comments->add($comment); $this->assertTrue($conversation->save()); Yii::app()->user->userModel = $super; $count = Conversation::getUnreadCountByUser($super); $this->assertEquals(2, $count); }
/** * For the current user, render a string of how many unread conversations exist for the user. * @return string */ public static function getUnreadCountTabMenuContentForCurrentUser() { return Conversation::getUnreadCountByUser(Yii::app()->user->userModel); }