You are here

public function DateRecurPartGridTest::testFrequency in Recurring Dates Field 3.x

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

Tests when a frequency is allowed or disallowed.

File

tests/src/Kernel/DateRecurPartGridTest.php, line 133

Class

DateRecurPartGridTest
Tests field validation failures as a result part grids.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testFrequency() {
  $this
    ->setPartSettings([
    'all' => FALSE,
    'frequencies' => [
      'WEEKLY' => [
        '*',
      ],
    ],
  ]);
  $entity = EntityTest::create();
  $entity->foo = [
    'value' => '2014-06-15T23:00:00',
    'end_value' => '2014-06-16T07:00:00',
    'rrule' => 'FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR;COUNT=3',
    'infinite' => '0',
    'timezone' => 'Australia/Sydney',
  ];

  // Try a disallowed frequency.

  /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $violations */
  $violations = $entity->foo
    ->validate();
  $this
    ->assertEquals(1, $violations
    ->count());
  $violation = $violations
    ->get(0);
  $message = strip_tags((string) $violation
    ->getMessage());
  $this
    ->assertEquals('Daily is not a permitted frequency.', $message);

  // Try an allowed frequency.
  $entity = EntityTest::create();
  $entity->foo = [
    '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' => 'Australia/Sydney',
  ];

  /** @var \Symfony\Component\Validator\ConstraintViolationListInterface $violations */
  $violations = $entity->foo
    ->validate();
  $this
    ->assertEquals(0, $violations
    ->count());
}