| Conditions | 1 |
| Paths | 1 |
| Total Lines | 76 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 87 | public function testEntityForm() { |
||
| 88 | /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */ |
||
| 89 | $browser = $this->container->get('entity_type.manager') |
||
| 90 | ->getStorage('entity_browser') |
||
| 91 | ->load('entity_browser_test_entity_form'); |
||
| 92 | |||
| 93 | // Make sure that the "Save entities" button exists. |
||
| 94 | $this->drupalGet('entity-browser/iframe/entity_browser_test_entity_form'); |
||
| 95 | $this->assertSession()->buttonExists('Save entity'); |
||
| 96 | |||
| 97 | // Change save button's text and make sure that the change was respected. |
||
| 98 | $config = $browser->getWidget('9c6ee4c0-4642-4203-b4bd-ec0bad068ad3')->getConfiguration(); |
||
| 99 | $config['settings']['submit_text'] = 'Save node'; |
||
| 100 | $browser->getWidget('9c6ee4c0-4642-4203-b4bd-ec0bad068ad3')->setConfiguration($config); |
||
| 101 | $browser->save(); |
||
| 102 | $this->drupalGet('entity-browser/iframe/entity_browser_test_entity_form'); |
||
| 103 | $this->assertSession()->buttonNotExists('Save entity'); |
||
| 104 | $this->assertSession()->buttonExists('Save node'); |
||
| 105 | |||
| 106 | // Make sure that the widget works correctly with the field widget |
||
| 107 | $this->drupalGet('node/add/foo'); |
||
| 108 | $this->getSession()->getPage()->clickLink('Select entities'); |
||
| 109 | $this->getSession()->switchToIFrame('entity_browser_iframe_entity_browser_test_entity_form'); |
||
| 110 | $this->getSession()->getPage()->fillField('inline_entity_form[title][0][value]', 'War is peace'); |
||
| 111 | $this->getSession()->getPage()->pressButton('Save node'); |
||
| 112 | |||
| 113 | // Switch back to the main page. |
||
| 114 | $this->getSession()->switchToIFrame(); |
||
| 115 | $this->assertSession()->assertWaitOnAjaxRequest(); |
||
| 116 | |||
| 117 | $this->assertSession()->pageTextContains('War is peace'); |
||
| 118 | $this->getSession()->getPage()->fillField('title[0][value]', 'Freedom is slavery'); |
||
| 119 | $this->getSession()->getPage()->pressButton('Save'); |
||
| 120 | |||
| 121 | $parent_node = $this->container->get('entity_type.manager') |
||
| 122 | ->getStorage('node') |
||
| 123 | ->loadByProperties(['title' => 'Freedom is slavery']); |
||
| 124 | $parent_node = current($parent_node); |
||
| 125 | $this->assertEquals(1, $parent_node->get('field_reference')->count(), 'There is one child node.'); |
||
| 126 | $this->assertEquals('War is peace', $parent_node->field_reference->entity->label(), 'Child node has correct title.'); |
||
| 127 | |||
| 128 | // Now try using Multi value selection display and make sure there is only |
||
| 129 | // one node created by the Entity browser. |
||
| 130 | $browser->setSelectionDisplay('multi_step_display')->save(); |
||
| 131 | $this->drupalGet('node/add/foo'); |
||
| 132 | $this->getSession()->getPage()->clickLink('Select entities'); |
||
| 133 | $this->getSession()->switchToIFrame('entity_browser_iframe_entity_browser_test_entity_form'); |
||
| 134 | $this->getSession()->getPage()->fillField('inline_entity_form[title][0][value]', 'War is peace'); |
||
| 135 | $this->getSession()->getPage()->pressButton('Save node'); |
||
| 136 | $this->getSession()->getPage()->pressButton('Use selected'); |
||
| 137 | |||
| 138 | // Switch back to the main page. |
||
| 139 | $this->getSession()->switchToIFrame(); |
||
| 140 | $this->assertSession()->assertWaitOnAjaxRequest(); |
||
| 141 | |||
| 142 | $this->assertSession()->pageTextContains('War is peace'); |
||
| 143 | $this->getSession()->getPage()->fillField('title[0][value]', 'Ignorance is strength'); |
||
| 144 | $this->getSession()->getPage()->pressButton('Save'); |
||
| 145 | |||
| 146 | $parent_node = $this->container->get('entity_type.manager') |
||
| 147 | ->getStorage('node') |
||
| 148 | ->loadByProperties(['title' => 'Ignorance is strength']); |
||
| 149 | $parent_node = current($parent_node); |
||
| 150 | $this->assertEquals(1, $parent_node->get('field_reference')->count(), 'There is one child node.'); |
||
| 151 | $this->assertEquals('War is peace', $parent_node->field_reference->entity->label(), 'Child node has correct title.'); |
||
| 152 | |||
| 153 | // Make sure entity create access is respected. |
||
| 154 | $account = $this->drupalCreateUser([ |
||
| 155 | 'access entity_browser_test_entity_form entity browser pages', |
||
| 156 | 'create foo content', |
||
| 157 | 'access content', |
||
| 158 | ]); |
||
| 159 | $this->drupalLogin($account); |
||
| 160 | $this->drupalGet('entity-browser/iframe/entity_browser_test_entity_form'); |
||
| 161 | $this->assertSession()->pageTextContains('No widgets are available.'); |
||
| 162 | } |
||
| 163 | |||
| 165 |