|
16 | 16 | use CodeIgniter\Events\Events;
|
17 | 17 | use CodeIgniter\Test\CIUnitTestCase;
|
18 | 18 | use CodeIgniter\Test\Mock\MockEmail;
|
| 19 | +use CodeIgniter\Test\ReflectionHelper; |
19 | 20 | use ErrorException;
|
20 | 21 | use PHPUnit\Framework\Attributes\DataProvider;
|
21 | 22 | use PHPUnit\Framework\Attributes\Group;
|
| 23 | +use ReflectionException; |
22 | 24 |
|
23 | 25 | /**
|
24 | 26 | * @internal
|
25 | 27 | */
|
26 | 28 | #[Group('Others')]
|
27 | 29 | final class EmailTest extends CIUnitTestCase
|
28 | 30 | {
|
| 31 | + use ReflectionHelper; |
| 32 | + |
29 | 33 | public function testEmailValidation(): void
|
30 | 34 | {
|
31 | 35 | $config = config('Email');
|
@@ -215,4 +219,51 @@ public function testSetAttachmentCIDBufferString(): void
|
215 | 219 | $email->archive['body'],
|
216 | 220 | );
|
217 | 221 | }
|
| 222 | + |
| 223 | + /** |
| 224 | + * @throws ReflectionException |
| 225 | + */ |
| 226 | + public function testGetHostnameUsesServerName(): void |
| 227 | + { |
| 228 | + $email = $this->createMockEmail(); |
| 229 | + |
| 230 | + $superglobals = service('superglobals'); |
| 231 | + $superglobals->setServer('SERVER_NAME', 'example.test'); |
| 232 | + |
| 233 | + $getHostname = self::getPrivateMethodInvoker($email, 'getHostname'); |
| 234 | + |
| 235 | + $this->assertSame('example.test', $getHostname()); |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * @throws ReflectionException |
| 240 | + */ |
| 241 | + public function testGetHostnameUsesServerAddr(): void |
| 242 | + { |
| 243 | + $email = $this->createMockEmail(); |
| 244 | + |
| 245 | + $superglobals = service('superglobals'); |
| 246 | + $superglobals->setServer('SERVER_NAME', ''); |
| 247 | + $superglobals->setServer('SERVER_ADDR', '192.168.1.10'); |
| 248 | + |
| 249 | + $getHostname = self::getPrivateMethodInvoker($email, 'getHostname'); |
| 250 | + |
| 251 | + $this->assertSame('[192.168.1.10]', $getHostname()); |
| 252 | + } |
| 253 | + |
| 254 | + /** |
| 255 | + * @throws ReflectionException |
| 256 | + */ |
| 257 | + public function testGetHostnameFallsBackToGethostnameFunction(): void |
| 258 | + { |
| 259 | + $email = $this->createMockEmail(); |
| 260 | + |
| 261 | + $superglobals = service('superglobals'); |
| 262 | + $superglobals->setServer('SERVER_NAME', ''); |
| 263 | + $superglobals->setServer('SERVER_ADDR', ''); |
| 264 | + |
| 265 | + $getHostname = self::getPrivateMethodInvoker($email, 'getHostname'); |
| 266 | + |
| 267 | + $this->assertSame(gethostname(), $getHostname()); |
| 268 | + } |
218 | 269 | }
|
0 commit comments