Пример #1
0
 public function makeAll(&$demoDataHelper)
 {
     assert('$demoDataHelper instanceof DemoDataHelper');
     assert('$demoDataHelper->isSetRange("User")');
     $missions = array();
     foreach (self::getMissionData() as $randomMissionData) {
         $postData = array();
         $mission = new Mission();
         $mission->setScenario('importModel');
         $mission->status = Mission::STATUS_AVAILABLE;
         $mission->owner = $demoDataHelper->getRandomByModelName('User');
         $mission->createdByUser = $mission->owner;
         $mission->description = $randomMissionData['description'];
         $mission->reward = $randomMissionData['reward'];
         //Add some comments
         foreach ($randomMissionData['comments'] as $commentDescription) {
             $comment = new Comment();
             $comment->setScenario('importModel');
             $comment->createdByUser = $demoDataHelper->getRandomByModelName('User');
             $comment->description = $commentDescription;
             $mission->comments->add($comment);
         }
         $mission->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE);
         $saved = $mission->save();
         assert('$saved');
         $mission = Mission::getById($mission->id);
         ReadPermissionsOptimizationUtil::securableItemGivenPermissionsForGroup($mission, Group::getByName(Group::EVERYONE_GROUP_NAME));
         $mission->save();
         $missions[] = $mission->id;
     }
     $demoDataHelper->setRangeByModelName('Mission', $missions[0], $missions[count($missions) - 1]);
 }
 public function actionEdit($id, $redirectUrl = null)
 {
     $mission = Mission::getById(intval($id));
     MissionAccessUtil::resolveCanCurrentUserWriteOrDeleteMission($mission);
     ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($mission);
     $editView = new MissionEditView($this->getId(), $this->getModule()->getId(), $this->attemptToSaveModelFromPost($mission), strval($mission));
     $missionsMashableInboxUrl = Yii::app()->createUrl('mashableInbox/default/list', array('modelClassName' => 'Mission'));
     $breadCrumbLinks = array(Zurmo::t('MissionsModule', 'Missions') => $missionsMashableInboxUrl, StringUtil::getChoppedStringContent(strval($mission), 25) => array('default/details', 'id' => $id), Zurmo::t('Core', 'Edit'));
     $view = new MissionsPageView(ZurmoDefaultViewUtil::makeViewWithBreadcrumbsForCurrentUser($this, $editView, $breadCrumbLinks, 'MissionBreadCrumbView'));
     echo $view->render();
 }
 public function testReadUnread()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->deleteAllMissions();
     $createdMission = $this->createAndSaveNewMissionForUser($super);
     $this->assertTrue($this->rules->hasCurrentUserReadLatest($createdMission->id));
     $this->rules->resolveMarkUnread($createdMission->id);
     $savedMission = Mission::getById($createdMission->id);
     $this->assertFalse($this->rules->hasCurrentUserReadLatest($createdMission->id));
     $this->rules->resolveMarkRead($createdMission->id);
     $savedMission = Mission::getById($createdMission->id);
     $this->assertTrue($this->rules->hasCurrentUserReadLatest($createdMission->id));
 }
 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));
 }
Пример #5
0
 /**
  * @depends testAddingComments
  */
 public function testDeleteMission()
 {
     $missions = Mission::getAll();
     $comments = Comment::getAll();
     $personsWhoHaveNotReadLatest = PersonWhoHaveNotReadLatest::getAll();
     $this->assertGreaterThan(0, count($missions));
     $this->assertGreaterThan(0, count($comments));
     $this->assertGreaterThan(0, count($personsWhoHaveNotReadLatest));
     foreach ($missions as $mission) {
         $missionId = $mission->id;
         $mission->forget();
         $mission = Mission::getById($missionId);
         $deleted = $mission->delete();
         $this->assertTrue($deleted);
     }
     //check that all comments and personsWhoHaveNotReadLatest are removed, since they are owned.
     $comments = Comment::getAll();
     $this->assertEquals(0, count($comments));
     $missions = Mission::getAll();
     $this->assertEquals(0, count($missions));
     $personsWhoHaveNotReadLatest = PersonWhoHaveNotReadLatest::getAll();
     $this->assertEquals(0, count($personsWhoHaveNotReadLatest));
 }
 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));
 }