You are here

public function SocialUserNameConstraintTest::providerTestValidate in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  2. 8 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  3. 8.2 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  4. 8.3 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  5. 8.5 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  6. 8.6 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  7. 8.7 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  8. 8.8 modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  9. 10.3.x modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  10. 10.0.x modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  11. 10.1.x modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()
  12. 10.2.x modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php \Drupal\social_user\Tests\SocialUserNameConstraintTest::providerTestValidate()

Data provider for ::testValidate().

File

modules/social_features/social_user/tests/src/Unit/Validation/Constraint/SocialUserNameConstraintTest.php, line 82

Class

SocialUserNameConstraintTest
@coversDefaultClass \Drupal\social_user\Plugin\Validation\Constraint\SocialUserNameConstraintValidator

Namespace

Drupal\social_user\Tests

Code

public function providerTestValidate() {
  $cases = [];

  // Case 1: Validation context should not be touched if no items are passed.
  $cases[] = [
    NULL,
    FALSE,
  ];

  // Case 2: Empty user should be ignored.
  $field_definition = $this
    ->getMock('Drupal\\Core\\Field\\FieldDefinitionInterface');
  $items = $this
    ->getMock('Drupal\\Core\\Field\\FieldItemListInterface');
  $items
    ->expects($this
    ->any())
    ->method('getFieldDefinition')
    ->willReturn($field_definition);
  $items
    ->expects($this
    ->any())
    ->method('first')
    ->willReturn(NULL);
  $cases[] = [
    $items,
    FALSE,
  ];

  // Correct email cases.
  // See https://en.wikipedia.org/wiki/Email_address.
  $invalid_names = [
    'prettyandsimple@example.com',
    'very.common@example.com',
    'disposable.style.email.with+symbol@example.com',
    'other.email-with-dash@example.com',
    '"much.more unusual"@example.com',
    '"very.unusual.@.unusual.com"@example.com',
    'admin@mailserver1 (local domain name with no TLD)',
    '#!$%&\'*+-/=?^_`{}|~@example.org',
    '" "@example.org (space between the quotes)',
    'example@s.solutions (see the List of Internet top-level domains)',
    'example@s.solutions (see the List of Internet top-level domains)',
    'user@com',
    'user@localserver',
    'user@[IPv6:2001:db8::1]',
  ];
  foreach ($invalid_names as $name) {
    $cases[] = [
      $this
        ->itemsMock($name),
      TRUE,
      $this
        ->buildViolationList(0),
      $name,
    ];
  }

  // These names are valid names, but are validated as incorrect.
  // Because we use the same validation for the Emails it will not
  // Affect the email login system.
  $valid_names_but_valid_emails = [
    '"very.(),:;<>[]\\".VERY.\\"very@\\ \\"very\\".unusual"@strange.example.com',
    '"()<>[]:,;@\\\\"!#$%&\'*+-/=?^_`{}| ~.a"@example.org',
    'Abc.example.com (no @ character)',
  ];
  $email_violations = 1;
  foreach ($valid_names_but_valid_emails as $name) {
    $cases[] = [
      $this
        ->itemsMock($name),
      FALSE,
      $this
        ->buildViolationList($email_violations),
      $name,
    ];
    $email_violations++;
  }
  $valid_names = [
    'admin',
    'user1',
    'haha',
    'neil goodman',
    'Abc.example.com',
    'ohn.doe@example..com',
    'this is"not\\allowed@example.com',
    'just"not"right@example.com',
    'john..doe@example.com',
    'a"b(c)d,e:f;g<h>i[j\\k]l@example.com',
    'A@b@c@example.com',
  ];
  $email_violations = 3;
  foreach ($valid_names as $name) {
    $cases[] = [
      $this
        ->itemsMock($name),
      FALSE,
      $this
        ->buildViolationList($email_violations),
      $name,
    ];
    $email_violations++;
  }
  return $cases;
}