You are here

public function DateRecurTest::testSingleCardinalityBaseField in Recurring Dates Field 3.1.x

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

Basic tests for purposes of ensuring the entity type works.

File

tests/src/Kernel/DateRecurTest.php, line 46

Class

DateRecurTest
Tests basic functionality of date_recur fields.

Namespace

Drupal\Tests\date_recur\Kernel

Code

public function testSingleCardinalityBaseField() {
  $this
    ->installEntitySchema('dr_entity_test_single');
  $entity = DrEntityTestSingleCardinality::create();
  $entity->dr = [
    [
      'value' => '2014-06-15T23:00:00',
      'end_value' => '2014-06-16T07:00:00',
      'rrule' => 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR',
      'infinite' => '1',
      'timezone' => 'Australia/Sydney',
    ],
    [
      'value' => '2013-06-15T23:00:00',
      'end_value' => '2013-06-16T07:00:00',
      'rrule' => 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR',
      'infinite' => '1',
      'timezone' => 'Australia/Sydney',
    ],
  ];

  /** @var \Drupal\date_recur\Plugin\Field\FieldType\DateRecurFieldItemList $fieldList */
  $fieldList = $entity->dr;
  $validations = $fieldList
    ->validate();
  $violation = $validations
    ->get(0);
  $message = (string) $violation
    ->getMessage();
  $this
    ->assertEquals('<em class="placeholder">Rule</em>: this field cannot hold more than 1 values.', $message);
  $this
    ->assertEquals(2, $fieldList
    ->count());

  // Assert after saving and reloading entity only one value is available.
  $entity
    ->save();
  $entity = DrEntityTestSingleCardinality::load($entity
    ->id());
  $this
    ->assertEquals(1, $entity->dr
    ->count());
}