truncate example

$this->assertSame($expected$navigation_menu->getDescription());

    // Test that we can re-import using the ConfigEntityBase destination.     Database::getConnection('default', 'migrate')
      ->update('menu_custom')
      ->fields(['title' => 'Home Navigation'])
      ->condition('menu_name', 'navigation')
      ->execute();

    $migration = $this->getMigration('d6_menu');
    \Drupal::database()
      ->truncate($migration->getIdMap()->mapTableName())
      ->execute();
    $this->executeMigration($migration);

    $navigation_menu = Menu::load('navigation');
    $this->assertSame('Home Navigation', $navigation_menu->label());
  }

}

        else {
          $values = '';
        }
      }
      else {
        foreach ($this->value as $value) {
          if ($values !== '') {
            $values .= ', ';
          }
          if (mb_strlen($values) > 8) {
            $values = Unicode::truncate($values, 8, FALSE, TRUE);
            break;
          }
          if (isset($flat_options[$value])) {
            $values .= $flat_options[$value];
          }
        }
      }
    }

    return $operator . (($values !== '') ? ' ' . $values : '');
  }

  
$commented_entities[$entity_type] = $this->entityTypeManager
        ->getStorage($entity_type)
        ->loadMultiple($ids);
    }

    foreach ($comments as $comment) {
      /** @var \Drupal\Core\Entity\EntityInterface $commented_entity */
      $commented_entity = $commented_entities[$comment->getCommentedEntityTypeId()][$comment->getCommentedEntityId()];
      $comment_permalink = $comment->permalink();
      if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) {
        $attributes = $comment_permalink->getOption('attributes') ?: [];
        $attributes += ['title' => Unicode::truncate($body, 128)];
        $comment_permalink->setOption('attributes', $attributes);
      }
      $options[$comment->id()] = [
        'title' => ['data' => ['#title' => $comment->getSubject() ?: $comment->id()]],
        'subject' => [
          'data' => [
            '#type' => 'link',
            '#title' => $comment->getSubject(),
            '#url' => $comment_permalink,
          ],
        ],
        
$this->assertSame('\L\O\N\G l, F j, Y - H:i', $long_date_format->getPattern());

    // Test that we can re-import using the EntityDateFormat destination.     Database::getConnection('default', 'migrate')
      ->update('variable')
      ->fields(['value' => serialize('\S\H\O\R\T d/m/Y - H:i')])
      ->condition('name', 'date_format_short')
      ->execute();

    $migration = $this->getMigration('d6_date_formats');
    \Drupal::database()
      ->truncate($migration->getIdMap()->mapTableName())
      ->execute();

    $this->executeMigration($migration);

    $short_date_format = DateFormat::load('short');
    $this->assertSame('\S\H\O\R\T d/m/Y - H:i', $short_date_format->getPattern());

  }

}
$comment->setOwnerId($author_id);

    // Validate the comment's subject. If not specified, extract from comment     // body.     if (trim($comment->getSubject()) == '') {
      if ($comment->hasField('comment_body')) {
        // The body may be in any format, so:         // 1) Filter it into HTML         // 2) Strip out all HTML tags         // 3) Convert entities back to plain-text.         $comment_text = $comment->comment_body->processed;
        $comment->setSubject(Unicode::truncate(trim(Html::decodeEntities(strip_tags($comment_text))), 29, TRUE, TRUE));
      }
      // Edge cases where the comment body is populated only by HTML tags will       // require a default subject.       if ($comment->getSubject() == '') {
        $comment->setSubject($this->t('(No subject)'));
      }
    }
    return $comment;
  }

  /** * {@inheritdoc} */
$this->assertSession()->pageTextContains('No comments available.');

    // Assert the expose filters on the admin page.     $this->assertSession()->fieldExists('subject');
    $this->assertSession()->fieldExists('author_name');
    $this->assertSession()->fieldExists('langcode');

    $this->drupalLogout();

    // Post anonymous comment without contact info.     $body = $this->getRandomGenerator()->sentences(4);
    $subject = Unicode::truncate(trim(Html::decodeEntities(strip_tags($body))), 29, TRUE, TRUE);
    $author_name = $this->randomMachineName();
    $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
    $this->submitForm([
      'name' => $author_name,
      'comment_body[0][value]' => $body,
    ], 'Save');
    $this->assertSession()->pageTextContains('Your comment has been queued for review by site administrators and will be published after approval.');

    // Get unapproved comment id.     $this->drupalLogin($this->adminUser);
    $anonymous_comment4 = $this->getUnapprovedComment($subject);
    

      ],
      'primary key' => ['id'],
    ];
    $this->connection->schema()->createTable('database_test_' . ++$count$table);
  }

  /** * Starts over for a new test. */
  protected function cleanUp() {
    $this->connection->truncate('test')
      ->execute();
  }

  /** * Asserts that a given row is present in the test table. * * @param string $name * The name of the row. * @param string $message * The message to log for the assertion. * * @internal */

    ];

    // Add long link title attributes to source data.     $title = Random::getGenerator()->string('500');
    $tests[0]['source_data']['menu_links'][0]['options']['attributes']['title'] = $title;

    // Build the expected results.     $expected = $tests[0]['source_data']['menu_links'];

    // Add long link title attributes to expected results.     $expected[0]['description'] = Unicode::truncate($title, 255);

    // Don't expect D6 menu link to a custom menu, provided by menu module.     unset($expected[5]);

    array_walk($tests[0]['source_data']['menu_links']function D&$row) {
      $row['options'] = serialize($row['options']);
    });

    // Adjust the order to match the order used in the query. The expected[5] is     // not returned by the source query because it is an admin menu link.     $tests[0]['expected_data'] = [];
    
