FieldTokensGeneralTest.php in Field tokens 8
File
src/Tests/FieldTokensGeneralTest.php
View source
<?php
namespace Drupal\field_tokens\Tests;
use Drupal\node\Entity\Node;
class FieldTokensGeneralTest extends FieldTokensTestBase {
public function testHiddenFields() {
$file_system = \Drupal::service('file_system');
$field_name = strtolower($this
->randomMachineName());
$this
->createImageField($field_name, $this->contentType
->id());
$edit = [];
$edit["fields[{$field_name}][type]"] = 'hidden';
$this
->drupalPostForm("admin/structure/types/manage/{$this->contentType->id()}/display", $edit, t('Save'));
$test_image = current($this
->drupalGetTestFiles('image'));
$edit = [];
$edit['title[0][value]'] = $this
->randomMachineName();
$edit["files[{$this->field->get('field_name')}_0]"] = $file_system
->realpath($test_image->uri);
$edit["files[{$field_name}_0]"] = $file_system
->realpath($test_image->uri);
$this
->drupalPostForm('node/add/' . $this->contentType
->id(), $edit, t('Save and publish'));
$edit = [];
$edit["{$this->field->get('field_name')}[0][alt]"] = $this
->randomString();
$edit["{$field_name}[0][alt]"] = $this
->randomString();
$this
->drupalPostForm(NULL, $edit, t('Save and publish'));
$matches = [];
preg_match('/node\\/([0-9]+)/', $this
->getUrl(), $matches);
$nid = $matches[1];
$node = Node::load($nid);
$token = "[node:{$this->field->get('field_name')}-formatted:0:image]";
\Drupal::service('token')
->replace($token, [
'node' => $node,
]);
}
}