Loading core/.phpstan-baseline.php +0 −348 File changed.Preview size limit exceeded, changes collapsed. Show changes core/modules/field/tests/src/Traits/EntityReferenceFieldCreationTrait.php +1 −1 Changes for core/modules/field/tests/src/Traits/EntityReferenceFieldCreationTrait.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ trait EntityReferenceFieldCreationTrait { * * @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm() */ protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1) { protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1): void { // Look for or add the specified field to the requested entity bundle. if (!FieldStorageConfig::loadByName($entity_type, $field_name)) { FieldStorageConfig::create([ Loading core/modules/file/tests/src/Kernel/Plugin/EntityReference/FileSelectionTest.php 0 → 100644 +89 −0 Changes for core/modules/file/tests/src/Kernel/Plugin/EntityReference/FileSelectionTest.php: 89 added lines, 0 removed lines. Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\file\Kernel\Plugin\EntityReference; use Drupal\Component\Utility\Html; use Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait; /** * Tests file selection plugin. * * @group file */ class FileSelectionTest extends KernelTestBase { use EntityReferenceFieldCreationTrait; /** * {@inheritdoc} */ protected static $modules = ['entity_test', 'file', 'user', 'field']; /** * The selection handler. * * @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface */ protected SelectionInterface $selectionHandler; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->installEntitySchema('entity_test'); $this->installEntitySchema('file'); $this->installEntitySchema('user'); $field_name = $this->randomMachineName(); $this->createEntityReferenceField('entity_test', 'entity_test', $field_name, $this->randomString(), 'file'); $field_config = FieldConfig::loadByName('entity_test', 'entity_test', $field_name); $this->selectionHandler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($field_config); } /** * Tests that entity reference should refer permanent files. */ public function testCanReferToPermanentFiles(): void { $expected_result = []; \file_put_contents('public://file.png', str_repeat('a', 10)); $file = File::create([ 'uri' => 'public://file.png', 'filename' => 'file.png', 'label' => $this->randomMachineName(), 'status' => FileInterface::STATUS_PERMANENT, ]); $file->save(); $expected_result[$file->id()] = Html::escape($file->label()); // Assert the result. $result = $this->selectionHandler->getReferenceableEntities(); self::assertEquals($expected_result, $result['file'], 'Permanent files can be referred by handler.'); } /** * Tests that entity reference should avoid referring to temporary files. */ public function testCanNotReferToTemporaryFiles(): void { \file_put_contents('public://test.png', str_repeat('b', 10)); $file = File::create([ 'uri' => 'public://test.png', 'filename' => 'test.png', 'label' => $this->randomMachineName(), ]); $file->save(); // Assert the result. $result = $this->selectionHandler->getReferenceableEntities(); self::assertEmpty($result, 'Temporary files can not be referred by handler.'); } } Loading
core/.phpstan-baseline.php +0 −348 File changed.Preview size limit exceeded, changes collapsed. Show changes
core/modules/field/tests/src/Traits/EntityReferenceFieldCreationTrait.php +1 −1 Changes for core/modules/field/tests/src/Traits/EntityReferenceFieldCreationTrait.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ trait EntityReferenceFieldCreationTrait { * * @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\SelectionBase::buildConfigurationForm() */ protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1) { protected function createEntityReferenceField($entity_type, $bundle, $field_name, $field_label, $target_entity_type, $selection_handler = 'default', $selection_handler_settings = [], $cardinality = 1): void { // Look for or add the specified field to the requested entity bundle. if (!FieldStorageConfig::loadByName($entity_type, $field_name)) { FieldStorageConfig::create([ Loading
core/modules/file/tests/src/Kernel/Plugin/EntityReference/FileSelectionTest.php 0 → 100644 +89 −0 Changes for core/modules/file/tests/src/Kernel/Plugin/EntityReference/FileSelectionTest.php: 89 added lines, 0 removed lines. Original line number Diff line number Diff line <?php declare(strict_types=1); namespace Drupal\Tests\file\Kernel\Plugin\EntityReference; use Drupal\Component\Utility\Html; use Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface; use Drupal\field\Entity\FieldConfig; use Drupal\file\Entity\File; use Drupal\file\FileInterface; use Drupal\KernelTests\KernelTestBase; use Drupal\Tests\field\Traits\EntityReferenceFieldCreationTrait; /** * Tests file selection plugin. * * @group file */ class FileSelectionTest extends KernelTestBase { use EntityReferenceFieldCreationTrait; /** * {@inheritdoc} */ protected static $modules = ['entity_test', 'file', 'user', 'field']; /** * The selection handler. * * @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface */ protected SelectionInterface $selectionHandler; /** * {@inheritdoc} */ protected function setUp(): void { parent::setUp(); $this->installEntitySchema('entity_test'); $this->installEntitySchema('file'); $this->installEntitySchema('user'); $field_name = $this->randomMachineName(); $this->createEntityReferenceField('entity_test', 'entity_test', $field_name, $this->randomString(), 'file'); $field_config = FieldConfig::loadByName('entity_test', 'entity_test', $field_name); $this->selectionHandler = $this->container->get('plugin.manager.entity_reference_selection')->getSelectionHandler($field_config); } /** * Tests that entity reference should refer permanent files. */ public function testCanReferToPermanentFiles(): void { $expected_result = []; \file_put_contents('public://file.png', str_repeat('a', 10)); $file = File::create([ 'uri' => 'public://file.png', 'filename' => 'file.png', 'label' => $this->randomMachineName(), 'status' => FileInterface::STATUS_PERMANENT, ]); $file->save(); $expected_result[$file->id()] = Html::escape($file->label()); // Assert the result. $result = $this->selectionHandler->getReferenceableEntities(); self::assertEquals($expected_result, $result['file'], 'Permanent files can be referred by handler.'); } /** * Tests that entity reference should avoid referring to temporary files. */ public function testCanNotReferToTemporaryFiles(): void { \file_put_contents('public://test.png', str_repeat('b', 10)); $file = File::create([ 'uri' => 'public://test.png', 'filename' => 'test.png', 'label' => $this->randomMachineName(), ]); $file->save(); // Assert the result. $result = $this->selectionHandler->getReferenceableEntities(); self::assertEmpty($result, 'Temporary files can not be referred by handler.'); } }