You are here

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

Tests violations when RRULE over max length.

File

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

Class

DateRecurFieldItemTest
Tests date_recur field.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testRruleMaxLengthConstraint() {
  $this
    ->installEntitySchema('entity_test');
  $field_storage = FieldStorageConfig::create([
    'entity_type' => 'entity_test',
    'field_name' => 'foo',
    'type' => 'date_recur',
    'settings' => [
      'datetime_type' => DateRecurItem::DATETIME_TYPE_DATETIME,
      // Test a super short length.
      'rrule_max_length' => 20,
    ],
  ]);
  $field_storage
    ->save();
  $field = [
    'field_name' => 'foo',
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
  ];
  FieldConfig::create($field)
    ->save();
  $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(1, $violations
    ->count());
  $violation = $violations
    ->get(0);
  $message = strip_tags((string) $violation
    ->getMessage());
  $this
    ->assertEquals('This value is too long. It should have 20 characters or less.', $message);
}