public function testSendJoinRequestConfirmation_PropertiesFromToBodyOk()
 {
     $e = new LexiconMongoTestEnvironment();
     $e->clean();
     $userId = $e->createUser('User', 'Name', '*****@*****.**');
     $user = new UserModel($userId);
     $project = $e->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE);
     $delivery = new MockCommunicateDelivery();
     Communicate::sendJoinRequestConfirmation($user, $project, $e->website, $delivery);
     // What's in the delivery?
     $senderEmail = 'no-reply@' . $e->website->domain;
     $expectedFrom = array($senderEmail => $e->website->name);
     $expectedTo = array($user->email => $user->name);
     $this->assertEqual($expectedFrom, $delivery->from);
     $this->assertEqual($expectedTo, $delivery->to);
     $this->assertPattern('/' . SF_TESTPROJECT . '/', $delivery->subject);
     $this->assertPattern('/' . $e->website->name . '/', $delivery->subject);
     $this->assertPattern('/have requested/', $delivery->content);
     $this->assertPattern('/' . SF_TESTPROJECT . '/', $delivery->content);
 }
예제 #2
0
 /**
  * Sends an email to request joining of the project
  * @param string $projectId
  * @param string $inviterUserId
  * @param Website $website
  * @param string $toEmail
  * @param DeliveryInterface $delivery
  * @throws \Exception
  * @return string $userId
  */
 public static function sendJoinRequest($projectId, $userId, $website, DeliveryInterface $delivery = null)
 {
     $newUser = new UserModel($userId);
     $project = new ProjectModel();
     $project->read($projectId['id']);
     // Make sure the user exists on the site
     if (!$newUser->hasRoleOnSite($website)) {
         $newUser->siteRole[$website->domain] = $website->userDefaultSiteRole;
     }
     // Determine if user is already a member of the project
     if ($project->userIsMember($newUser->id->asString())) {
         return $newUser->id;
     }
     // Add the user to the project
     $project->createUserJoinRequest($userId, ProjectRoles::CONTRIBUTOR);
     $project->write();
     $admin = new UserModel($project->ownerRef->asString());
     if ($admin->email != '') {
         Communicate::sendJoinRequest($newUser, $admin, $project, $website, $delivery);
         Communicate::sendJoinRequestConfirmation($newUser, $project, $website, $delivery);
     }
     return $admin;
 }