class CdnSchemeConstraintValidatorTest in CDN 8.3
@coversDefaultClass \Drupal\cdn\Plugin\Validation\Constraint\CdnSchemeConstraintValidator @group cdn
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\cdn\Unit\Plugin\Validation\Constraint\CdnSchemeConstraintValidatorTest
 
 
Expanded class hierarchy of CdnSchemeConstraintValidatorTest
File
- tests/
src/ Unit/ Plugin/ Validation/ Constraint/ CdnSchemeConstraintValidatorTest.php, line 16  
Namespace
Drupal\Tests\cdn\Unit\Plugin\Validation\ConstraintView source
class CdnSchemeConstraintValidatorTest extends UnitTestCase {
  /**
   * @covers ::validate
   *
   * @dataProvider provideTestValidate
   */
  public function testValidate($value, $valid) {
    $constraint_violation_builder = $this
      ->prophesize(ConstraintViolationBuilderInterface::class);
    $constraint_violation_builder
      ->setParameter('%scheme', $value)
      ->willReturn($constraint_violation_builder
      ->reveal());
    $constraint_violation_builder
      ->setInvalidValue($value)
      ->willReturn($constraint_violation_builder
      ->reveal());
    $constraint_violation_builder
      ->addViolation()
      ->willReturn($constraint_violation_builder
      ->reveal());
    if ($valid) {
      $constraint_violation_builder
        ->addViolation()
        ->shouldNotBeCalled();
    }
    else {
      $constraint_violation_builder
        ->addViolation()
        ->shouldBeCalled();
    }
    $context = $this
      ->prophesize(ExecutionContextInterface::class);
    $context
      ->buildViolation(Argument::type('string'))
      ->willReturn($constraint_violation_builder
      ->reveal());
    $constraint = new CdnSchemeConstraint();
    $validate = new CdnSchemeConstraintValidator();
    $validate
      ->initialize($context
      ->reveal());
    $validate
      ->validate($value, $constraint);
  }
  public function provideTestValidate() {
    $data = [];
    // Valid schemes.
    $data['http://'] = [
      'http://',
      TRUE,
    ];
    $data['https://'] = [
      'https://',
      TRUE,
    ];
    $data['//'] = [
      '//',
      TRUE,
    ];
    // Scheme without `://`.
    $data['https'] = [
      'https',
      FALSE,
    ];
    $data['https:'] = [
      'https:',
      FALSE,
    ];
    $data['https:/'] = [
      'https:/',
      FALSE,
    ];
    // Disallowed schemes.
    $data['ftp://'] = [
      'ftp://',
      FALSE,
    ];
    $data['something://'] = [
      'ftp://',
      FALSE,
    ];
    // Non-scheme values.
    $data['/'] = [
      '/',
      FALSE,
    ];
    $data[''] = [
      '',
      FALSE,
    ];
    return $data;
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            CdnSchemeConstraintValidatorTest:: | 
                  public | function | ||
| 
            CdnSchemeConstraintValidatorTest:: | 
                  public | function | @covers ::validate | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Returns a mock object for the specified class using the available method. | |
| 
            PhpunitCompatibilityTrait:: | 
                  public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| 
            UnitTestCase:: | 
                  protected | property | The random generator. | |
| 
            UnitTestCase:: | 
                  protected | property | The app root. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Asserts if two arrays are equal by sorting them first. | |
| 
            UnitTestCase:: | 
                  protected | function | Mocks a block with a block plugin. | 1 | 
| 
            UnitTestCase:: | 
                  protected | function | Returns a stub class resolver. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config factory that behaves according to the passed array. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub config storage that returns the supplied configuration. | |
| 
            UnitTestCase:: | 
                  protected | function | Sets up a container with a cache tags invalidator. | |
| 
            UnitTestCase:: | 
                  protected | function | Gets the random generator for the utility methods. | |
| 
            UnitTestCase:: | 
                  public | function | Returns a stub translation manager that just returns the passed string. | |
| 
            UnitTestCase:: | 
                  public | function | Generates a unique random string containing letters and numbers. | |
| 
            UnitTestCase:: | 
                  protected | function | 340 |