Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | public function testImageFieldFormatter() { |
||
49 | // Ensure that image field formatters are available as plugins. |
||
50 | $this->assertAvailableDisplayPlugins($this->image, [ |
||
51 | 'entity_reference:entity_reference_label', |
||
52 | 'entity_reference:entity_reference_entity_id', |
||
53 | 'file:file_default', |
||
54 | 'file:file_table', |
||
55 | 'file:file_url_plain', |
||
56 | 'image:responsive_image', |
||
57 | 'image:image', |
||
58 | ]); |
||
59 | |||
60 | // Ensure that correct form attributes are returned for the image plugin. |
||
61 | $form = array(); |
||
62 | $form_state = new FormState(); |
||
63 | $display = $this->container->get('plugin.manager.entity_embed.display') |
||
64 | ->createInstance('image:image', []); |
||
65 | $display->setContextValue('entity', $this->image); |
||
66 | $conf_form = $display->buildConfigurationForm($form, $form_state); |
||
67 | $this->assertIdentical(array_keys($conf_form), array( |
||
68 | 'image_style', |
||
69 | 'image_link', |
||
70 | 'alt', |
||
71 | 'title', |
||
72 | )); |
||
73 | $this->assertIdentical($conf_form['image_style']['#type'], 'select'); |
||
74 | $this->assertIdentical((string) $conf_form['image_style']['#title'], 'Image style'); |
||
75 | $this->assertIdentical($conf_form['image_link']['#type'], 'select'); |
||
76 | $this->assertIdentical((string) $conf_form['image_link']['#title'], 'Link image to'); |
||
77 | $this->assertIdentical($conf_form['alt']['#type'], 'textfield'); |
||
78 | $this->assertIdentical((string) $conf_form['alt']['#title'], 'Alternate text'); |
||
79 | $this->assertIdentical($conf_form['title']['#type'], 'textfield'); |
||
80 | $this->assertIdentical((string) $conf_form['title']['#title'], 'Title'); |
||
81 | |||
82 | // Test entity embed using 'Image' Entity Embed Display plugin. |
||
83 | $alt_text = "This is sample description"; |
||
84 | $title = "This is sample title"; |
||
85 | $embed_settings = array('image_link' => 'file'); |
||
86 | $content = '<drupal-entity data-entity-type="file" data-entity-uuid="' . $this->image->uuid() . '" data-entity-embed-display="image:image" data-entity-embed-display-settings=\'' . Json::encode($embed_settings) . '\' alt="' . $alt_text . '" title="' . $title . '">This placeholder should not be rendered.</drupal-entity>'; |
||
87 | $settings = array(); |
||
88 | $settings['type'] = 'page'; |
||
89 | $settings['title'] = 'Test entity embed with image:image'; |
||
90 | $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); |
||
91 | $node = $this->drupalCreateNode($settings); |
||
92 | $this->drupalGet('node/' . $node->id()); |
||
93 | $this->assertRaw($alt_text, 'Alternate text for the embedded image is visible when embed is successful.'); |
||
94 | $this->assertNoText(strip_tags($content), 'Placeholder does not appears in the output when embed is successful.'); |
||
95 | $this->assertLinkByHref(file_create_url($this->image->getFileUri()), 0, 'Link to the embedded image exists.'); |
||
96 | |||
97 | // Embed all three field types in one, to ensure they all render correctly. |
||
98 | $content = '<drupal-entity data-entity-type="node" data-entity-uuid="' . $this->node->uuid() . '" data-entity-embed-display="entity_reference:entity_reference_label"></drupal-entity>'; |
||
99 | $content .= '<drupal-entity data-entity-type="file" data-entity-uuid="' . $this->file->uuid() . '" data-entity-embed-display="file:file_default"></drupal-entity>'; |
||
100 | $content .= '<drupal-entity data-entity-type="file" data-entity-uuid="' . $this->image->uuid() . '" data-entity-embed-display="image:image"></drupal-entity>'; |
||
101 | $settings = array(); |
||
102 | $settings['type'] = 'page'; |
||
103 | $settings['title'] = 'Test node entity embedded first then a file entity'; |
||
104 | $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); |
||
105 | $node = $this->drupalCreateNode($settings); |
||
106 | $this->drupalGet('node/' . $node->id()); |
||
107 | } |
||
108 | |||
110 |