You are here

public function DateRecurFieldItemTest::testTimeZoneConstraintInvalidFormat 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::testTimeZoneConstraintInvalidFormat()
  2. 3.0.x tests/src/Kernel/DateRecurFieldItemTest.php \Drupal\Tests\date_recur\Kernel\DateRecurFieldItemTest::testTimeZoneConstraintInvalidFormat()
  3. 3.1.x tests/src/Kernel/DateRecurFieldItemTest.php \Drupal\Tests\date_recur\Kernel\DateRecurFieldItemTest::testTimeZoneConstraintInvalidFormat()

Tests violations when time zone is not a string.

File

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

Class

DateRecurFieldItemTest
Tests date_recur field.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testTimeZoneConstraintInvalidFormat() {
  $entity = DrEntityTest::create();
  $entity->dr = [
    'value' => '2014-06-15T23:00:00',
    'end_value' => '2014-06-16T07:00:00',
    'rrule' => 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;COUNT=3',
    'infinite' => '0',
    'timezone' => new \StdClass(),
  ];

  /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $violations */
  $violations = $entity->dr
    ->validate();
  $this
    ->assertGreaterThanOrEqual(1, $violations
    ->count());
  $expectedMessage = 'This value should be of the correct primitive type.';
  $list = [];
  foreach ($violations as $violation) {
    if ((string) $violation
      ->getMessage() === $expectedMessage) {
      $list[] = $violation;
    }
  }
  $this
    ->assertCount(1, $list);
}