You are here

DateRecurOccurrenceTableTest.php in Recurring Dates Field 8

File

tests/src/Kernel/DateRecurOccurrenceTableTest.php
View source
<?php

namespace Drupal\Tests\date_recur\Kernel;

use Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;

/**
 * Tests occurrence tables.
 *
 * @group date_recur
 */
class DateRecurOccurrenceTableTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $this
      ->installEntitySchema('entity_test');
  }

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'entity_test',
    'datetime',
    'datetime_range',
    'date_recur',
    'field',
    'user',
  ];

  /**
   * Ensure occurrence table is created and deleted for field storage entities.
   */
  public function testTableCreateDeleteOnFieldStorageCreate() {
    $tableName = 'date_recur__entity_test__abc';
    $actualExists = $this->container
      ->get('database')
      ->schema()
      ->tableExists($tableName);
    $this
      ->assertFalse($actualExists);
    $fieldStorage = FieldStorageConfig::create([
      'entity_type' => 'entity_test',
      'field_name' => 'abc',
      'type' => 'date_recur',
      'settings' => [
        'datetime_type' => DateRecurItem::DATETIME_TYPE_DATETIME,
        'occurrence_handler_plugin' => 'date_recur_occurrence_handler',
      ],
    ]);
    $fieldStorage
      ->save();
    $actualExists = $this->container
      ->get('database')
      ->schema()
      ->tableExists($tableName);
    $this
      ->assertTrue($actualExists);
    $fieldStorage
      ->delete();
    $actualExists = $this->container
      ->get('database')
      ->schema()
      ->tableExists($tableName);
    $this
      ->assertFalse($actualExists);
  }

}

Classes

Namesort descending Description
DateRecurOccurrenceTableTest Tests occurrence tables.