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