You are here

public function DateRecurFieldItemTest::testHelperResetAfterValueChange in Recurring Dates Field 3.1.x

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

Tests cached helper instance is reset if its dependant values are modified.

@covers ::onChange

File

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

Class

DateRecurFieldItemTest
Tests date_recur field.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testHelperResetAfterValueChange() {
  $entity = DrEntityTest::create();
  $entity->dr = [
    [
      'value' => '2014-06-15T23:00:01',
      'end_value' => '2014-06-16T07:00:02',
      'timezone' => 'Indian/Christmas',
      'rrule' => 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR;COUNT=5',
    ],
  ];

  /** @var \Drupal\date_recur\DateRecurHelperInterface $helper1 */
  $helper1 = $entity->dr[0]
    ->getHelper();
  $firstOccurrence = $helper1
    ->getOccurrences(NULL, NULL, 1)[0];
  $this
    ->assertEquals('Mon, 16 Jun 2014 06:00:01 +0700', $firstOccurrence
    ->getStart()
    ->format('r'));
  $this
    ->assertEquals('Mon, 16 Jun 2014 14:00:02 +0700', $firstOccurrence
    ->getEnd()
    ->format('r'));
  $this
    ->assertEquals('WEEKLY', $helper1
    ->getRules()[0]
    ->getFrequency());

  // Change some values.
  $entity->dr[0]->value = '2015-07-15T23:00:03';
  $entity->dr[0]->end_value = '2015-07-16T07:00:04';
  $entity->dr[0]->rrule = 'FREQ=DAILY;COUNT=3';

  /** @var \Drupal\date_recur\DateRecurHelperInterface $helper2 */
  $helper2 = $entity->dr[0]
    ->getHelper();
  $firstOccurrence = $helper2
    ->getOccurrences(NULL, NULL, 1)[0];
  $this
    ->assertEquals('Thu, 16 Jul 2015 06:00:03 +0700', $firstOccurrence
    ->getStart()
    ->format('r'));
  $this
    ->assertEquals('Thu, 16 Jul 2015 14:00:04 +0700', $firstOccurrence
    ->getEnd()
    ->format('r'));
  $this
    ->assertEquals('DAILY', $helper2
    ->getRules()[0]
    ->getFrequency());
}