| Conditions | 1 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 36 | public function testEntityReferenceFieldFormatter() { |
||
| 37 | // Ensure that entity reference field formatters are available as plugins. |
||
| 38 | $this->assertAvailableDisplayPlugins($this->node, [ |
||
| 39 | 'entity_reference:entity_reference_label', |
||
| 40 | 'entity_reference:entity_reference_entity_id', |
||
| 41 | 'view_mode:node.full', |
||
| 42 | 'view_mode:node.rss', |
||
| 43 | 'view_mode:node.search_index', |
||
| 44 | 'view_mode:node.search_result', |
||
| 45 | 'view_mode:node.teaser', |
||
| 46 | ]); |
||
| 47 | |||
| 48 | $this->container->get('config.factory')->getEditable('entity_embed.settings') |
||
| 49 | ->set('rendered_entity_mode', TRUE)->save(); |
||
| 50 | $this->displayPluginManager()->clearCachedDefinitions(); |
||
| 51 | |||
| 52 | $this->assertAvailableDisplayPlugins($this->node, [ |
||
| 53 | 'entity_reference:entity_reference_label', |
||
| 54 | 'entity_reference:entity_reference_entity_id', |
||
| 55 | 'entity_reference:entity_reference_entity_view', |
||
| 56 | ]); |
||
| 57 | |||
| 58 | // Ensure that correct form attributes are returned for |
||
| 59 | // 'entity_reference:entity_reference_entity_id' plugin. |
||
| 60 | $form = array(); |
||
| 61 | $form_state = new FormState(); |
||
| 62 | $display = $this->displayPluginManager()->createInstance('entity_reference:entity_reference_entity_id', array()); |
||
| 63 | $display->setContextValue('entity', $this->node); |
||
| 64 | $conf_form = $display->buildConfigurationForm($form, $form_state); |
||
| 65 | $this->assertIdentical(array_keys($conf_form), array()); |
||
| 66 | |||
| 67 | // Ensure that correct form attributes are returned for |
||
| 68 | // 'entity_reference:entity_reference_entity_view' plugin. |
||
| 69 | $form = array(); |
||
| 70 | $form_state = new FormState(); |
||
| 71 | $display = $this->displayPluginManager()->createInstance('entity_reference:entity_reference_entity_view', array()); |
||
| 72 | $display->setContextValue('entity', $this->node); |
||
| 73 | $conf_form = $display->buildConfigurationForm($form, $form_state); |
||
| 74 | $this->assertIdentical($conf_form['view_mode']['#type'], 'select'); |
||
| 75 | $this->assertIdentical((string) $conf_form['view_mode']['#title'], 'View mode'); |
||
| 76 | |||
| 77 | // Ensure that correct form attributes are returned for |
||
| 78 | // 'entity_reference:entity_reference_label' plugin. |
||
| 79 | $form = array(); |
||
| 80 | $form_state = new FormState(); |
||
| 81 | $display = $this->displayPluginManager()->createInstance('entity_reference:entity_reference_label', array()); |
||
| 82 | $display->setContextValue('entity', $this->node); |
||
| 83 | $conf_form = $display->buildConfigurationForm($form, $form_state); |
||
| 84 | $this->assertIdentical(array_keys($conf_form), array('link')); |
||
| 85 | $this->assertIdentical($conf_form['link']['#type'], 'checkbox'); |
||
| 86 | $this->assertIdentical((string) $conf_form['link']['#title'], 'Link label to the referenced entity'); |
||
| 87 | |||
| 88 | // Ensure that 'Rendered Entity' plugin is not available for an entity not |
||
| 89 | // having a view controller. |
||
| 90 | $plugin_options = $this->displayPluginManager()->getDefinitionOptionsForEntity($this->menu); |
||
| 91 | $this->assertFalse(array_key_exists('entity_reference:entity_reference_entity_view', $plugin_options), "The 'Rendered entity' plugin is not available."); |
||
| 92 | } |
||
| 93 | |||
| 138 |