-
Notifications
You must be signed in to change notification settings - Fork 0
/
3114989-18.patch
86 lines (81 loc) · 3.63 KB
/
3114989-18.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
diff --git a/src/ConnectionTester/ConnectionTester.php b/src/ConnectionTester/ConnectionTester.php
index 1301176..300427e 100644
--- a/src/ConnectionTester/ConnectionTester.php
+++ b/src/ConnectionTester/ConnectionTester.php
@@ -13,10 +13,8 @@ class ConnectionTester {
use StringTranslationTrait;
- /**
- * These constants de not seem to be available outside of the .install file
- * so we need to declare them here.
- */
+ // These constants de not seem to be available outside of the .install file
+ // so we need to declare them here.
const REQUIREMENT_OK = 0;
const REQUIREMENT_ERROR = 2;
@@ -44,6 +42,9 @@ class ConnectionTester {
$this->testConnection();
}
+ /**
+ * Test SMTP connection.
+ */
public function testConnection() {
$mailer = $this->phpMailer();
@@ -59,11 +60,9 @@ class ConnectionTester {
$this->value = $this->t('SMTP module is enabled, turned on, and connection is valid.');
return;
}
- else {
- $this->severity = self::REQUIREMENT_ERROR;
- $this->value = $this->t('SMTP module is enabled, turned on, but SmtpConnect() returned FALSE.');
- return;
- }
+ $this->severity = REQUIREMENT_ERROR;
+ $this->value = $this->t('SMTP module is enabled, turned on, but SmtpConnect() returned FALSE.');
+ return;
}
catch (PHPMailerException $e) {
$this->value = $this->t('SMTP module is enabled, turned on, but SmtpConnect() threw exception @e', [
@@ -104,11 +103,11 @@ class ConnectionTester {
public function hookRequirements(string $phase) {
$requirements = [];
if ($phase == 'runtime') {
- $requirements['smtp_connection'] = array(
+ $requirements['smtp_connection'] = [
'title' => $this->t('SMTP connection'),
'value' => $this->getValue(),
'severity' => $this->getSeverity(),
- );
+ ];
}
return $requirements;
}
@@ -129,11 +128,14 @@ class ConnectionTester {
$mailer->SMTPDebug = FALSE;
$mailer->Host = $this->configGet('smtp_host') . ';' . $this->configGet('smtp_hostbackup');
$mailer->Port = $this->configGet('smtp_port');
- $mailer->SMTPSecure == in_array($this->configGet('smtp_protocol'), ['ssl', 'tls']) ? $this->configGet('smtp_protocol') : '';
+ $protocol = $this->configGet('smtp_protocol');
+ $mailer->SMTPSecure = in_array($protocol, ['ssl', 'tls'], TRUE) ? $protocol : '';
if ($helo = $this->configGet('smtp_client_helo')) {
$mailer->Helo = $helo;
}
- if ($username = $this->configGet('smtp_username') && $password = $this->configGet('smtp_password')) {
+ $username = $this->configGet('smtp_username');
+ $password = $this->configGet('smtp_password');
+ if ($username && $password) {
$mailer->SMTPAuth = TRUE;
$mailer->Username = $username;
$mailer->Password = $password;
diff --git a/tests/src/Unit/ConnectionTester/ConnectionTesterTest.php b/tests/src/Unit/ConnectionTester/ConnectionTesterTest.php
index df9739b..1b8b486 100644
--- a/tests/src/Unit/ConnectionTester/ConnectionTesterTest.php
+++ b/tests/src/Unit/ConnectionTester/ConnectionTesterTest.php
@@ -105,7 +105,7 @@ class ConnectionTesterTest extends UnitTestCase {
'expected' => [
'smtp_connection'=> [
'title' => serialize(['SMTP connection', []]),
- 'value' => serialize(['SMTP module is enabled, turned on, but SmtpConnect() returned FALSE.', []]),
+ 'value' => serialize(['SMTP module is enabled, turned on, but SmtpConnect() threw an unexpected exception', []]),
'severity' => ConnectionTester::REQUIREMENT_ERROR,
],
],