|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of Sulu. |
| 5 | + * |
| 6 | + * (c) Sulu GmbH |
| 7 | + * |
| 8 | + * This source file is subject to the MIT license that is bundled |
| 9 | + * with this source code in the file LICENSE. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Sulu\Bundle\FormBundle\Tests\Functional\Metadata; |
| 13 | + |
| 14 | +use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FieldMetadata; |
| 15 | +use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\FormMetadata; |
| 16 | +use Sulu\Bundle\AdminBundle\Metadata\FormMetadata\SectionMetadata; |
| 17 | +use Sulu\Bundle\TestBundle\Testing\SuluTestCase; |
| 18 | + |
| 19 | +class DynamicFormMetadataLoaderTest extends SuluTestCase |
| 20 | +{ |
| 21 | + private $dynamicFormMetadataLoader; |
| 22 | + |
| 23 | + protected function setUp(): void |
| 24 | + { |
| 25 | + $this->dynamicFormMetadataLoader = $this->getContainer()->get('sulu_form_test.dynamic_form_metadata_loader'); |
| 26 | + } |
| 27 | + |
| 28 | + public function testGetMetadataEnglish(): void |
| 29 | + { |
| 30 | + $formMetadata = $this->dynamicFormMetadataLoader->getMetadata('form_details', 'en'); |
| 31 | + |
| 32 | + $this->assertInstanceOf(FormMetadata::class, $formMetadata); |
| 33 | + $this->assertEquals('form_details', $formMetadata->getKey()); |
| 34 | + $this->assertCount(5, $formMetadata->getItems()); |
| 35 | + $this->assertContains('title', \array_keys($formMetadata->getItems())); |
| 36 | + $this->assertContains('formFields', \array_keys($formMetadata->getItems())); |
| 37 | + $this->assertContains('websiteConfiguration', \array_keys($formMetadata->getItems())); |
| 38 | + $this->assertContains('emailConfiguration', \array_keys($formMetadata->getItems())); |
| 39 | + $this->assertContains('receivers', \array_keys($formMetadata->getItems())); |
| 40 | + |
| 41 | + $formFields = $formMetadata->getItems()['formFields']; |
| 42 | + $this->assertInstanceOf(SectionMetadata::class, $formFields); |
| 43 | + $this->assertCount(1, $formFields->getItems()); |
| 44 | + $this->assertContains('fields', \array_keys($formFields->getItems())); |
| 45 | + $this->assertEquals('section', $formFields->getType()); |
| 46 | + $this->assertEquals('formFields', $formFields->getName()); |
| 47 | + $this->assertEquals('Form Fields', $formFields->getLabel()); |
| 48 | + |
| 49 | + $fields = $formFields->getItems()['fields']; |
| 50 | + $this->assertInstanceOf(FieldMetadata::class, $fields); |
| 51 | + $this->assertCount(28, $fields->getTypes()); |
| 52 | + $this->assertEquals('fields', $fields->getName()); |
| 53 | + $this->assertEquals('block', $fields->getType()); |
| 54 | + $this->assertEquals('attachment', $fields->getDefaultType()); |
| 55 | + $this->assertEquals([ |
| 56 | + 'attachment', |
| 57 | + 'recaptcha', |
| 58 | + 'checkbox', |
| 59 | + 'checkboxMultiple', |
| 60 | + 'city', |
| 61 | + 'company', |
| 62 | + 'country', |
| 63 | + 'date', |
| 64 | + 'email', |
| 65 | + 'fax', |
| 66 | + 'firstName', |
| 67 | + 'freeText', |
| 68 | + 'function', |
| 69 | + 'headline', |
| 70 | + 'hidden', |
| 71 | + 'lastName', |
| 72 | + 'textarea', |
| 73 | + 'phone', |
| 74 | + 'radioButtons', |
| 75 | + 'salutation', |
| 76 | + 'dropdown', |
| 77 | + 'dropdownMultiple', |
| 78 | + 'text', |
| 79 | + 'spacer', |
| 80 | + 'state', |
| 81 | + 'street', |
| 82 | + 'title', |
| 83 | + 'zip', |
| 84 | + ], \array_keys($fields->getTypes())); |
| 85 | + } |
| 86 | + |
| 87 | + public function testGetMetadataGerman(): void |
| 88 | + { |
| 89 | + $formMetadata = $this->dynamicFormMetadataLoader->getMetadata('form_details', 'de'); |
| 90 | + |
| 91 | + $this->assertInstanceOf(FormMetadata::class, $formMetadata); |
| 92 | + $this->assertEquals('form_details', $formMetadata->getKey()); |
| 93 | + $this->assertCount(5, $formMetadata->getItems()); |
| 94 | + $this->assertContains('title', \array_keys($formMetadata->getItems())); |
| 95 | + $this->assertContains('formFields', \array_keys($formMetadata->getItems())); |
| 96 | + $this->assertContains('websiteConfiguration', \array_keys($formMetadata->getItems())); |
| 97 | + $this->assertContains('emailConfiguration', \array_keys($formMetadata->getItems())); |
| 98 | + $this->assertContains('receivers', \array_keys($formMetadata->getItems())); |
| 99 | + |
| 100 | + $formFields = $formMetadata->getItems()['formFields']; |
| 101 | + $this->assertInstanceOf(SectionMetadata::class, $formFields); |
| 102 | + $this->assertCount(1, $formFields->getItems()); |
| 103 | + $this->assertContains('fields', \array_keys($formFields->getItems())); |
| 104 | + $this->assertEquals('section', $formFields->getType()); |
| 105 | + $this->assertEquals('formFields', $formFields->getName()); |
| 106 | + $this->assertEquals('Formular Felder', $formFields->getLabel()); |
| 107 | + |
| 108 | + $fields = $formFields->getItems()['fields']; |
| 109 | + $this->assertInstanceOf(FieldMetadata::class, $fields); |
| 110 | + $this->assertCount(28, $fields->getTypes()); |
| 111 | + $this->assertEquals('fields', $fields->getName()); |
| 112 | + $this->assertEquals('block', $fields->getType()); |
| 113 | + $this->assertEquals('attachment', $fields->getDefaultType()); |
| 114 | + $this->assertEquals([ |
| 115 | + 'attachment', |
| 116 | + 'salutation', |
| 117 | + 'state', |
| 118 | + 'recaptcha', |
| 119 | + 'checkbox', |
| 120 | + 'checkboxMultiple', |
| 121 | + 'date', |
| 122 | + 'dropdown', |
| 123 | + 'dropdownMultiple', |
| 124 | + 'email', |
| 125 | + 'text', |
| 126 | + 'fax', |
| 127 | + 'company', |
| 128 | + 'freeText', |
| 129 | + 'function', |
| 130 | + 'hidden', |
| 131 | + 'country', |
| 132 | + 'spacer', |
| 133 | + 'textarea', |
| 134 | + 'lastName', |
| 135 | + 'zip', |
| 136 | + 'radioButtons', |
| 137 | + 'city', |
| 138 | + 'street', |
| 139 | + 'phone', |
| 140 | + 'title', |
| 141 | + 'firstName', |
| 142 | + 'headline', |
| 143 | + ], \array_keys($fields->getTypes())); |
| 144 | + } |
| 145 | + |
| 146 | + public function testGetMetadataLabelsEnglish(): void |
| 147 | + { |
| 148 | + $formMetadata = $this->dynamicFormMetadataLoader->getMetadata('form_details', 'en'); |
| 149 | + |
| 150 | + $this->assertInstanceOf(FormMetadata::class, $formMetadata); |
| 151 | + $this->assertEquals('form_details', $formMetadata->getKey()); |
| 152 | + $this->assertCount(5, $formMetadata->getItems()); |
| 153 | + $this->assertEquals('Title', $formMetadata->getItems()['title']->getLabel()); |
| 154 | + $this->assertEquals('Form Fields', $formMetadata->getItems()['formFields']->getLabel()); |
| 155 | + $this->assertEquals('Website Configuration', $formMetadata->getItems()['websiteConfiguration'] |
| 156 | + ->getLabel()); |
| 157 | + $this->assertEquals('E-Mail Configuration', $formMetadata->getItems()['emailConfiguration']->getLabel()); |
| 158 | + $this->assertEquals('Receivers', $formMetadata->getItems()['receivers']->getLabel()); |
| 159 | + } |
| 160 | + |
| 161 | + public function testGetMetadataLabelsGerman(): void |
| 162 | + { |
| 163 | + $formMetadata = $this->dynamicFormMetadataLoader->getMetadata('form_details', 'de'); |
| 164 | + |
| 165 | + $this->assertInstanceOf(FormMetadata::class, $formMetadata); |
| 166 | + $this->assertEquals('form_details', $formMetadata->getKey()); |
| 167 | + $this->assertCount(5, $formMetadata->getItems()); |
| 168 | + $this->assertEquals('Titel', $formMetadata->getItems()['title']->getLabel()); |
| 169 | + $this->assertEquals('Formular Felder', $formMetadata->getItems()['formFields']->getLabel()); |
| 170 | + $this->assertEquals('Website Konfiguration', $formMetadata->getItems()['websiteConfiguration'] |
| 171 | + ->getLabel()); |
| 172 | + $this->assertEquals('E-Mail Konfiguration', $formMetadata->getItems()['emailConfiguration']->getLabel()); |
| 173 | + $this->assertEquals('Empfänger', $formMetadata->getItems()['receivers']->getLabel()); |
| 174 | + } |
| 175 | + |
| 176 | + public function testGetMetadataAttachmentEnglish(): void |
| 177 | + { |
| 178 | + $formMetadata = $this->dynamicFormMetadataLoader->getMetadata('form_details', 'en'); |
| 179 | + |
| 180 | + $this->assertInstanceOf(FormMetadata::class, $formMetadata); |
| 181 | + $this->assertCount(5, $formMetadata->getItems()); |
| 182 | + |
| 183 | + $formFields = $formMetadata->getItems()['formFields']; |
| 184 | + $this->assertInstanceOf(SectionMetadata::class, $formFields); |
| 185 | + $this->assertCount(1, $formFields->getItems()); |
| 186 | + |
| 187 | + $fields = $formFields->getItems()['fields']; |
| 188 | + $this->assertInstanceOf(FieldMetadata::class, $fields); |
| 189 | + $this->assertCount(28, $fields->getTypes()); |
| 190 | + |
| 191 | + $attachment = $fields->getTypes()['attachment']; |
| 192 | + $this->assertInstanceOf(FormMetadata::class, $attachment); |
| 193 | + $this->assertEquals('attachment', $attachment->getKey()); |
| 194 | + $this->assertEquals('Attachment', $attachment->getTitle('en')); |
| 195 | + $this->assertCount(6, $attachment->getItems()); |
| 196 | + |
| 197 | + $this->arrayHasKey('required', $attachment->getItems()); |
| 198 | + $this->assertEquals('Required field', $attachment->getItems()['required']->getLabel('en')); |
| 199 | + $this->assertEquals('checkbox', $attachment->getItems()['required']->getType()); |
| 200 | + $this->assertEquals(6, $attachment->getItems()['required']->getColspan()); |
| 201 | + |
| 202 | + $this->arrayHasKey('width', $attachment->getItems()); |
| 203 | + $this->assertEquals('Width', $attachment->getItems()['width']->getLabel('en')); |
| 204 | + $this->assertEquals('single_select', $attachment->getItems()['width']->getType()); |
| 205 | + $this->assertEquals(6, $attachment->getItems()['width']->getColspan()); |
| 206 | + $this->assertCount(3, $attachment->getItems()['width']->getOptions()); |
| 207 | + $this->arrayHasKey('label', $attachment->getItems()['width']->getOptions()); |
| 208 | + $this->arrayHasKey('default_value', $attachment->getItems()['width']->getOptions()); |
| 209 | + $this->arrayHasKey('values', $attachment->getItems()['width']->getOptions()); |
| 210 | + $this->assertCount(8, $attachment->getItems()['width']->getOptions()['values']->getValue()); |
| 211 | + |
| 212 | + $this->arrayHasKey('title', $attachment->getItems()); |
| 213 | + $this->assertEquals('Title', $attachment->getItems()['title']->getLabel('en')); |
| 214 | + $this->assertEquals('text_editor', $attachment->getItems()['title']->getType()); |
| 215 | + $this->assertEquals(12, $attachment->getItems()['title']->getColspan()); |
| 216 | + |
| 217 | + $this->arrayHasKey('shortTitle', $attachment->getItems()); |
| 218 | + $this->assertEquals('Short title', $attachment->getItems()['shortTitle']->getLabel('en')); |
| 219 | + $this->assertEquals('text_line', $attachment->getItems()['shortTitle']->getType()); |
| 220 | + $this->assertEquals(12, $attachment->getItems()['shortTitle']->getColspan()); |
| 221 | + $this->assertEquals( |
| 222 | + 'Optional title of field, for example in notification mail.', |
| 223 | + $attachment->getItems()['shortTitle']->getDescription() |
| 224 | + ); |
| 225 | + |
| 226 | + $this->arrayHasKey('options/type', $attachment->getItems()); |
| 227 | + $this->assertEquals('Restrict file types', $attachment->getItems()['options/type']->getLabel('en')); |
| 228 | + $this->assertEquals('select', $attachment->getItems()['options/type']->getType()); |
| 229 | + $this->assertEquals('No choice will allow all file types.', $attachment->getItems()['options/type'] |
| 230 | + ->getDescription()); |
| 231 | + $this->assertEquals(6, $attachment->getItems()['options/type']->getColspan()); |
| 232 | + $this->assertCount(1, $attachment->getItems()['options/type']->getOptions()); |
| 233 | + $this->arrayHasKey('values', $attachment->getItems()['options/type']->getOptions()); |
| 234 | + $this->assertCount(3, $attachment->getItems()['options/type']->getOptions()['values']->getValue()); |
| 235 | + |
| 236 | + $this->arrayHasKey('options/max', $attachment->getItems()); |
| 237 | + $this->assertEquals('Maximum amount', $attachment->getItems()['options/max']->getLabel('en')); |
| 238 | + $this->assertEquals('number', $attachment->getItems()['options/max']->getType()); |
| 239 | + $this->assertEquals(6, $attachment->getItems()['options/max']->getColspan()); |
| 240 | + |
| 241 | + $this->assertTrue(\property_exists($attachment, 'schema')); |
| 242 | + $this->assertTrue(\property_exists($attachment, 'key')); |
| 243 | + } |
| 244 | + |
| 245 | + public function testGetMetadataAttachmentGerman(): void |
| 246 | + { |
| 247 | + $formMetadata = $this->dynamicFormMetadataLoader->getMetadata('form_details', 'de'); |
| 248 | + |
| 249 | + $this->assertInstanceOf(FormMetadata::class, $formMetadata); |
| 250 | + $this->assertCount(5, $formMetadata->getItems()); |
| 251 | + |
| 252 | + $formFields = $formMetadata->getItems()['formFields']; |
| 253 | + $this->assertInstanceOf(SectionMetadata::class, $formFields); |
| 254 | + $this->assertCount(1, $formFields->getItems()); |
| 255 | + |
| 256 | + $fields = $formFields->getItems()['fields']; |
| 257 | + $this->assertInstanceOf(FieldMetadata::class, $fields); |
| 258 | + $this->assertCount(28, $fields->getTypes()); |
| 259 | + |
| 260 | + $attachment = $fields->getTypes()['attachment']; |
| 261 | + $this->assertInstanceOf(FormMetadata::class, $attachment); |
| 262 | + $this->assertEquals('attachment', $attachment->getKey()); |
| 263 | + $this->assertEquals('Anhang', $attachment->getTitle('de')); |
| 264 | + |
| 265 | + $this->arrayHasKey('required', $attachment->getItems()); |
| 266 | + $this->assertEquals('Pflichtfeld', $attachment->getItems()['required']->getLabel('de')); |
| 267 | + $this->assertEquals('checkbox', $attachment->getItems()['required']->getType()); |
| 268 | + |
| 269 | + $this->arrayHasKey('width', $attachment->getItems()); |
| 270 | + $this->assertEquals('Breite', $attachment->getItems()['width']->getLabel('de')); |
| 271 | + $this->assertEquals('single_select', $attachment->getItems()['width']->getType()); |
| 272 | + |
| 273 | + $this->arrayHasKey('title', $attachment->getItems()); |
| 274 | + $this->assertEquals('Titel', $attachment->getItems()['title']->getLabel('de')); |
| 275 | + $this->assertEquals('text_editor', $attachment->getItems()['title']->getType()); |
| 276 | + |
| 277 | + $this->arrayHasKey('shortTitle', $attachment->getItems()); |
| 278 | + $this->assertEquals('Kurztitel', $attachment->getItems()['shortTitle']->getLabel('de')); |
| 279 | + $this->assertEquals('text_line', $attachment->getItems()['shortTitle']->getType()); |
| 280 | + $this->assertEquals( |
| 281 | + 'Optionaler Titel des Feldes, z.B. in der Benachrichtigungs-Email.', |
| 282 | + $attachment->getItems()['shortTitle']->getDescription() |
| 283 | + ); |
| 284 | + |
| 285 | + self::assertProperty($attachment->getItems(), 'options/type', 'Dateitypen beschränken', 'select', 'de'); |
| 286 | + $this->assertEquals( |
| 287 | + 'Bei keiner Auswahl sind alle Dateitypen möglich.', |
| 288 | + $attachment-> getItems()['options/type'] ->getDescription(), |
| 289 | + ); |
| 290 | + |
| 291 | + $this->arrayHasKey('options/max', $attachment->getItems()); |
| 292 | + $this->assertEquals('Maximale Anzahl', $attachment->getItems()['options/max']->getLabel('de')); |
| 293 | + } |
| 294 | + |
| 295 | + private function assertProperty(array $data, string $propertyName, string $label, string $type, string $locale): void { |
| 296 | + $this->arrayHasKey($propertyName, $data); |
| 297 | + $this->assertEquals($label, $data[$propertyName]->getLabel($locale)); |
| 298 | + $this->assertEquals($type, $data[$propertyName]->getType()); |
| 299 | + |
| 300 | + } |
| 301 | +} |
0 commit comments