You are here

public function DateRecurPartGridTest::testAllowedSomeParts in Recurring Dates Field 8.2

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

Tests when some parts for a frequency is allowed.

File

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

Class

DateRecurPartGridTest
Tests field validation failures as a result part grids.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testAllowedSomeParts() {
  $this
    ->setPartSettings([
    'all' => FALSE,
    'frequencies' => [
      'WEEKLY' => [
        'DTSTART',
        'FREQ',
        'COUNT',
        'INTERVAL',
        'WKST',
      ],
    ],
  ]);
  $entity = EntityTest::create();
  $entity->foo = [
    'value' => '2014-06-15T23:00:00',
    'end_value' => '2014-06-16T07:00:00',
    // Include a disallowed part.
    '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(1, $violations
    ->count());
  $violation = $violations
    ->get(0);
  $message = strip_tags((string) $violation
    ->getMessage());
  $this
    ->assertEquals('By-day is not a permitted part.', $message);
  $entity = EntityTest::create();
  $entity->foo = [
    'value' => '2014-06-15T23:00:00',
    'end_value' => '2014-06-16T07:00:00',
    // Remove the disallowed BYDAY part.
    'rrule' => 'FREQ=WEEKLY;COUNT=3',
    'infinite' => '0',
    'timezone' => 'Australia/Sydney',
  ];

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