Loading core/lib/Drupal/Core/Validation/ConstraintManager.php +6 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Symfony\Component\Validator\Constraints\Blank; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Constraints\Image; use Symfony\Component\Validator\Constraints\NotBlank; /** Loading Loading @@ -116,6 +117,11 @@ public function registerDefinitions() { 'class' => Choice::class, 'type' => FALSE, ]); $this->getDiscovery()->setDefinition('Image', [ 'label' => new TranslatableMarkup('Image'), 'class' => Image::class, 'type' => ['string'], ]); } /** Loading core/modules/forum/tests/fixtures/drupal7.php +1 −1 Original line number Diff line number Diff line Loading @@ -30040,7 +30040,7 @@ )) ->values(array( 'name' => 'image_style_preview_image', 'value' => 's:33:"core/modules/image/testsample.png";', 'value' => 's:23:"core/misc/druplicon.png";', )) ->values(array( 'name' => 'image_toolkit', core/modules/image/config/schema/image.schema.yml +8 −0 Original line number Diff line number Diff line Loading @@ -87,10 +87,18 @@ image.effect.image_scale_and_crop: image.settings: type: config_object constraints: FullyValidatable: ~ mapping: preview_image: type: string label: 'Preview image' constraints: NotBlank: [] # We need to use Symfony's Image constraint because it will accept a file # path as a string, whereas the File module's FileIsImage constraint expects # a full file entity. Image: [] allow_insecure_derivatives: type: boolean label: 'Allow insecure image derivatives' Loading core/modules/image/tests/src/Kernel/Migrate/d7/MigrateImageSettingsTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ public function testMigration() { // These settings are not recommended... $this->assertTrue($config->get('allow_insecure_derivatives')); $this->assertTrue($config->get('suppress_itok_output')); $this->assertSame("core/modules/image/testsample.png", $config->get('preview_image')); $this->assertSame("core/misc/druplicon.png", $config->get('preview_image')); } } core/modules/image/tests/src/Kernel/SettingsConfigValidationTest.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\image\Kernel; use Drupal\Core\Config\Schema\SchemaIncompleteException; use Drupal\KernelTests\KernelTestBase; /** * @group image */ class SettingsConfigValidationTest extends KernelTestBase { /** * {@inheritdoc} */ protected static $modules = ['image']; /** * Tests that the preview_image setting must be an existing image file. */ public function testPreviewImagePathIsValidated(): void { $this->installConfig('image'); $file = sys_get_temp_dir() . '/fake_image.png'; file_put_contents($file, 'Not an image!'); $this->expectException(SchemaIncompleteException::class); $this->expectExceptionMessage('[preview_image] This file is not a valid image.'); $this->config('image.settings') ->set('preview_image', $file) ->save(); } } Loading
core/lib/Drupal/Core/Validation/ConstraintManager.php +6 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ use Symfony\Component\Validator\Constraints\Blank; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Constraints\Choice; use Symfony\Component\Validator\Constraints\Image; use Symfony\Component\Validator\Constraints\NotBlank; /** Loading Loading @@ -116,6 +117,11 @@ public function registerDefinitions() { 'class' => Choice::class, 'type' => FALSE, ]); $this->getDiscovery()->setDefinition('Image', [ 'label' => new TranslatableMarkup('Image'), 'class' => Image::class, 'type' => ['string'], ]); } /** Loading
core/modules/forum/tests/fixtures/drupal7.php +1 −1 Original line number Diff line number Diff line Loading @@ -30040,7 +30040,7 @@ )) ->values(array( 'name' => 'image_style_preview_image', 'value' => 's:33:"core/modules/image/testsample.png";', 'value' => 's:23:"core/misc/druplicon.png";', )) ->values(array( 'name' => 'image_toolkit',
core/modules/image/config/schema/image.schema.yml +8 −0 Original line number Diff line number Diff line Loading @@ -87,10 +87,18 @@ image.effect.image_scale_and_crop: image.settings: type: config_object constraints: FullyValidatable: ~ mapping: preview_image: type: string label: 'Preview image' constraints: NotBlank: [] # We need to use Symfony's Image constraint because it will accept a file # path as a string, whereas the File module's FileIsImage constraint expects # a full file entity. Image: [] allow_insecure_derivatives: type: boolean label: 'Allow insecure image derivatives' Loading
core/modules/image/tests/src/Kernel/Migrate/d7/MigrateImageSettingsTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ public function testMigration() { // These settings are not recommended... $this->assertTrue($config->get('allow_insecure_derivatives')); $this->assertTrue($config->get('suppress_itok_output')); $this->assertSame("core/modules/image/testsample.png", $config->get('preview_image')); $this->assertSame("core/misc/druplicon.png", $config->get('preview_image')); } }
core/modules/image/tests/src/Kernel/SettingsConfigValidationTest.php 0 → 100644 +34 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\image\Kernel; use Drupal\Core\Config\Schema\SchemaIncompleteException; use Drupal\KernelTests\KernelTestBase; /** * @group image */ class SettingsConfigValidationTest extends KernelTestBase { /** * {@inheritdoc} */ protected static $modules = ['image']; /** * Tests that the preview_image setting must be an existing image file. */ public function testPreviewImagePathIsValidated(): void { $this->installConfig('image'); $file = sys_get_temp_dir() . '/fake_image.png'; file_put_contents($file, 'Not an image!'); $this->expectException(SchemaIncompleteException::class); $this->expectExceptionMessage('[preview_image] This file is not a valid image.'); $this->config('image.settings') ->set('preview_image', $file) ->save(); } }