DateRecurOccurrenceTableAttachedTest.php in Recurring Dates Field 3.0.x
File
tests/src/Kernel/DateRecurOccurrenceTableAttachedTest.php
View source
<?php
namespace Drupal\Tests\date_recur\Kernel;
use Drupal\date_recur\Plugin\Field\FieldType\DateRecurItem;
use Drupal\entity_test\Entity\EntityTestRev;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
class DateRecurOccurrenceTableAttachedTest extends DateRecurOccurrenceTableTest {
protected function setUp() : void {
parent::setUp();
$this->testEntityType = 'entity_test_rev';
$this
->installEntitySchema($this->testEntityType);
$fieldStorage = FieldStorageConfig::create([
'entity_type' => $this->testEntityType,
'field_name' => 'abc',
'type' => 'date_recur',
'settings' => [
'datetime_type' => DateRecurItem::DATETIME_TYPE_DATETIME,
],
]);
$fieldStorage
->save();
$this->fieldDefinition = $fieldStorage;
$this->fieldName = 'abc';
$fieldConfig = FieldConfig::create([
'field_name' => 'abc',
'entity_type' => $this->testEntityType,
'bundle' => $this->testEntityType,
'settings' => [],
]);
$fieldConfig
->save();
}
public function testTableCreateDeleteOnFieldStorageCreate() {
$tableName = 'date_recur__entity_test_rev__abc123';
$actualExists = $this->container
->get('database')
->schema()
->tableExists($tableName);
$this
->assertFalse($actualExists);
$fieldStorage = FieldStorageConfig::create([
'entity_type' => $this->testEntityType,
'field_name' => 'abc123',
'type' => 'date_recur',
'settings' => [
'datetime_type' => DateRecurItem::DATETIME_TYPE_DATETIME,
],
]);
$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);
}
protected function createEntity() {
return EntityTestRev::create();
}
}