You are here

public function RangeBothValuesRequiredConstraintValidatorTest::providerValidate in Range 8

Data provider for testValidate().

Return value

array Nested arrays of values to check:

  • $item
  • $valid

File

tests/src/Unit/Plugin/Validation/Constraint/RangeBothValuesRequiredConstraintValidatorTest.php, line 58

Class

RangeBothValuesRequiredConstraintValidatorTest
Tests the RangeBothValuesRequiredConstraintValidator validator.

Namespace

Drupal\Tests\range\Unit\Plugin\Validation\Constraint

Code

public function providerValidate() {
  $data = [];
  $cases = [
    [
      'range' => [
        'from' => '',
        'to' => 10,
      ],
      'valid' => FALSE,
    ],
    [
      'range' => [
        'from' => 10,
        'to' => '',
      ],
      'valid' => FALSE,
    ],
    [
      'range' => [
        'from' => '',
        'to' => '',
      ],
      'valid' => FALSE,
    ],
    [
      'range' => [
        'from' => NULL,
        'to' => 10,
      ],
      'valid' => FALSE,
    ],
    [
      'range' => [
        'from' => 10,
        'to' => NULL,
      ],
      'valid' => FALSE,
    ],
    [
      'range' => [
        'from' => NULL,
        'to' => NULL,
      ],
      'valid' => FALSE,
    ],
    [
      'range' => [
        'from' => 0,
        'to' => 0,
      ],
      'valid' => TRUE,
    ],
    [
      'range' => [
        'from' => 0.0,
        'to' => 0.0,
      ],
      'valid' => TRUE,
    ],
    [
      'range' => [
        'from' => 10,
        'to' => 10,
      ],
      'valid' => TRUE,
    ],
  ];
  foreach ($cases as $case) {
    $item = $this
      ->createMock('Drupal\\range\\RangeItemInterface');
    $item
      ->expects($this
      ->any())
      ->method('getValue')
      ->willReturn($case['range']);
    $data[] = [
      $item,
      $case['valid'],
    ];
  }
  return $data;
}