public static function resolveRowCssClasses($grid, $row, $data) { if (is_array($grid->rowCssClass) && ($n = count($grid->rowCssClass)) > 0) { $content = $grid->rowCssClass[$row % $n]; if (!MissionsUtil::hasUserReadMissionLatest($data, Yii::app()->user->userModel)) { $content .= ' unread'; } return $content; } }
public function testMissionReadUnreadStatus() { $steven = User::getByUsername('steven'); $sally = User::getByUsername('sally'); $mary = User::getByUsername('mary'); $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $mission = new Mission(); $mission->owner = $steven; $mission->description = 'My test mission description'; $mission->status = Mission::STATUS_AVAILABLE; $this->assertTrue($mission->save()); $missionId = $mission->id; $explicitReadWriteModelPermissions = new ExplicitReadWriteModelPermissions(); $explicitReadWriteModelPermissions->addReadWritePermitable(Group::getByName(Group::EVERYONE_GROUP_NAME)); ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($mission, $explicitReadWriteModelPermissions); $mission = Mission::getById($missionId); //Confirm users have mission marked as unread but not owner $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); //Super reads the mission $this->setGetArray(array('id' => $missionId)); $this->runControllerWithNoExceptionsAndGetContent('missions/default/details'); $mission = Mission::getById($missionId); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); //Mary marks mission as read and post a comment $this->logoutCurrentUserLoginNewUserAndGetByUsername('mary'); MissionsUtil::markUserHasReadLatest($mission, $mary); $this->setGetArray(array('relatedModelId' => $missionId, 'relatedModelClassName' => 'Mission', 'relatedModelRelationName' => 'comments', 'redirectUrl' => 'someRedirect')); $this->setPostArray(array('Comment' => array('description' => 'Mary\'s new comment'))); $this->runControllerWithRedirectExceptionAndGetContent('comments/default/inlineCreateSave'); $mission = Mission::getById($missionId); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); //Sally reads and takes the mission $this->logoutCurrentUserLoginNewUserAndGetByUsername('sally'); $this->setGetArray(array('id' => $missionId)); $this->resetPostArray(); $this->runControllerWithNoExceptionsAndGetContent('missions/default/details'); $mission = Mission::getById($missionId); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); $this->setGetArray(array('status' => Mission::STATUS_TAKEN, 'id' => $missionId)); $this->runControllerWithNoExceptionsAndGetContent('missions/default/ajaxChangeStatus'); //Every user other than owner and takenby are marked as read latest $mission = Mission::getById($missionId); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $sally)); $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $mary)); }
/** * @depends testCreateAndGetMissionById */ public function testAddingComments() { $missions = Mission::getAll(); $this->assertEquals(1, count($missions)); $mission = $missions[0]; $steven = User::getByUserName('steven'); $super = User::getByUsername('super'); $latestStamp = $mission->latestDateTime; //latestDateTime should not change when just saving the mission $this->assertTrue($mission->save()); $this->assertEquals($latestStamp, $mission->latestDateTime); sleep(2); // Sleeps are bad in tests, but I need some time to pass //Add comment, this should update the latestDateTime, //and also it should mark takenByUser as not read latest $comment = new Comment(); $comment->description = 'This is my first comment'; $mission->comments->add($comment); $this->assertTrue($mission->save()); $this->assertNotEquals($latestStamp, $mission->latestDateTime); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $steven)); //super made the comment, so this should remain the same. $this->assertTrue(MissionsUtil::hasUserReadMissionLatest($mission, $super)); //have steven make the comment. Now the owner HasReadLatest, //and takenByUser HasNotReadLatest Yii::app()->user->userModel = $steven; $mission = Mission::getById($mission->id); $comment = new Comment(); $comment->description = 'This is steven`\\s first comment'; $mission->comments->add($comment); $this->assertTrue($mission->save()); $this->assertFalse(MissionsUtil::hasUserReadMissionLatest($mission, $super)); }
public function testMarkReadUnreadMassActionByModel() { $super = User::getByUsername('super'); //Conversation model $conversation = new Conversation(); $conversation->owner = $super; $conversation->subject = 'My test conversation subject'; $conversation->description = 'My test conversation description'; $this->assertTrue($conversation->save()); $conversationId = $conversation->id; $this->assertTrue((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super)); //Mark conversation as unread $selectedIds = $conversationId; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Conversation', 'MashableInboxForm' => array('massAction' => 'markUnread', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $conversation = Conversation::getById($conversationId); $this->assertFalse((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super)); //Mark conversation as read $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Conversation', 'MashableInboxForm' => array('massAction' => 'markRead', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $conversation = Conversation::getById($conversationId); $this->assertTrue((bool) ConversationsUtil::hasUserReadConversationLatest($conversation, $super)); //Mission model $mission = new Mission(); $mission->owner = $super; $mission->description = 'My test mission description'; $mission->status = Mission::STATUS_AVAILABLE; $this->assertTrue($mission->save()); $missionId = $mission->id; $this->assertTrue((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super)); //Mark mission as unread $selectedIds = $missionId; $_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Mission', 'MashableInboxForm' => array('massAction' => 'markUnread', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $mission = Mission::getById($missionId); $this->assertFalse((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super)); //Mark mission as read $this->setGetArray(array('ajax' => 'list-view', 'modelClassName' => 'Mission', 'MashableInboxForm' => array('massAction' => 'markRead', 'selectedIds' => $selectedIds))); $content = $this->runControllerWithNoExceptionsAndGetContent('mashableInbox/default/list'); $mission = Mission::getById($missionId); $this->assertTrue((bool) MissionsUtil::hasUserReadMissionLatest($mission, $super)); }
public function testMarkUserHasReadLatestAndMarkHasUserUnreadLatest() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $steven = User::getByUsername('steven'); $missions = Mission::getAll(); $mission = $missions[0]; $this->assertTrue($mission->save()); $this->assertEquals(1, MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertEquals(0, MissionsUtil::hasUserReadMissionLatest($mission, $steven)); MissionsUtil::markUserHasUnreadLatest($mission, Yii::app()->user->userModel); $missions = Mission::getAll(); $mission = $missions[0]; $this->assertEquals(0, MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertEquals(0, MissionsUtil::hasUserReadMissionLatest($mission, $steven)); MissionsUtil::markUserHasReadLatest($mission, Yii::app()->user->userModel); $missions = Mission::getAll(); $mission = $missions[0]; $this->assertEquals(1, MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertEquals(0, MissionsUtil::hasUserReadMissionLatest($mission, $steven)); Yii::app()->user->userModel = User::getByUsername('steven'); MissionsUtil::markUserHasReadLatest($mission, Yii::app()->user->userModel); $missions = Mission::getAll(); $mission = $missions[0]; $this->assertEquals(1, MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertEquals(1, MissionsUtil::hasUserReadMissionLatest($mission, $steven)); MissionsUtil::markUserHasUnreadLatest($mission, Yii::app()->user->userModel); $missions = Mission::getAll(); $mission = $missions[0]; $this->assertEquals(1, MissionsUtil::hasUserReadMissionLatest($mission, $super)); $this->assertEquals(0, MissionsUtil::hasUserReadMissionLatest($mission, $steven)); }