예제 #1
0
 /**
  * Read each line in the test suite files: 
  *   test_data/email_valid.txt 
  *   test_data/email_invalid.txt 
  * 
  * Each line in the valid urls should not throw an exception.
  * Each line in the invalid urls should throw an exception.
  * 
  * @thanks to http://blogs.msdn.com/b/testing123/archive/2009/02/05/email-address-test-cases.aspx
  * 
  */
 public function testTestValidAndInvalidTestSuites()
 {
     $valid_emails = file_get_contents(__DIR__ . '/test_data/email_valid.txt');
     $valid_emails = explode("\n", $valid_emails);
     foreach ($valid_emails as $valid_email) {
         try {
             //good email: shouldn't throw
             $url = \Altumo\Validation\Emails::assertEmailAddress($valid_email);
             $this->assertTrue(true);
         } catch (\Exception $e) {
             $this->assertTrue(false, $valid_email);
         }
     }
     $invalid_emails = file_get_contents(__DIR__ . '/test_data/email_invalid.txt');
     $invalid_emails = explode("\n", $invalid_emails);
     foreach ($invalid_emails as $invalid_email) {
         try {
             //bad email: should throw exception
             $url = \Altumo\Validation\Emails::assertEmailAddress($invalid_email);
             $this->assertTrue(false, $invalid_email);
         } catch (\Exception $e) {
             $this->assertTrue(true);
         }
     }
 }
예제 #2
0
 /**
  * Determines whether the provided $email_address is available to be used. 
  * This is a case-insensitive match.
  * 
  * @param string $email_address
  * @throws \Exception                    //if email address format is invalid
  * @return boolean
  */
 public static function testAvailableEmailAddress($email_address, $exception_message = null)
 {
     $email_address = \Altumo\Validation\Emails::assertEmailAddress($email_address, $exception_message);
     $email_address = strtolower($email_address);
     $count = UserQuery::create()->usesfGuardUserQuery()->filterByUsername($email_address)->endUse()->count();
     if ($count === 0) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * @param string $email
  * 
  * @return string
  * 
  * @throws \Exception if value fails to validate
  */
 protected function assertEmailValid($email)
 {
     return \Altumo\Validation\Emails::assertEmailAddress($email);
 }
예제 #4
0
 /**
  * Enables testing mode, which means this Message will NOT be sent to the
  * recipients specified by "To", "CC", "BCC". This Message will be sent to
  * $reroute_emails_to instead, with a modified subject showing the original 
  * recipients.
  * 
  * @param string $reroute_emails_to
  *   // email address to reroute message to.
  * 
  * @return \sfAltumoPlugin\Email\Message
  */
 public function setTestingModeRerouteToEmail($reroute_emails_to)
 {
     $this->testing_mode_reroute_to_email = \Altumo\Validation\Emails::assertEmailAddress($reroute_emails_to, '$reroute_emails_to expects an email address.');
     return $this;
 }