FieldFormatterFromViewDisplayUITest.php in (Entity Reference) Field Formatters 8.2
File
src/Tests/FieldFormatterFromViewDisplayUITest.php
View source
<?php
namespace Drupal\field_formatter\Tests;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class FieldFormatterFromViewDisplayUITest extends WebTestBase {
use StringTranslationTrait;
protected $adminUser;
public static $modules = [
'field_formatter_test',
'field_ui',
];
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer taxonomy',
'bypass node access',
]);
$this
->drupalLogin($this->adminUser);
}
public function testFieldFormatterFromViewDisplay() {
$this
->drupalGet('admin/structure/taxonomy/manage/test_vocabulary/add');
$term_name = strtolower($this
->randomMachineName());
$field = strtolower($this
->randomMachineName());
$edit_term = [
'name[0][value]' => $term_name,
'field_test_field[0][value]' => $field,
];
$this
->drupalPostForm(NULL, $edit_term, $this
->t('Save'));
$this
->assertText("Created new term {$term_name}.", 'Created term.');
$this
->drupalGet('node/add/test_content_type');
$content_name = strtolower($this
->randomMachineName());
$edit_content = [
'title[0][value]' => $content_name,
'field_field_test_ref[0][target_id]' => $term_name,
];
$this
->drupalPostForm(NULL, $edit_content, $this
->t('Save'));
$this
->assertRaw('<div class="field__label">test_field</div>', 'Field is correctly displayed on node page.');
$this
->assertRaw('<div class="field__item">' . $field . '</div>', "Field's content was found.");
}
public function testFieldFormatterFromViewConfigForm() {
$account = $this
->drupalCreateUser([
'administer node display',
]);
$this
->drupalLogin($account);
$this
->drupalGet('admin/structure/types/manage/test_content_type/display');
$this
->drupalPostAjaxForm(NULL, [], 'field_field_test_ref_settings_edit');
$this
->assertFieldByName('fields[field_field_test_ref][settings_edit_form][settings][view_mode]', NULL, 'Field to select the view mode is available.');
$this
->assertRaw('<option value="default">Default</option>', 'Default view mode can be selected.');
$this
->assertFieldByName('fields[field_field_test_ref][settings_edit_form][settings][field_name]', NULL, 'Field to select the field name is available.');
}
}