-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathPostmarkAdminClientSenderSignatureTest.php
More file actions
184 lines (144 loc) · 6.28 KB
/
PostmarkAdminClientSenderSignatureTest.php
File metadata and controls
184 lines (144 loc) · 6.28 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
namespace Postmark\Tests;
require_once __DIR__ . '/PostmarkClientBaseTest.php';
use Postmark\PostmarkAdminClient;
use Exception;
/**
* @internal
*
* @coversNothing
*/
class PostmarkAdminClientSenderSignatureTest extends PostmarkClientBaseTest
{
public static function tearDownAfterClass(): void
{
$tk = parent::$testKeys;
$client = new PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$signatures = $client->listSenderSignatures();
foreach ($signatures->getSenderSignatures() as $key => $value) {
if (preg_match('/test-php.+/', $value->getName()) > 0) {
$client->deleteSenderSignature($value->getID());
}
}
}
public function testClientCanGetSignatureList()
{
$tk = parent::$testKeys;
$client = new PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$sigs = $client->listSenderSignatures();
$this->assertGreaterThan(0, $sigs->getTotalCount());
$this->assertNotEmpty($sigs->getSenderSignatures());
}
public function testClientCanGetSingleSignature()
{
$tk = parent::$testKeys;
$client = new PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$signatures = $client->listSenderSignatures()->getSenderSignatures();
if (empty($signatures)) {
$this->markTestSkipped('No sender signatures available in test account');
return;
}
$id = $signatures[0]->getID();
$sig = $client->getSenderSignature($id);
$this->assertNotEmpty($sig->getName());
}
public function testClientCanCreateSignature()
{
$tk = parent::$testKeys;
$client = new PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$i = $tk->WRITE_TEST_SENDER_SIGNATURE_PROTOTYPE;
$sender = str_replace('[TOKEN]', 'test-php-create' . date('U'), $i);
$name = 'test-php-create-' . date('U');
$note = 'This is a test note';
$sig = $client->createSenderSignature($sender, $name, null, null, $note);
$this->assertNotEmpty($sig->getID());
$this->assertEquals($sender, $sig->getEmailAddress());
$this->assertEquals($name, $sig->getName());
$this->assertEquals($note, $sig->getConfirmationPersonalNote());
}
public function testClientCanEditSignature()
{
$tk = parent::$testKeys;
$client = new PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$name = 'test-php-edit-' . date('U');
$i = $tk->WRITE_TEST_SENDER_SIGNATURE_PROTOTYPE;
$sender = str_replace('[TOKEN]', 'test-php-edit' . date('U'), $i);
$exploded = explode('@', $tk->WRITE_TEST_SENDER_SIGNATURE_PROTOTYPE);
$returnPath = 'test.' . $exploded[1];
$sig = $client->createSenderSignature($sender, $name, null, $returnPath);
$updated = $client->editSenderSignature(
$sig->getID(),
$name . '-updated',
null,
'updated-' . $returnPath
);
$this->assertNotSame($sig->getName(), $updated->getName());
$this->assertNotSame($sig->getReturnpathdomain(), $updated->getReturnpathdomain());
}
public function testClientCanDeleteSignature()
{
$tk = parent::$testKeys;
$client = new PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$i = $tk->WRITE_TEST_SENDER_SIGNATURE_PROTOTYPE;
$timestamp = date('U') . '-' . uniqid();
// Create a unique email by replacing the [TOKEN] placeholder
$sender = str_replace('[TOKEN]', 'test-php-delete-' . $timestamp, $i);
// Validate the generated email is valid
if (!filter_var($sender, FILTER_VALIDATE_EMAIL)) {
$this->fail("Generated email address is invalid: $sender");
}
$name = 'test-php-delete-' . $timestamp;
// First, try to clean up any existing signature with the same name
$sigs = $client->listSenderSignatures()->getSenderSignatures();
foreach ($sigs as $existing) {
if ($existing->getName() === $name) {
try {
$client->deleteSenderSignature($existing->getID());
// Wait a moment for deletion to process
sleep(2);
} catch (Exception $e) {
// Continue if deletion fails
continue;
}
}
}
// Also try to clean up any signature with the same email address
foreach ($sigs as $existing) {
try {
// Get the signature details to check the email
$sigDetails = $client->getSenderSignature($existing->getID());
if ($sigDetails->getEmailAddress() === $sender) {
$client->deleteSenderSignature($existing->getID());
sleep(2);
}
} catch (Exception $e) {
// Continue if we can't check or delete
continue;
}
}
// Now try to create the signature
$sig = $client->createSenderSignature($sender, $name);
$client->deleteSenderSignature($sig->getID());
$sigs = $client->listSenderSignatures()->getSenderSignatures();
// Verify the deleted signature is not in the list
$deletedSignatureFound = false;
foreach ($sigs as $key => $value) {
if ($value->getID() === $sig->getID()) {
$deletedSignatureFound = true;
break;
}
}
$this->assertFalse($deletedSignatureFound, 'Deleted signature should not be found in the list');
}
public function testClientCanRequestNewVerificationForSignature()
{
$tk = parent::$testKeys;
$client = new PostmarkAdminClient($tk->WRITE_ACCOUNT_TOKEN, $tk->TEST_TIMEOUT);
$i = $tk->WRITE_TEST_SENDER_SIGNATURE_PROTOTYPE;
$sender = str_replace('[TOKEN]', 'test-php-reverify' . date('U'), $i);
$name = 'test-php-reverify-' . date('U');
$sig = $client->createSenderSignature($sender, $name);
$result = $client->resendSenderSignatureConfirmation($sig->getID());
$this->assertEquals(0, $result->getErrorCode());
}
}