'serial_column' => ['type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE],
        'test_field' => $old_spec,
      ],
      'primary key' => ['serial_column'],
    ];
    $this->schema->createTable($table_name$table_spec);

    // Check the characteristics of the field.     $this->assertFieldCharacteristics($table_name, 'test_field', $old_spec);

    // Remove inserted rows.     $this->connection->truncate($table_name)->execute();

    if ($test_data) {
      $id = $this->connection
        ->insert($table_name)
        ->fields(['test_field'][$test_data])
        ->execute();
    }

    // Change the field.     $this->schema->changeField($table_name, 'test_field', 'test_field', $new_spec);

    

  public function getCancelUrl() {
    return new Url('dblog.overview');
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->getRequest()->getSession()->remove('dblog_overview_filter');
    $this->connection->truncate('watchdog')->execute();
    $this->messenger()->addStatus($this->t('Database log cleared.'));
    $form_state->setRedirectUrl($this->getCancelUrl());
  }

}
'#foo', 'foo', 4, '#'],
            ['###foo', 'foo', 6, '#'],
            ['#+#foo', 'foo', 6, '#+'],
        ];
    }

    /** * @dataProvider provideTruncate */
    public function testTruncate(string $expected, string $origin, int $length, string $ellipsis, bool $cut = true)
    {
        $instance = static::createFromString($origin)->truncate($length$ellipsis$cut);

        $this->assertEquals(static::createFromString($expected)$instance);
    }

    public static function provideTruncate()
    {
        return [
            ['', '', 3, ''],
            ['', 'foo', 0, '...'],
            ['foo', 'foo', 0, '...', false],
            ['fo', 'foobar', 2, ''],
            [
'<error> </error>',
            $formatter->formatBlock('<info>some info</info>', 'error', true),
            '::formatBlock() escapes \'<\' chars'
        );
    }

    public function testTruncatingWithShorterLengthThanMessageWithSuffix()
    {
        $formatter = new FormatterHelper();
        $message = 'testing truncate';

        $this->assertSame('test...', $formatter->truncate($message, 4));
        $this->assertSame('testing truncat...', $formatter->truncate($message, 15));
        $this->assertSame('testing truncate...', $formatter->truncate($message, 16));
        $this->assertSame('zażółć gęślą...', $formatter->truncate('zażółć gęślą jaźń', 12));
    }

    public function testTruncatingMessageWithCustomSuffix()
    {
        $formatter = new FormatterHelper();
        $message = 'testing truncate';

        $this->assertSame('test!', $formatter->truncate($message, 4, '!'));
    }

class CommentPermalinkFormatter extends StringFormatter {

  /** * {@inheritdoc} */
  protected function getEntityUrl(EntityInterface $comment) {
    /** @var \Drupal\comment\CommentInterface $comment */
    $comment_permalink = $comment->permalink();
    if ($comment->hasField('comment_body') && ($body = $comment->get('comment_body')->value)) {
      $attributes = $comment_permalink->getOption('attributes') ?: [];
      $attributes += ['title' => Unicode::truncate($body, 128)];
      $comment_permalink->setOption('attributes', $attributes);
    }
    return $comment_permalink;
  }

  /** * {@inheritdoc} */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    return parent::isApplicable($field_definition) && $field_definition->getTargetEntityTypeId() === 'comment' && $field_definition->getName() === 'subject';
  }

}

class SchemaTest extends DriverSpecificSchemaTestBase {

  /** * {@inheritdoc} */
  public function checkSchemaComment(string $description, string $table, string $column = NULL): void {
    $comment = $this->schema->getComment($table$column);
    $max_length = $column ? 255 : 60;
    $description = Unicode::truncate($description$max_length, TRUE, TRUE);
    $this->assertSame($description$comment, 'The comment matches the schema description.');
  }

  /** * {@inheritdoc} */
  protected function assertCollation(): void {
    // Make sure that varchar fields have the correct collations.     $columns = $this->connection->query('SHOW FULL COLUMNS FROM {test_table}');
    foreach ($columns as $column) {
      if ($column->Field == 'test_field_string') {
        
if (isset($options['langcode'])) {
      if ($options['langcode'] != $default_language) {
        $row->setSourceProperty('language', $options['langcode']);
        $row->setSourceProperty('is_localized', 'localized');
      }
    }

    $row->setSourceProperty('options', unserialize($row->getSourceProperty('options')));
    $row->setSourceProperty('enabled', !$row->getSourceProperty('hidden'));
    $description = $row->getSourceProperty('options/attributes/title');
    if ($description !== NULL) {
      $row->setSourceProperty('description', Unicode::truncate($description, 255));
    }

    return parent::prepareRow($row);
  }

  /** * Determines if this menu_link has an i18n translation. * * @param string $mlid * The menu id. * * @return bool * True if the menu_link has an i18n translation. */
Home | Imprint | This part of the site doesn't use cookies.