Exemple #1
0
 public function testResolvePeopleToSendNotificationToOnNewMission()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $steven = User::getByUsername('steven');
     $mary = UserTestHelper::createBasicUser('mary');
     $missions = Mission::getAll();
     $mission = $missions[0];
     $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($mission);
     $this->assertNotContains($super, $people);
     $this->assertContains($steven, $people);
     $this->assertContains($mary, $people);
 }
 /**
  * Alter takenByUserHasReadLatest and/or ownerHasReadLatest based on comments being added.
  * (non-PHPdoc)
  * @see Item::beforeSave()
  */
 protected function beforeSave()
 {
     $missionRules = new MissionMashableInboxRules();
     $personsToAddAsHaveNotReadLatest = array();
     if (parent::beforeSave()) {
         if ($this->getIsNewModel()) {
             $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
             $personsToAddAsHaveNotReadLatest = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($this);
         }
         if (isset($this->originalAttributeValues['status']) && $this->originalAttributeValues['status'] != $this->status && $this->status == self::STATUS_TAKEN) {
             MissionsUtil::markAllUserHasReadLatestExceptOwnerAndTakenBy($this);
         }
         if ($this->comments->isModified()) {
             $this->unrestrictedSet('latestDateTime', DateTimeUtil::convertTimestampToDbFormatDateTime(time()));
             foreach ($this->comments as $comment) {
                 if ($comment->id < 0) {
                     if (Yii::app()->user->userModel != $this->owner) {
                         $this->sendOwnerUnreadCommentNotification = true;
                     }
                     if (Yii::app()->user->userModel != $this->takenByUser && $this->takenByUser->id > 0) {
                         $this->sendTakenByUserUnreadCommentNotification = true;
                     }
                 }
             }
             $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewComment($this, Yii::app()->user->userModel);
             foreach ($people as $person) {
                 if ($missionRules->hasUserReadLatest($this, $person)) {
                     if (!in_array($person, $personsToAddAsHaveNotReadLatest)) {
                         $personsToAddAsHaveNotReadLatest[] = $person;
                     }
                 }
             }
         }
         foreach ($personsToAddAsHaveNotReadLatest as $person) {
             $personWhoHaveNotReadLatest = $missionRules->makePersonWhoHasNotReadLatest($person);
             $personsToAddAsHaveNotReadLatest[] = $personWhoHaveNotReadLatest;
             $this->personsWhoHaveNotReadLatest->add($personWhoHaveNotReadLatest);
         }
         return true;
     } else {
         return false;
     }
 }
 public function testResolvePeopleToSendNotificationToOnNewMission()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $steven = User::getByUsername('steven');
     $jack = User::getByUsername('jack');
     // assert steven is active user
     $this->assertEquals(1, $steven->isActive);
     // assert steven is active user
     $this->assertEquals(1, $jack->isActive);
     // assert steven have access to missions module
     $this->assertTrue(RightsUtil::canUserAccessModule('MissionsModule', $steven));
     // assert jack dont have access to missions module
     $this->assertFalse(RightsUtil::canUserAccessModule('MissionsModule', $jack));
     $missions = Mission::getAll();
     $mission = $missions[0];
     $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($mission);
     // assert active user will get notification on creation of new mission
     $this->assertEquals(1, count($people));
     $this->assertNotContains($super, $people);
     $this->assertContains($steven, $people);
     $this->assertNotContains($jack, $people);
     // Change the user's status to inactive and confirm the changes in rights and isActive attribute.
     $steven = User::getByUsername('steven');
     $steven->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB, RIGHT::DENY);
     $this->assertTrue($steven->save());
     // assert steven is inactive user
     $this->assertEquals(0, $steven->isActive);
     $missions = Mission::getAll();
     $mission = $missions[0];
     $people = MissionsUtil::resolvePeopleToSendNotificationToOnNewMission($mission);
     // assert inactive user won't get notification on creation of new mission
     $this->assertEquals(0, count($people));
     $this->assertNotContains($super, $people);
     $this->assertNotContains($steven, $people);
     $this->assertNotContains($jack, $people);
 }