3 namespace Drupal\Tests\slick\Kernel;
5 use Drupal\Core\Form\FormState;
6 use Drupal\Tests\blazy\Kernel\BlazyKernelTestBase;
7 use Drupal\Tests\slick\Traits\SlickUnitTestTrait;
10 * Tests the Slick field rendering using the text field type.
12 * @coversDefaultClass \Drupal\slick\Plugin\Field\FieldFormatter\SlickFileFormatter
15 class SlickFileFormatterTest extends BlazyKernelTestBase {
17 use SlickUnitTestTrait;
22 public static $modules = [
39 protected function setUp() {
42 $this->installConfig(static::$modules);
43 $this->installEntitySchema('slick');
45 $this->testFieldName = 'field_file_multiple';
46 $this->testEmptyName = 'field_file_multiple_empty';
47 $this->testFieldType = 'image';
48 $this->testPluginId = 'slick_file';
50 $this->maxParagraphs = 2;
51 $this->slickAdmin = $this->container->get('slick.admin');
52 $this->slickManager = $this->container->get('slick.manager');
53 $this->slickFormatter = $this->container->get('slick.formatter');
56 $bundle = $this->bundle;
59 'field_name' => $this->testEmptyName,
60 'field_type' => 'image',
63 $this->setUpContentTypeTest($bundle, $data);
64 $this->setUpContentWithItems($bundle);
66 $this->display = $this->setUpFormatterDisplay($bundle);
68 $data['plugin_id'] = $this->testPluginId;
69 $this->displayEmpty = $this->setUpFormatterDisplay($bundle, $data);
71 $this->formatterInstance = $this->getFormatterInstance();
75 * Tests the Slick formatters.
77 public function testSlickFormatter() {
78 $entity = $this->entity;
80 // Generate the render array to verify if the cache tags are as expected.
81 $build = $this->display->build($entity);
82 $build_empty = $this->displayEmpty->build($entity);
84 $component = $this->display->getComponent($this->testFieldName);
85 $this->assertEquals($this->testPluginId, $component['type']);
87 $render = $this->slickManager->getRenderer()->renderRoot($build);
88 $this->assertNotEmpty($render);
90 $render_empty = $this->slickManager->getRenderer()->renderRoot($build_empty[$this->testEmptyName]);
91 $this->assertEmpty($render_empty);
93 $scopes = $this->formatterInstance->getScopedFormElements();
94 $this->assertEquals($this->testPluginId, $scopes['plugin_id']);
96 $settings = $this->formatterInstance->buildSettings();
97 $this->assertEquals(TRUE, $settings['blazy']);
100 $form_state = new FormState();
101 $element = $this->formatterInstance->settingsForm($form, $form_state);
102 $this->assertArrayHasKey('optionset', $element);