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