| Conditions | 3 |
| Paths | 4 |
| Total Lines | 131 |
| Code Lines | 111 |
| 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 |
||
| 80 | public function testEmailPublicLink($validEmailAddress) { |
||
| 81 | $this->userSession->expects($this->once()) |
||
| 82 | ->method('getUser') |
||
| 83 | ->will($this->returnValue($this->dummyUser)); |
||
| 84 | $this->dummyUser->expects($this->once()) |
||
| 85 | ->method('getDisplayName') |
||
| 86 | ->will($this->returnValue('Fancy displayname 42')); |
||
| 87 | |||
| 88 | $this->l10n->expects($this->at(0)) |
||
| 89 | ->method('t') |
||
| 90 | ->with('%s has published the calendar »%s«', ['Fancy displayname 42', 'Calendarname 1337']) |
||
| 91 | ->will($this->returnValue('localized_1')); |
||
| 92 | |||
| 93 | $this->config->expects($this->at(0)) |
||
| 94 | ->method('getSystemValue') |
||
| 95 | ->with('version') |
||
| 96 | ->will($this->returnValue('12.0.0')); |
||
| 97 | |||
| 98 | $this->mailer->expects($this->at(0)) |
||
| 99 | ->method('createEMailTemplate') |
||
| 100 | ->will($this->returnValue($this->emailTemplate)); |
||
| 101 | |||
| 102 | $this->emailTemplate->expects($this->at(1)) |
||
| 103 | ->method('addHeader'); |
||
| 104 | |||
| 105 | $this->l10n->expects($this->at(1)) |
||
| 106 | ->method('t') |
||
| 107 | ->with('%s has published the calendar »%s«', ['Fancy displayname 42', 'Calendarname 1337']) |
||
| 108 | ->will($this->returnValue('localized_2')); |
||
| 109 | $this->emailTemplate->expects($this->at(1)) |
||
| 110 | ->method('addHeading') |
||
| 111 | ->with('localized_2'); |
||
| 112 | |||
| 113 | $this->l10n->expects($this->at(2)) |
||
| 114 | ->method('t') |
||
| 115 | ->with('Hello,') |
||
| 116 | ->will($this->returnValue('localized_3')); |
||
| 117 | $this->emailTemplate->expects($this->at(2)) |
||
| 118 | ->method('addBodyText') |
||
| 119 | ->with('localized_3'); |
||
| 120 | |||
| 121 | $this->l10n->expects($this->at(3)) |
||
| 122 | ->method('t') |
||
| 123 | ->with('We wanted to inform you that %s has published the calendar »%s«.', ['Fancy displayname 42', 'Calendarname 1337']) |
||
| 124 | ->will($this->returnValue('localized_4')); |
||
| 125 | $this->emailTemplate->expects($this->at(3)) |
||
| 126 | ->method('addBodyText') |
||
| 127 | ->with('localized_4'); |
||
| 128 | |||
| 129 | $this->l10n->expects($this->at(4)) |
||
| 130 | ->method('t') |
||
| 131 | ->with('Open »%s«', ['Calendarname 1337']) |
||
| 132 | ->will($this->returnValue('localized_5')); |
||
| 133 | $this->emailTemplate->expects($this->at(4)) |
||
| 134 | ->method('addBodyButton') |
||
| 135 | ->with('localized_5', 'https://url-to-public-calendar'); |
||
| 136 | |||
| 137 | $this->l10n->expects($this->at(5)) |
||
| 138 | ->method('t') |
||
| 139 | ->with('Cheers!') |
||
| 140 | ->will($this->returnValue('localized_6')); |
||
| 141 | $this->emailTemplate->expects($this->at(5)) |
||
| 142 | ->method('addBodyText') |
||
| 143 | ->with('localized_6'); |
||
| 144 | |||
| 145 | $this->emailTemplate->expects($this->at(6)) |
||
| 146 | ->method('addFooter'); |
||
| 147 | $this->emailTemplate->expects($this->at(7)) |
||
| 148 | ->method('renderHtml') |
||
| 149 | ->will($this->returnValue('html_body')); |
||
| 150 | $this->emailTemplate->expects($this->at(8)) |
||
| 151 | ->method('renderText') |
||
| 152 | ->will($this->returnValue('text_body')); |
||
| 153 | |||
| 154 | $this->mailer->expects($this->at(1)) |
||
| 155 | ->method('validateMailAddress') |
||
| 156 | ->with('[email protected]') |
||
| 157 | ->will($this->returnValue($validEmailAddress)); |
||
| 158 | |||
| 159 | if ($validEmailAddress) { |
||
| 160 | $this->config->expects($this->at(1)) |
||
| 161 | ->method('getSystemValue') |
||
| 162 | ->with('mail_domain', 'domain.org') |
||
| 163 | ->will($this->returnValue('domain_123')); |
||
| 164 | $this->config->expects($this->at(2)) |
||
| 165 | ->method('getSystemValue') |
||
| 166 | ->with('mail_from_address', 'nextcloud') |
||
| 167 | ->will($this->returnValue('from_456')); |
||
| 168 | |||
| 169 | $this->mailer->expects($this->at(2)) |
||
| 170 | ->method('createMessage') |
||
| 171 | ->will($this->returnValue($this->message)); |
||
| 172 | |||
| 173 | $this->message->expects($this->at(0)) |
||
| 174 | ->method('setSubject') |
||
| 175 | ->with('localized_1'); |
||
| 176 | $this->defaults->expects($this->at(0)) |
||
| 177 | ->method('getName') |
||
| 178 | ->will($this->returnValue('default_instance_name')); |
||
| 179 | $this->message->expects($this->at(1)) |
||
| 180 | ->method('setFrom') |
||
| 181 | ->with(['from_456@domain_123' => 'default_instance_name']); |
||
| 182 | $this->l10n->expects($this->at(6)) |
||
| 183 | ->method('t') |
||
| 184 | ->with('Recipient') |
||
| 185 | ->will($this->returnValue('localized_7')); |
||
| 186 | $this->message->expects($this->at(2)) |
||
| 187 | ->method('setTo') |
||
| 188 | ->with(['[email protected]' => 'localized_7']); |
||
| 189 | $this->message->expects($this->at(3)) |
||
| 190 | ->method('setPlainBody') |
||
| 191 | ->with('text_body'); |
||
| 192 | $this->message->expects($this->at(4)) |
||
| 193 | ->method('setHtmlBody') |
||
| 194 | ->with('html_body'); |
||
| 195 | |||
| 196 | $this->mailer->expects($this->at(3)) |
||
| 197 | ->method('send') |
||
| 198 | ->with($this->message); |
||
| 199 | } |
||
| 200 | |||
| 201 | $response = $this->controller->sendEmailPublicLink('[email protected]', 'https://url-to-public-calendar', 'Calendarname 1337'); |
||
| 202 | $this->assertInstanceOf('OCP\AppFramework\Http\JSONResponse', $response); |
||
| 203 | $this->assertEquals([], $response->getData()); |
||
| 204 | |||
| 205 | if ($validEmailAddress) { |
||
| 206 | $this->assertEquals(200, $response->getStatus()); |
||
| 207 | } else { |
||
| 208 | $this->assertEquals(400, $response->getStatus()); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 219 |