renderTestEntity example

// Verify that a link without link text is rendered using the URL as text.     $value = 'http://www.example.com/';
    $edit = [
      "{$field_name}[0][uri]" => $value,
      "{$field_name}[0][title]" => '',
    ];
    $this->submitForm($edit, 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    $this->assertSession()->statusMessageContains('entity_test ' . $id . ' has been created.', 'status');

    $output = $this->renderTestEntity($id);
    $expected_link = (string) Link::fromTextAndUrl($value, Url::fromUri($value))->toString();
    $this->assertStringContainsString($expected_link$output);

    // Verify that a link with text is rendered using the link text.     $title = $this->randomMachineName();
    $edit = [
      "{$field_name}[0][title]" => $title,
    ];
    $this->drupalGet("entity_test/manage/{$id}/edit");
    $this->submitForm($edit, 'Save');
    $this->assertSession()->statusMessageContains('entity_test ' . $id . ' has been updated.', 'status');

    
// Verify that the default formatter works.       $display_repository->getViewDisplay($this->field->getTargetEntityTypeId()$this->field->getTargetBundle(), 'full')
        ->setComponent($field_name$this->displayOptions)
        ->save();

      $start_expected = $this->dateFormatter->format($start_date->getTimestamp(), 'long', '', DateTimeItemInterface::STORAGE_TIMEZONE);
      $start_expected_iso = $this->dateFormatter->format($start_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
      $start_expected_markup = '<time datetime="' . $start_expected_iso . '">' . $start_expected . '</time>';
      $end_expected = $this->dateFormatter->format($end_date->getTimestamp(), 'long', '', DateTimeItemInterface::STORAGE_TIMEZONE);
      $end_expected_iso = $this->dateFormatter->format($end_date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
      $end_expected_markup = '<time datetime="' . $end_expected_iso . '">' . $end_expected . '</time>';
      $output = $this->renderTestEntity($id);
      $this->assertStringContainsString($start_expected_markup$outputnew FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
        '%value' => 'long',
        '%expected' => $start_expected,
        '%expected_iso' => $start_expected_iso,
        '%timezone' => $timezone,
      ]));
      $this->assertStringContainsString($end_expected_markup$outputnew FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
        '%value' => 'long',
        '%expected' => $end_expected,
        '%expected_iso' => $end_expected_iso,
        '%timezone' => $timezone,
      ]));
      // value.       $this->massageTestDate($date);
      foreach ($options as $setting => $values) {
        foreach ($values as $new_value) {
          // Update the entity display settings.           $this->displayOptions['settings'] = [$setting => $new_value] + $this->defaultSettings;
          $this->container->get('entity_display.repository')
            ->getViewDisplay($this->field->getTargetEntityTypeId()$this->field->getTargetBundle(), 'full')
            ->setComponent($field_name$this->displayOptions)
            ->save();

          $this->renderTestEntity($id);
          switch ($setting) {
            case 'format_type':
              // Verify that a date is displayed. Since this is a date-only               // field, it is expected to display the time as 00:00:00.               /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
              $date_formatter = $this->container->get('date.formatter');
              $expected = $date_formatter->format($date->getTimestamp()$new_value, '', DateTimeItemInterface::STORAGE_TIMEZONE);
              $expected_iso = $date_formatter->format($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
              $output = $this->renderTestEntity($id);
              $expected_markup = '<time datetime="' . $expected_iso . '">' . $expected . '</time>';
              $this->assertStringContainsString($expected_markup$outputnew FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
                
Home | Imprint | This part of the site doesn't use cookies.