Yaffs site version 1.1
[yaffs-website] / web / modules / contrib / slick / tests / src / Kernel / SlickFileFormatterTest.php
1 <?php
2
3 namespace Drupal\Tests\slick\Kernel;
4
5 use Drupal\Core\Form\FormState;
6 use Drupal\Tests\blazy\Kernel\BlazyKernelTestBase;
7 use Drupal\Tests\slick\Traits\SlickUnitTestTrait;
8
9 /**
10  * Tests the Slick field rendering using the text field type.
11  *
12  * @coversDefaultClass \Drupal\slick\Plugin\Field\FieldFormatter\SlickFileFormatter
13  * @group slick
14  */
15 class SlickFileFormatterTest extends BlazyKernelTestBase {
16
17   use SlickUnitTestTrait;
18
19   /**
20    * {@inheritdoc}
21    */
22   public static $modules = [
23     'system',
24     'user',
25     'field',
26     'file',
27     'image',
28     'filter',
29     'node',
30     'text',
31     'blazy',
32     'slick',
33     'slick_test',
34   ];
35
36   /**
37    * {@inheritdoc}
38    */
39   protected function setUp() {
40     parent::setUp();
41
42     $this->installConfig(static::$modules);
43     $this->installEntitySchema('slick');
44
45     $this->testFieldName  = 'field_file_multiple';
46     $this->testEmptyName  = 'field_file_multiple_empty';
47     $this->testFieldType  = 'image';
48     $this->testPluginId   = 'slick_file';
49     $this->maxItems       = 7;
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');
54
55     // Create contents.
56     $bundle = $this->bundle;
57
58     $data = [
59       'field_name' => $this->testEmptyName,
60       'field_type' => 'image',
61     ];
62
63     $this->setUpContentTypeTest($bundle, $data);
64     $this->setUpContentWithItems($bundle);
65
66     $this->display = $this->setUpFormatterDisplay($bundle);
67
68     $data['plugin_id'] = $this->testPluginId;
69     $this->displayEmpty = $this->setUpFormatterDisplay($bundle, $data);
70
71     $this->formatterInstance = $this->getFormatterInstance();
72   }
73
74   /**
75    * Tests the Slick formatters.
76    */
77   public function testSlickFormatter() {
78     $entity = $this->entity;
79
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);
83
84     $component = $this->display->getComponent($this->testFieldName);
85     $this->assertEquals($this->testPluginId, $component['type']);
86
87     $render = $this->slickManager->getRenderer()->renderRoot($build);
88     $this->assertNotEmpty($render);
89
90     $render_empty = $this->slickManager->getRenderer()->renderRoot($build_empty[$this->testEmptyName]);
91     $this->assertEmpty($render_empty);
92
93     $scopes = $this->formatterInstance->getScopedFormElements();
94     $this->assertEquals($this->testPluginId, $scopes['plugin_id']);
95
96     $settings = $this->formatterInstance->buildSettings();
97     $this->assertEquals(TRUE, $settings['blazy']);
98
99     $form = [];
100     $form_state = new FormState();
101     $element = $this->formatterInstance->settingsForm($form, $form_state);
102     $this->assertArrayHasKey('optionset', $element);
103   }
104
105 }