|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Email\Test\Unit\Model\Plugin; |
| 9 | + |
| 10 | +use Magento\Email\Model\Plugin\WindowsSmtpConfig; |
| 11 | +use Magento\Framework\App\Config\ReinitableConfigInterface; |
| 12 | +use Magento\Framework\Mail\TransportInterface; |
| 13 | +use Magento\Framework\OsInfo; |
| 14 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 15 | + |
| 16 | +/** |
| 17 | + * WindowsSmtpConfigTest |
| 18 | + */ |
| 19 | +class WindowsSmtpConfigTest extends \PHPUnit\Framework\TestCase |
| 20 | +{ |
| 21 | + /** |
| 22 | + * @var WindowsSmtpConfig |
| 23 | + */ |
| 24 | + private $windowsSmtpConfig; |
| 25 | + |
| 26 | + /** |
| 27 | + * @var OsInfo|\PHPUnit_Framework_MockObject_MockObject |
| 28 | + */ |
| 29 | + private $osInfoMock; |
| 30 | + |
| 31 | + /** |
| 32 | + * @var ReinitableConfigInterface|\PHPUnit_Framework_MockObject_MockObject |
| 33 | + */ |
| 34 | + private $configMock; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var TransportInterface |
| 38 | + */ |
| 39 | + private $transportMock; |
| 40 | + |
| 41 | + /** |
| 42 | + * setUp |
| 43 | + * |
| 44 | + * @return void |
| 45 | + */ |
| 46 | + public function setUp(): void |
| 47 | + { |
| 48 | + $objectManager = new ObjectManager($this); |
| 49 | + |
| 50 | + $this->osInfoMock = $this->createMock(OsInfo::class); |
| 51 | + $this->configMock = $this->createMock(ReinitableConfigInterface::class); |
| 52 | + $this->transportMock = $this->createMock(TransportInterface::class); |
| 53 | + |
| 54 | + $this->windowsSmtpConfig = $objectManager->getObject( |
| 55 | + WindowsSmtpConfig::class, |
| 56 | + [ |
| 57 | + 'config' => $this->configMock, |
| 58 | + 'osInfo' => $this->osInfoMock |
| 59 | + ] |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Test if SMTP settings if windows server |
| 65 | + * |
| 66 | + * @return void |
| 67 | + */ |
| 68 | + public function testBeforeSendMessageOsWindows(): void |
| 69 | + { |
| 70 | + $this->osInfoMock->expects($this->once()) |
| 71 | + ->method('isWindows') |
| 72 | + ->willReturn(true); |
| 73 | + |
| 74 | + $this->configMock->expects($this->exactly(2)) |
| 75 | + ->method('getValue') |
| 76 | + ->willReturnMap([ |
| 77 | + [WindowsSmtpConfig::XML_SMTP_HOST, '127.0.0.1'], |
| 78 | + [WindowsSmtpConfig::XML_SMTP_PORT, '80'] |
| 79 | + ]); |
| 80 | + |
| 81 | + $this->windowsSmtpConfig->beforeSendMessage($this->transportMock); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Test if SMTP settings if not windows server |
| 86 | + * |
| 87 | + * @return void |
| 88 | + */ |
| 89 | + public function testBeforeSendMessageOsIsWindows(): void |
| 90 | + { |
| 91 | + $this->osInfoMock->expects($this->once()) |
| 92 | + ->method('isWindows') |
| 93 | + ->willReturn(false); |
| 94 | + |
| 95 | + $this->configMock->expects($this->never()) |
| 96 | + ->method('getValue'); |
| 97 | + |
| 98 | + $this->windowsSmtpConfig->beforeSendMessage($this->transportMock); |
| 99 | + } |
| 100 | +} |
0 commit comments