FieldTokensFormattedTest.php in Field tokens 8
File
src/Tests/FieldTokensFormattedTest.php
View source
<?php
namespace Drupal\field_tokens\Tests;
use Drupal\node\Entity\Node;
class FieldTokensFormattedTest extends FieldTokensTestBase {
public function testFormattedTokens() {
$test_image = current($this
->drupalGetTestFiles('image'));
$nid = $this
->uploadNodeImage($test_image, $this->field
->get('field_name'), $this->contentType
->id(), $this
->randomString());
$node = Node::load($nid);
$display = [
'type' => 'image',
'settings' => [
'image_style' => '',
'image_link' => '',
],
'module' => 'image',
];
$element = $node->{$this->field
->get('field_name')}
->view($display);
$output = \Drupal::service('renderer')
->renderRoot($element['0']);
$token = "[node:{$this->field->get('field_name')}-formatted:0:image]";
$value = \Drupal::service('token')
->replace($token, [
'node' => $node,
]);
$this
->assertEqual($value, $output, $token . ' matches rendered Image formatter for provided Image field.');
}
}