Skip to content
Snippets Groups Projects
Commit 3f32cb01 authored by Pucci, Murilo henrique [GTSBR NON-J&J]'s avatar Pucci, Murilo henrique [GTSBR NON-J&J]
Browse files

Issue #3277710 by murilohp: Add tests for the field formatter

parent e22fbf2f
No related branches found
No related tags found
No related merge requests found
# @file
# Schema for the configuration files of the Lightgallery module.
field.formatter.settings.lightgallery:
type: mapping
label: ''
mapping:
lightgallery_core:
type: mapping
mapping:
thumb_field:
type: string
label: 'Thumbnail field'
image_field:
type: string
label: 'Image field'
title:
type: string
label: 'Title'
thumb_image_style:
type: string
label: 'Thumbnail image style'
lightgallery_image_style:
type: string
label: 'Lightgallery image style'
title_source:
type: string
label: Title Source
closable:
type: integer
label: 'Closable'
mode:
type: integer
label: 'Mode'
preload:
type: integer
label: 'Preload'
loop:
type: integer
label: 'Loop'
esc_key:
type: integer
label: 'Escape key'
key_press:
type: integer
label: 'Key press'
controls:
type: integer
label: 'Controls'
mouse_wheel:
type: integer
label: 'Mouse wheel'
download:
type: integer
label: 'Download'
counter:
type: integer
label: 'Counter'
drag:
type: integer
label: 'Drag'
touch:
type: integer
label: 'Touch'
lightgallery_thumbs:
type: mapping
mapping:
thumbnails:
type: integer
label: 'Use thumbnails'
animate_thumb:
type: integer
label: 'Animate thumbnails'
current_pager_position:
type: string
label: 'Position'
thumb_width:
type: string
label: 'Width'
thumb_cont_height:
type: string
label: 'Height'
lightgallery_autoplay:
type: mapping
mapping:
autoplay:
type: integer
label: 'Autoplay'
pause:
type: string
label: 'Pause'
progress_bar:
type: string
label: 'Progress bar'
autoplay_controls:
type: string
label: 'Autoplay controls'
lightgallery_full_screen:
type: mapping
mapping:
full_screen:
type: integer
label: 'Full screen'
lightgallery_pager:
type: mapping
mapping:
pager:
type: integer
label: 'Pager'
lightgallery_zoom:
type: mapping
mapping:
zoom:
type: integer
label: 'Pager'
scale:
type: string
label: 'Scale'
lightgallery_hash:
type: mapping
mapping:
hash:
type: integer
label: 'Hash'
gallery_id:
type: string
label: 'Gallery ID'
<?php
namespace Drupal\Tests\lightgallery\Kernel\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\file\Entity\File;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
/**
* Test the lightgallery field formatter plugin.
*
* @group lightgallery
*
* @coversDefaultClass \Drupal\lightgallery\Plugin\Field\FieldFormatter\LightgalleryFormatter
*/
class LightgalleryFormatterTest extends FieldKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = ['file', 'image', 'lightgallery', 'entity_test'];
/**
* The entity type test.
*
* @var string
*/
protected $entityType;
/**
* The entity test bundle.
*
* @var string
*/
protected $bundle;
/**
* The image test field name.
*
* @var string
*/
protected $fieldName;
/**
* The field display.
*
* @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface
*/
protected $display;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installConfig(['field']);
$this->installEntitySchema('entity_test');
$this->installEntitySchema('file');
$this->installSchema('file', ['file_usage']);
$this->entityType = 'entity_test';
$this->bundle = $this->entityType;
$this->fieldName = mb_strtolower($this->randomMachineName());
FieldStorageConfig::create([
'entity_type' => $this->entityType,
'field_name' => $this->fieldName,
'type' => 'image',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
])->save();
FieldConfig::create([
'entity_type' => $this->entityType,
'field_name' => $this->fieldName,
'bundle' => $this->bundle,
'settings' => [
'file_extensions' => 'png',
],
])->save();
$this->display = \Drupal::service('entity_display.repository')
->getViewDisplay($this->entityType, $this->bundle)
->setComponent($this->fieldName, [
'type' => 'lightgallery',
]);
$this->display->save();
}
/**
* Tests lightgallery fomart.
*/
public function testLightgalleryImageFormatter() {
// Install the default image styles.
$this->installConfig(['image']);
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = $this->container->get('file_system');
$file_system->copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://logo.png');
$file_system->copy(DRUPAL_ROOT . '/core/misc/tree.png', 'public://tree.png');
// Create a logo file.
$drupal_logo_file = File::create([
'uri' => 'public://logo.png',
]);
$drupal_logo_file->save();
// Create the tree file for testing purposes.
$tree_file = File::create([
'uri' => 'public://tree.png',
]);
$tree_file->save();
$entity = EntityTest::create([
'name' => $this->randomMachineName(),
$this->fieldName => [$drupal_logo_file, $tree_file],
]);
$entity->save();
// Render a page.
$build = $this->display->build($entity);
$content = $this->container->get('renderer')->renderRoot($build)->__toString();
$this->assertStringContainsString('<div class="lightgallery-wrapper">', $content);
$this->assertStringContainsString('<img class="img-responsive"', $content);
$this->assertStringContainsString('<ul class="lightgallery"', $content);
}
}
<?php
namespace Drupal\Tests\lightgallery\Kernel;
namespace Drupal\Tests\lightgallery\Kernel\Plugin\views\style;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
......@@ -11,13 +11,13 @@ use Drupal\views\Tests\ViewTestData;
use Drupal\views\Views;
/**
* Tests the views tree list style plugin.
* Test the view lightgallery style plugin.
*
* @group lightgallery
*
* @coversDefaultClass \Drupal\lightgallery\Plugin\views\style\LightGallery
*/
class StyleLightGalleryTest extends ViewsKernelTestBase {
class LightgalleryTest extends ViewsKernelTestBase {
/**
* {@inheritdoc}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment