You are here

public function DateRecurFieldItemTest::testRruleInvalidConstraint in Recurring Dates Field 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Kernel/DateRecurFieldItemTest.php \Drupal\Tests\date_recur\Kernel\DateRecurFieldItemTest::testRruleInvalidConstraint()
  2. 3.0.x tests/src/Kernel/DateRecurFieldItemTest.php \Drupal\Tests\date_recur\Kernel\DateRecurFieldItemTest::testRruleInvalidConstraint()
  3. 3.1.x tests/src/Kernel/DateRecurFieldItemTest.php \Drupal\Tests\date_recur\Kernel\DateRecurFieldItemTest::testRruleInvalidConstraint()

Tests when an invalid RRULE is passed.

File

tests/src/Kernel/DateRecurFieldItemTest.php, line 189

Class

DateRecurFieldItemTest
Tests date_recur field.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testRruleInvalidConstraint() {
  $entity = DrEntityTest::create();
  $entity->dr = [
    'value' => '2014-06-15T23:00:00',
    'end_value' => '2014-06-16T07:00:00',
    'rrule' => $this
      ->randomMachineName(),
    'infinite' => '0',
    'timezone' => 'Australia/Sydney',
  ];

  /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $violations */
  $violations = $entity->dr
    ->validate();
  $this
    ->assertGreaterThanOrEqual(1, $violations
    ->count());
  $expectedMessage = 'Invalid RRULE.';
  $list = [];
  foreach ($violations as $violation) {
    if ((string) $violation
      ->getMessage() === $expectedMessage) {
      $list[] = $violation;
    }
  }
  $this
    ->assertCount(1, $list);
}