View source
<?php
namespace Drupal\Tests\iframe\Kernel;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\Tests\SchemaCheckTestTrait;
class IframeSchemaTest extends EntityKernelTestBase {
use SchemaCheckTestTrait;
public static $modules = [
'iframe',
'link',
];
public function testIframeSchema() {
$url = 'https://www.drupal.org/';
$typed_config = \Drupal::service('config.typed');
$field_storage = FieldStorageConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'type' => 'iframe',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
]);
$field_storage
->save();
$this
->assertConfigSchema($typed_config, 'field.storage.' . $field_storage
->id(), $field_storage
->toArray());
$field = FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'bundle' => 'entity_test',
]);
$entity_storage = \Drupal::entityTypeManager()
->getStorage('entity_test');
$field
->setDefaultValue([
[
'title' => 'Iframe title',
'class' => 'iframe-class',
'height' => '768',
'width' => '1024',
'frameborder' => '0',
'scrolling' => 'auto',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
'url' => $url,
],
]);
$field
->save();
$this
->assertConfigSchema($typed_config, 'field.field.' . $field
->id(), $field
->toArray());
$form_display = EntityFormDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
]);
$form_display
->setComponent('field_test', [
'weight' => 0,
'type' => 'iframe_urlwidthheight',
'settings' => [
'width' => '1024',
'height' => '768',
'class' => 'iframe-class',
'expose_class' => 0,
'frameborder' => '0',
'scrolling' => 'auto',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
],
'third_party_settings' => [],
])
->save();
$this
->assertConfigSchema($typed_config, 'core.entity_form_display.' . $form_display
->id(), $form_display
->toArray());
$form_display
->setComponent('field_test', [
'weight' => 0,
'type' => 'iframe_urlheight',
'settings' => [
'width' => '1024',
'height' => '768',
'class' => 'iframe-class',
'expose_class' => 0,
'frameborder' => '0',
'scrolling' => 'auto',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
],
'third_party_settings' => [],
])
->save();
$this
->assertConfigSchema($typed_config, 'core.entity_form_display.' . $form_display
->id(), $form_display
->toArray());
$form_display
->setComponent('field_test', [
'weight' => 0,
'type' => 'iframe_url',
'settings' => [
'width' => '1024',
'height' => '768',
'class' => 'iframe-class',
'expose_class' => 0,
'frameborder' => '0',
'scrolling' => 'auto',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
],
'third_party_settings' => [],
])
->save();
$this
->assertConfigSchema($typed_config, 'core.entity_form_display.' . $form_display
->id(), $form_display
->toArray());
$view_display = EntityViewDisplay::create([
'targetEntityType' => 'entity_test',
'bundle' => 'entity_test',
'mode' => 'default',
'status' => TRUE,
]);
$view_display
->setComponent('field_test', [
'weight' => 0,
'type' => 'iframe_default',
'label' => 'above',
'settings' => [
'url' => '',
'title' => '',
'width' => '',
'height' => '',
'class' => '',
'frameborder' => '0',
'scrolling' => '',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
],
'third_party_settings' => [],
])
->save();
$this
->assertConfigSchema($typed_config, 'core.entity_view_display.' . $view_display
->id(), $view_display
->toArray());
$view_display
->setComponent('field_test', [
'weight' => 0,
'type' => 'iframe_asurl',
'label' => 'above',
'settings' => [
'url' => '',
'title' => '',
'width' => '',
'height' => '',
'class' => '',
'frameborder' => '0',
'scrolling' => '',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
],
'third_party_settings' => [],
])
->save();
$this
->assertConfigSchema($typed_config, 'core.entity_view_display.' . $view_display
->id(), $view_display
->toArray());
$view_display
->setComponent('field_test', [
'weight' => 0,
'type' => 'iframe_asurlwithuri',
'label' => 'above',
'settings' => [
'url' => '',
'title' => '',
'width' => '',
'height' => '',
'class' => '',
'frameborder' => '0',
'scrolling' => '',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
],
'third_party_settings' => [],
])
->save();
$this
->assertConfigSchema($typed_config, 'core.entity_view_display.' . $view_display
->id(), $view_display
->toArray());
$view_display
->setComponent('field_test', [
'weight' => 0,
'type' => 'iframe_only',
'label' => 'above',
'settings' => [
'url' => '',
'title' => '',
'width' => '',
'height' => '',
'class' => '',
'frameborder' => '0',
'scrolling' => '',
'transparency' => '0',
'tokensupport' => '0',
'allowfullscreen' => '0',
],
'third_party_settings' => [],
])
->save();
$this
->assertConfigSchema($typed_config, 'core.entity_view_display.' . $view_display
->id(), $view_display
->toArray());
}
}