Conditions | 1 |
Paths | 1 |
Total Lines | 70 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
62 | public function testCropTypeCrud() { |
||
63 | // Anonymous users don't have access to crop type admin pages. |
||
64 | $this->drupalGet('admin/structure/crop'); |
||
65 | $this->assertResponse(403); |
||
66 | $this->drupalGet('admin/structure/crop/add'); |
||
67 | $this->assertResponse(403); |
||
68 | |||
69 | // Can access pages if logged in and no crop types exist. |
||
70 | $this->drupalLogin($this->adminUser); |
||
71 | $this->drupalGet('admin/structure/crop'); |
||
72 | $this->assertResponse(200); |
||
73 | $this->assertText(t('No crop types available.')); |
||
74 | $this->assertLink(t('Add crop type')); |
||
75 | |||
76 | // Can access add crop type form. |
||
77 | $this->clickLink(t('Add crop type')); |
||
78 | $this->assertResponse(200); |
||
79 | $this->assertUrl('admin/structure/crop/add'); |
||
80 | |||
81 | // Create crop type. |
||
82 | $edit = [ |
||
83 | 'id' => strtolower($this->randomMachineName()), |
||
84 | 'label' => $this->randomMachineName(), |
||
85 | 'description' => $this->randomGenerator->sentences(10), |
||
86 | ]; |
||
87 | $this->drupalPostForm('admin/structure/crop/add', $edit, t('Save crop type')); |
||
88 | $this->assertRaw(t('The crop type %name has been added.', ['%name' => $edit['label']])); |
||
89 | $this->assertUrl('admin/structure/crop'); |
||
90 | $label = $this->xpath("//td[contains(concat(' ',normalize-space(@class),' '),' menu-label ')]"); |
||
91 | $this->assert(strpos($label[0]->asXML(), $edit['label']) !== FALSE, 'Crop type label found on listing page.'); |
||
92 | $this->assertText($edit['description']); |
||
93 | |||
94 | // Check edit form. |
||
95 | $this->clickLink(t('Edit')); |
||
96 | $this->assertText(t('Edit @name crop type', ['@name' => $edit['label']])); |
||
97 | $this->assertRaw($edit['id']); |
||
98 | $this->assertFieldById('edit-label', $edit['label']); |
||
99 | $this->assertRaw($edit['description']); |
||
100 | |||
101 | // See if crop type appears on image effect configuration form. |
||
102 | $this->drupalGet('admin/config/media/image-styles/manage/' . $this->testStyle->id() . '/add/crop_crop'); |
||
103 | $option = $this->xpath("//select[@id='edit-data-crop-type']/option"); |
||
104 | $this->assert(strpos($option[0]->asXML(), $edit['label']) !== FALSE, 'Crop type label found on image effect page.'); |
||
105 | $this->drupalPostForm('admin/config/media/image-styles/manage/' . $this->testStyle->id() . '/add/crop_crop', ['data[crop_type]' => $edit['id']], t('Add effect')); |
||
106 | $this->assertText(t('The image effect was successfully applied.')); |
||
107 | $this->assertText(t('Manual crop uses @name crop type', ['@name' => $edit['label']])); |
||
108 | $this->testStyle = $this->container->get('entity.manager')->getStorage('image_style')->loadUnchanged($this->testStyle->id()); |
||
109 | $this->assertEqual($this->testStyle->getEffects()->count(), 1, 'One image effect added to test image style.'); |
||
110 | $effect_configuration = $this->testStyle->getEffects()->getIterator()->current()->getConfiguration(); |
||
111 | $this->assertEqual($effect_configuration['data'], ['crop_type' => $edit['id']], 'Manual crop effect uses correct image style.'); |
||
112 | |||
113 | // Try to access edit form as anonymous user. |
||
114 | $this->drupalLogout(); |
||
115 | $this->drupalGet('admin/structure/crop/manage/' . $edit['id']); |
||
116 | $this->assertResponse(403); |
||
117 | $this->drupalLogin($this->adminUser); |
||
118 | |||
119 | // Try to create crop type with same machine name. |
||
120 | $this->drupalPostForm('admin/structure/crop/add', $edit, t('Save crop type')); |
||
121 | $this->assertText(t('The machine-readable name is already in use. It must be unique.')); |
||
122 | |||
123 | // Delete crop type. |
||
124 | $this->drupalGet('admin/structure/crop'); |
||
125 | $this->assertLink('Test image style'); |
||
126 | $this->clickLink(t('Delete')); |
||
127 | $this->assertText(t('Are you sure you want to delete the crop type @name?', ['@name' => $edit['label']])); |
||
128 | $this->drupalPostForm('admin/structure/crop/manage/' . $edit['id'] . '/delete', [], t('Delete')); |
||
129 | $this->assertRaw(t('The crop type %name has been deleted.', ['%name' => $edit['label']])); |
||
130 | $this->assertText(t('No crop types available.')); |
||
131 | } |
||
132 | |||
134 |