Beispiel #1
0
 /**
  * Test the ability to recognize valid Twitter usernames
  *
  * @since 1.0.0
  *
  * @covers ::isValid
  * @small
  *
  * @return void
  */
 public function testValidity()
 {
     $this->assertFalse(\Twitter\Helpers\Validators\ScreenName::isValid(''), 'empty string is never valid');
     $this->assertTrue(\Twitter\Helpers\Validators\ScreenName::isValid('twitter'), 'failed to mark Twitter username as valid');
     $this->assertTrue(\Twitter\Helpers\Validators\ScreenName::isValid('abc_123'), 'alpha numeric with underscore should be valid');
     $this->assertFalse(\Twitter\Helpers\Validators\ScreenName::isValid('twitter$ir'), 'symbols are not allowed');
     $this->assertFalse(\Twitter\Helpers\Validators\ScreenName::isValid('Supercalifragilisticexpialidocious'), 'Twitter usernames should be limited to 20 characters');
 }
Beispiel #2
0
 /**
  * Construct a new follow intent for the given Twitter screen name
  *
  * @since 1.0.0
  *
  * @param string $screen_name Twitter screen name
  * @param bool $validate      validate screen name matches Twitter username allowed characters and length before saving
  */
 public function __construct($screen_name, $validate = true)
 {
     $screen_name = \Twitter\Helpers\Validators\ScreenName::trim($screen_name);
     if ($screen_name) {
         if (false === $validate || \Twitter\Helpers\Validators\ScreenName::isValid($screen_name)) {
             $this->screen_name = $screen_name;
         }
     }
 }
Beispiel #3
0
 /**
  * Add a related Twitter account
  *
  * @since 1.0.0
  *
  * @param string $username Twitter username
  * @param string $label brief description of how the account relates to the Tweet content
  *
  * @return __CLASS__ support chaining
  */
 public function addRelated($username, $label = '')
 {
     $username = \Twitter\Helpers\Validators\ScreenName::trim($username);
     if ($username) {
         // normalize passed parameter
         $comparison_username = strtolower($username);
         if (!isset($this->related[$comparison_username])) {
             if ($this->validate_inputs) {
                 if (\Twitter\Helpers\Validators\ScreenName::isValid($username)) {
                     $this->related[$comparison_username] = trim($label);
                 }
             } else {
                 $this->related[$comparison_username] = trim($label);
             }
         }
     }
     return $this;
 }