public function testSendMail()
 {
     $messagingProphecy = $this->prophesize('oat\\tao\\model\\messaging\\MessagingService');
     $messagingProphecy->isAvailable()->willReturn(true);
     $messagingProphecy->isAvailable()->should(new CallTimesPrediction(1));
     $user = $this->testUser;
     $messagingProphecy->send(Argument::type('oat\\tao\\model\\messaging\\Message'))->will(function ($args) use($user) {
         $message = $args[0];
         $tokenProperty = new core_kernel_classes_Property(PasswordRecoveryService::PROPERTY_PASSWORD_RECOVERY_TOKEN);
         $token = (string) $user->getOnePropertyValue($tokenProperty);
         if (is_null($token) || strpos($message->getBody(), $token) == false) {
             throw new Exception('Token not found in body');
         }
         return true;
     });
     $messagingProphecy->send(Argument::type('oat\\tao\\model\\messaging\\Message'))->should(new CallTimesPrediction(1));
     $passwordRecoveryService = $this->getPasswordRecoveryService($messagingProphecy->reveal());
     $generisUser = new \core_kernel_users_GenerisUser($this->testUser);
     $this->assertEmpty($generisUser->getPropertyValues(PasswordRecoveryService::PROPERTY_PASSWORD_RECOVERY_TOKEN));
     $generisUser->refresh();
     $this->assertTrue($passwordRecoveryService->sendMail($this->testUser));
     $passwordRecoveryToken = current($generisUser->getPropertyValues(PasswordRecoveryService::PROPERTY_PASSWORD_RECOVERY_TOKEN));
     $this->assertNotEmpty($passwordRecoveryToken);
     $messagingProphecy->checkProphecyMethodsPredictions();
 }
 /**
  * Gets the test takers available for a delivery as a table page
  *
  * @param core_kernel_classes_Resource $delivery
  * @param core_kernel_classes_Resource $testCenter
  * @param array [$options]
  * @param string [$testCenterId]
  * @return array
  * @throws \Exception
  * @throws \common_exception_Error
  * @throws \oat\oatbox\service\ServiceNotFoundException
  */
 public static function getAvailableTestTakers($delivery, $testCenter, $options = array())
 {
     $deliveryService = ServiceManager::getServiceManager()->get(DeliveryService::CONFIG_ID);
     $users = EligibilityService::singleton()->getEligibleTestTakers($testCenter, $delivery);
     $assignedUsers = $deliveryService->getDeliveryTestTakers($delivery->getUri(), $testCenter->getUri(), $options);
     array_walk($assignedUsers, function (&$value) {
         $value = $value->getIdentifier();
     });
     $users = array_diff($users, $assignedUsers);
     array_walk($users, function (&$user) {
         $user = new \core_kernel_users_GenerisUser(new \core_kernel_classes_Resource($user));
     });
     usort($users, function ($a, $b) {
         return strcasecmp(UserHelper::getUserLastName($a), UserHelper::getUserLastName($b));
     });
     return DataTableHelper::paginate($users, $options, function ($users) {
         $testTakers = array();
         foreach ($users as $user) {
             $userId = $user->getIdentifier();
             $lastName = UserHelper::getUserLastName($user);
             $firstName = UserHelper::getUserFirstName($user, empty($lastName));
             $testTakers[] = array('id' => $userId, 'firstname' => _dh($firstName), 'lastname' => _dh($lastName), 'identifier' => $userId);
         }
         return $testTakers;
     });
 }