Welcome To Our Shell

Mister Spy & Souheyl Bypass Shell

Current Path : /var/www/html/rocksensor1/web/core/modules/text/tests/src/Kernel/

Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
Upload File :
Current File : /var/www/html/rocksensor1/web/core/modules/text/tests/src/Kernel/TextItemBaseTest.php

<?php

declare(strict_types=1);

namespace Drupal\Tests\text\Kernel;

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\KernelTests\KernelTestBase;
use Drupal\text\Plugin\Field\FieldType\TextItemBase;

/**
 * Tests TextItemBase.
 *
 * @coversDefaultClass \Drupal\text\Plugin\Field\FieldType\TextItemBase
 * @group text
 */
class TextItemBaseTest extends KernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['filter', 'text', 'entity_test', 'field'];

  /**
   * Tests creation of sample values.
   *
   * @covers ::generateSampleValue
   * @dataProvider providerTextFieldSampleValue
   */
  public function testTextFieldSampleValue($max_length): void {
    // Create a text field.
    $field_definition = BaseFieldDefinition::create('text')
      ->setTargetEntityTypeId('foo');

    // Ensure testing of max_lengths from 1 to 3 because generateSampleValue
    // creates a sentence with a maximum number of words set to 1/3 of the
    // max_length of the field.
    $field_definition->setSetting('max_length', $max_length);
    $sample_value = TextItemBase::generateSampleValue($field_definition);
    $this->assertEquals($max_length, strlen($sample_value['value']));
  }

  /**
   * Data provider for testTextFieldSampleValue.
   */
  public static function providerTextFieldSampleValue() {
    return [
      [
        1,
      ],
      [
        2,
      ],
      [
        3,
      ],
      [
        4,
      ],
    ];
  }

  /**
   * @covers ::calculateDependencies
   */
  public function testCalculateDependencies(): void {
    $format = FilterFormat::create([
      'format' => 'test_format',
      'name' => 'Test format',
    ]);
    $format->save();
    $fieldName = $this->randomMachineName();
    $field_storage = FieldStorageConfig::create([
      'field_name' => $fieldName,
      'entity_type' => 'entity_test',
      'type' => 'text',
    ]);
    $field_storage->save();
    $field = FieldConfig::create([
      'field_name' => $fieldName,
      'entity_type' => 'entity_test',
      'bundle' => 'entity_test',
      'settings' => [
        'allowed_formats' => [$format->id()],
      ],
    ]);
    $field->save();

    $field->calculateDependencies();
    $this->assertEquals([
      'module' => [
        'entity_test',
        'text',
      ],
      'config' => [
        "field.storage.entity_test.$fieldName",
        'filter.format.test_format',
      ],
    ], $field->getDependencies());
  }

}

bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped)
Email: contact@elmoujehidin.net bypass 1.0, Devloped By El Moujahidin (the source has been moved and devloped) Email: contact@elmoujehidin.net