You are here

public function DateRecurFieldItemDefaultValuesTest::testDefaults in Recurring Dates Field 3.1.x

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

Tests default behaviour.

File

tests/src/Kernel/DateRecurFieldItemDefaultValuesTest.php, line 70

Class

DateRecurFieldItemDefaultValuesTest
Tests date_recur field with default values configured at the instance level.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testDefaults() {
  $this->baseFieldOverride
    ->setDefaultValue([
    [
      'default_date_type' => 'relative',
      'default_date' => '12th April 2013 3pm',
      'default_end_date_type' => 'relative',
      'default_end_date' => '12th April 2013 4pm',
      'default_date_time_zone' => 'Europe/Oslo',
      'default_time_zone' => 'Indian/Christmas',
      'default_rrule' => 'FREQ=DAILY;COUNT=100',
    ],
  ]);
  $this->baseFieldOverride
    ->save();
  $entity = DrEntityTest::create();
  $this
    ->assertEquals('2013-04-12T13:00:00', $entity->dr->value);
  $this
    ->assertEquals('2013-04-12T14:00:00', $entity->dr->end_value);
  $this
    ->assertEquals('Indian/Christmas', $entity->dr->timezone);
  $this
    ->assertEquals('FREQ=DAILY;COUNT=100', $entity->dr->rrule);
  $entity
    ->save();

  // Value is kept after save.
  $this
    ->assertEquals(1, $entity->dr
    ->count());
}