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