Conditions | 1 |
Paths | 1 |
Total Lines | 124 |
Code Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
49 | public function testConfigUI() { |
||
50 | $this->drupalGet('/admin/config/content/entity_browser'); |
||
51 | $this->assertResponse(403, "Anonymous user can't access entity browser listing page."); |
||
52 | $this->drupalGet('/admin/config/content/entity_browser/add'); |
||
53 | $this->assertResponse(403, "Anonymous user can't access entity browser add form."); |
||
54 | |||
55 | // Listing is empty. |
||
56 | $this->drupalLogin($this->adminUser); |
||
57 | $this->drupalGet('/admin/config/content/entity_browser'); |
||
58 | $this->assertResponse(200, 'Admin user is able to navigate to the entity browser listing page.'); |
||
59 | $this->assertText('There is no Entity browser yet.', 'Entity browsers table is empty.'); |
||
60 | |||
61 | // Add page. |
||
62 | $this->clickLink('Add Entity browser'); |
||
63 | $this->assertUrl('/admin/config/content/entity_browser/add'); |
||
64 | $edit = [ |
||
65 | 'label' => 'Test entity browser', |
||
66 | 'id' => 'test_entity_browser', |
||
67 | 'display' => 'iframe', |
||
68 | 'widget_selector' => 'tabs', |
||
69 | 'selection_display' => 'no_display', |
||
70 | ]; |
||
71 | $this->drupalPostForm(NULL, $edit, 'Next'); |
||
72 | |||
73 | // Display configuration step. |
||
74 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/display', ['query' => ['js' => 'nojs']]); |
||
75 | $edit = [ |
||
76 | 'width' => 100, |
||
77 | 'height' => 100, |
||
78 | 'link_text' => 'All animals are created equal', |
||
79 | 'auto_open' => TRUE, |
||
80 | ]; |
||
81 | $this->drupalPostForm(NULL, $edit, 'Next'); |
||
82 | |||
83 | // Widget selector step. |
||
84 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/widget_selector', ['query' => ['js' => 'nojs']]); |
||
85 | $this->drupalPostForm(NULL, [], 'Next'); |
||
86 | |||
87 | // Selection display step. |
||
88 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/selection_display', ['query' => ['js' => 'nojs']]); |
||
89 | $this->drupalPostForm(NULL, [], 'Next'); |
||
90 | |||
91 | // Widgets step. |
||
92 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/widgets', ['query' => ['js' => 'nojs']]); |
||
93 | $this->drupalPostAjaxForm(NULL, ['widget' => 'upload'], 'widget'); |
||
94 | $this->drupalPostForm(NULL, [], 'Finish'); |
||
95 | |||
96 | // Back on listing page. |
||
97 | $this->assertUrl('/admin/config/content/entity_browser'); |
||
98 | $this->assertText('Test entity browser', 'Entity browser label found on the listing page'); |
||
99 | $this->assertText('test_entity_browser', 'Entity browser ID found on the listing page.'); |
||
100 | |||
101 | // Check structure of entity browser object. |
||
102 | /** @var \Drupal\entity_browser\EntityBrowserInterface $loaded_entity_browser */ |
||
103 | $loaded_entity_browser = $this->container->get('entity_type.manager') |
||
104 | ->getStorage('entity_browser') |
||
105 | ->load('test_entity_browser'); |
||
106 | $this->assertEqual('test_entity_browser', $loaded_entity_browser->id(), 'Entity browser ID was correctly saved.'); |
||
107 | $this->assertEqual('Test entity browser', $loaded_entity_browser->label(), 'Entity browser label was correctly saved.'); |
||
108 | $this->assertTrue($loaded_entity_browser->getDisplay() instanceof IFrame, 'Entity browser display was correctly saved.'); |
||
109 | $expected = [ |
||
110 | 'width' => '100', |
||
111 | 'height' => '100', |
||
112 | 'link_text' => 'All animals are created equal', |
||
113 | 'auto_open' => TRUE, |
||
114 | ]; |
||
115 | $this->assertEqual($expected, $loaded_entity_browser->getDisplay()->getConfiguration(), 'Entity browser display configuration was correctly saved.'); |
||
116 | $this->assertTrue($loaded_entity_browser->getSelectionDisplay() instanceof NoDisplay, 'Entity browser selection display was correctly saved.'); |
||
117 | $this->assertEqual([], $loaded_entity_browser->getSelectionDisplay()->getConfiguration(), 'Entity browser selection display configuration was correctly saved.'); |
||
118 | $this->assertEqual($loaded_entity_browser->getWidgetSelector() instanceof Tabs, 'Entity browser widget selector was correctly saved.'); |
||
119 | $this->assertEqual([], $loaded_entity_browser->getWidgetSelector()->getConfiguration(), 'Entity browser widget selector configuration was correctly saved.'); |
||
120 | |||
121 | $widgets = $loaded_entity_browser->getWidgets(); |
||
122 | $uuid = current($widgets->getInstanceIds()); |
||
123 | /** @var \Drupal\entity_browser\WidgetInterface $widget */ |
||
124 | $widget = $widgets->get($uuid); |
||
125 | $this->assertEqual('upload', $widget->id(), 'Entity browser widget was correctly saved.'); |
||
126 | $this->assertEqual($uuid, $widget->uuid(), 'Entity browser widget uuid was correctly saved.'); |
||
127 | $configuration = $widget->getConfiguration()['settings']; |
||
128 | $this->assertEqual(['upload_location' => 'public://'], $configuration, 'Entity browser widget configuration was correctly saved.'); |
||
129 | $this->assertEqual(1, $widget->getWeight(), 'Entity browser widget weight was correctly saved.'); |
||
130 | |||
131 | // Navigate to edit. |
||
132 | $this->clickLink('Edit'); |
||
133 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/general'); |
||
134 | $this->assertFieldById('edit-label', 'Test entity browser', 'Correct label found.'); |
||
135 | $this->assertText('test_entity_browser', 'Correct id found.'); |
||
136 | $this->assertOptionSelected('edit-display', 'iframe', 'Correct display selected.'); |
||
137 | $this->assertOptionSelected('edit-widget-selector', 'tabs', 'Correct widget selector selected.'); |
||
138 | $this->assertOptionSelected('edit-selection-display', 'no_display', 'Correct selection display selected.'); |
||
139 | |||
140 | $this->drupalPostForm(NULL,[], 'Next'); |
||
141 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/display', ['query' => ['js' => 'nojs']]); |
||
142 | $this->assertFieldById('edit-width', '100', 'Correct value for width found.'); |
||
143 | $this->assertFieldById('edit-height', '100', 'Correct value for height found.'); |
||
144 | $this->assertFieldById('edit-link-text', 'All animals are created equal', 'Correct value for link text found.'); |
||
145 | $this->assertFieldChecked('edit-auto-open', 'Auto open is enabled.'); |
||
146 | |||
147 | $this->drupalPostForm(NULL,[], 'Next'); |
||
148 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/widget_selector', ['query' => ['js' => 'nojs']]); |
||
149 | |||
150 | $this->drupalPostForm(NULL,[], 'Next'); |
||
151 | $this->assertUrl('/admin/config/content/entity_browser/test_entity_browser/selection_display', ['query' => ['js' => 'nojs']]); |
||
152 | |||
153 | $this->drupalPostForm(NULL,[], 'Next'); |
||
154 | $this->assertFieldById('edit-table-' . $uuid . '-label', 'upload', 'Correct value for widget label found.'); |
||
155 | $this->assertFieldById('edit-table-' . $uuid . '-form-upload-location', 'public://', 'Correct value for upload location found.'); |
||
156 | |||
157 | $this->drupalPostForm(NULL,[], 'Finish'); |
||
158 | |||
159 | $this->drupalLogout(); |
||
160 | $this->drupalGet('/admin/config/content/entity_browser/test_entity_browser/general'); |
||
161 | $this->assertResponse(403, "Anonymous user can't access entity browser edit form."); |
||
162 | |||
163 | $this->drupalLogin($this->adminUser); |
||
164 | $this->drupalGet('/admin/config/content/entity_browser'); |
||
165 | $this->clickLink('Delete'); |
||
166 | $this->assertText('This action cannot be undone.', 'Delete question found.'); |
||
167 | $this->drupalPostForm(NULL, [], 'Delete Entity Browser'); |
||
168 | |||
169 | $this->assertText('Entity browser Test entity browser was deleted.', 'Confirmation message found.'); |
||
170 | $this->assertText('There is no Entity browser yet.', 'Entity browsers table is empty.'); |
||
171 | $this->drupalLogout(); |
||
172 | } |
||
173 | |||
175 |