comparison core/modules/field_ui/src/Tests/ManageDisplayTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 7a779792577d
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 2
3 namespace Drupal\field_ui\Tests; 3 namespace Drupal\field_ui\Tests;
4 4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Entity\Entity\EntityFormDisplay; 5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
7 use Drupal\Core\Entity\Entity\EntityViewDisplay; 6 use Drupal\Core\Entity\Entity\EntityViewDisplay;
8 use Drupal\Core\Entity\EntityInterface; 7 use Drupal\Core\Entity\EntityInterface;
9 use Drupal\Core\Language\LanguageInterface; 8 use Drupal\Core\Language\LanguageInterface;
10 use Drupal\node\Entity\NodeType; 9 use Drupal\node\Entity\NodeType;
46 45
47 // Create a default vocabulary. 46 // Create a default vocabulary.
48 $vocabulary = Vocabulary::create([ 47 $vocabulary = Vocabulary::create([
49 'name' => $this->randomMachineName(), 48 'name' => $this->randomMachineName(),
50 'description' => $this->randomMachineName(), 49 'description' => $this->randomMachineName(),
51 'vid' => Unicode::strtolower($this->randomMachineName()), 50 'vid' => mb_strtolower($this->randomMachineName()),
52 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED, 51 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
53 'help' => '', 52 'help' => '',
54 'nodes' => ['article' => 'article'], 53 'nodes' => ['article' => 'article'],
55 'weight' => mt_rand(0, 10), 54 'weight' => mt_rand(0, 10),
56 ]); 55 ]);
117 116
118 // Change the formatter and check that the summary is updated. 117 // Change the formatter and check that the summary is updated.
119 $edit = [ 118 $edit = [
120 'fields[field_test][type]' => 'field_test_multiple', 119 'fields[field_test][type]' => 'field_test_multiple',
121 'fields[field_test][region]' => 'content', 120 'fields[field_test][region]' => 'content',
122 'refresh_rows' => 'field_test' 121 'refresh_rows' => 'field_test',
123 ]; 122 ];
124 $this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]); 123 $this->drupalPostAjaxForm(NULL, $edit, ['op' => t('Refresh')]);
125 $format = 'field_test_multiple'; 124 $format = 'field_test_multiple';
126 $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format); 125 $default_settings = \Drupal::service('plugin.manager.field.formatter')->getDefaultSettings($format);
127 $setting_name = key($default_settings); 126 $setting_name = key($default_settings);
250 $options = array_map(function ($item) { 249 $options = array_map(function ($item) {
251 return (string) $item->attributes()->value[0]; 250 return (string) $item->attributes()->value[0];
252 }, $result); 251 }, $result);
253 $expected_options = [ 252 $expected_options = [
254 'test_field_widget', 253 'test_field_widget',
254 'test_field_widget_multilingual',
255 'test_field_widget_multiple', 255 'test_field_widget_multiple',
256 ]; 256 ];
257 $this->assertEqual($options, $expected_options, 'The expected widget ordering is respected.'); 257 $this->assertEqual($options, $expected_options, 'The expected widget ordering is respected.');
258 258
259 // Change the widget and check that the summary is updated. 259 // Change the widget and check that the summary is updated.
311 311
312 // Go to the Manage Form Display. 312 // Go to the Manage Form Display.
313 $this->drupalGet($manage_display); 313 $this->drupalGet($manage_display);
314 314
315 // Checks if the select elements contain the specified options. 315 // Checks if the select elements contain the specified options.
316 $this->assertFieldSelectOptions('fields[field_test][type]', ['test_field_widget', 'test_field_widget_multiple']); 316 $this->assertFieldSelectOptions('fields[field_test][type]', ['test_field_widget', 'test_field_widget_multilingual', 'test_field_widget_multiple']);
317 $this->assertFieldSelectOptions('fields[field_onewidgetfield][type]', ['test_field_widget']); 317 $this->assertFieldSelectOptions('fields[field_onewidgetfield][type]', ['test_field_widget', 'test_field_widget_multilingual']);
318 318
319 // Ensure that fields can be hidden directly by changing the region. 319 // Ensure that fields can be hidden directly by changing the region.
320 $this->assertFieldByName('fields[field_test][region]', 'content'); 320 $this->assertFieldByName('fields[field_test][region]', 'content');
321 $edit = ['fields[field_test][region]' => 'hidden']; 321 $edit = ['fields[field_test][region]' => 'hidden'];
322 $this->drupalPostForm(NULL, $edit, t('Save')); 322 $this->drupalPostForm(NULL, $edit, t('Save'));
485 public function assertNodeViewNoText(EntityInterface $node, $view_mode, $text, $message) { 485 public function assertNodeViewNoText(EntityInterface $node, $view_mode, $text, $message) {
486 return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, TRUE); 486 return $this->assertNodeViewTextHelper($node, $view_mode, $text, $message, TRUE);
487 } 487 }
488 488
489 /** 489 /**
490 * Asserts that a string is (not) found in the rendered nodein a view mode. 490 * Asserts that a string is (not) found in the rendered node in a view mode.
491 * 491 *
492 * This helper function is used by assertNodeViewText() and 492 * This helper function is used by assertNodeViewText() and
493 * assertNodeViewNoText(). 493 * assertNodeViewNoText().
494 * 494 *
495 * @param \Drupal\Core\Entity\EntityInterface $node 495 * @param \Drupal\Core\Entity\EntityInterface $node