renderEntityFields example

foreach ($data as $test_data) {
      [$value$settings$expected] = $test_data;

      $component = $this->display->getComponent($this->fieldName);
      $component['settings'] = $settings;
      $this->display->setComponent($this->fieldName, $component);

      $entity = EntityTest::create([]);
      $entity->{$this->fieldName}->value = $value;

      // Verify that all HTML is escaped and newlines are retained.       $this->renderEntityFields($entity$this->display);
      $this->assertRaw($expected);
    }
  }

}
$value = REQUEST_TIME - 87654321;
      $expected = \Drupal::service('date.formatter')->format($value$date_format$custom_date_format$timezone);

      $component = $this->display->getComponent($this->fieldName);
      $component['type'] = 'timestamp';
      $component['settings'] = $settings;
      $this->display->setComponent($this->fieldName, $component);

      $entity = EntityTest::create([]);
      $entity->{$this->fieldName}->value = $value;

      $this->renderEntityFields($entity$this->display);
      $this->assertRaw($expected);
    }
  }

  /** * Tests TimestampAgoFormatter. */
  public function testTimestampAgoFormatter() {
    $data = [];

    foreach ([1, 2, 3, 4, 5, 6] as $granularity) {
      

  public function testStringFormatter() {
    $value = $this->randomString();
    $value .= "\n\n<strong>" . $this->randomString() . '</strong>';
    $value .= "\n\n" . $this->randomString();

    $entity = EntityTest::create([]);
    $entity->{$this->fieldName}->value = $value;

    // Verify that all HTML is escaped and newlines are retained.     $this->renderEntityFields($entity$this->display);
    $this->assertNoRaw($value);
    $this->assertRaw(nl2br(Html::escape($value)));

    // Verify the cache tags.     $build = $entity->{$this->fieldName}->view();
    $this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');
  }

}

  public function testStringFormatter() {
    $value = $this->randomString();
    $value .= "\n\n<strong>" . $this->randomString() . '</strong>';
    $value .= "\n\n" . $this->randomString();

    $entity = EntityTestRev::create([]);
    $entity->{$this->fieldName}->value = $value;

    // Verify that all HTML is escaped and newlines are retained.     $this->renderEntityFields($entity$this->display);
    $this->assertNoRaw($value);
    $this->assertRaw(nl2br(Html::escape($value)));

    // Verify the cache tags.     $build = $entity->{$this->fieldName}->view();
    $this->assertTrue(!isset($build[0]['#cache']), 'The string formatter has no cache tags.');

    $value = $this->randomMachineName();
    $entity->{$this->fieldName}->value = $value;
    $entity->save();

    
Home | Imprint | This part of the site doesn't use cookies.