|
| 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\Framework\Mail\Test\Unit; |
| 9 | + |
| 10 | +use Magento\Framework\Mail\AddressConverter; |
| 11 | +use Magento\Framework\Mail\AddressFactory; |
| 12 | +use Magento\Framework\Mail\Address; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class AddressConverterTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @var Address |
| 19 | + */ |
| 20 | + private $addressMock; |
| 21 | + |
| 22 | + /** |
| 23 | + * @var AddressFactory |
| 24 | + */ |
| 25 | + private $addressFactoryMock; |
| 26 | + |
| 27 | + /** |
| 28 | + * @var AddressConverter |
| 29 | + */ |
| 30 | + private $addressConverter; |
| 31 | + |
| 32 | + protected function setUp(): void |
| 33 | + { |
| 34 | + $this->addressMock = $this->createMock(Address::class); |
| 35 | + $this->addressFactoryMock = $this->createMock(AddressFactory::class); |
| 36 | + $this->addressConverter = new AddressConverter($this->addressFactoryMock); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @param string $email |
| 41 | + * @param string $name |
| 42 | + * @param string $emailExpected |
| 43 | + * @param string $nameExpected |
| 44 | + * @dataProvider convertDataProvider |
| 45 | + */ |
| 46 | + public function testConvert(string $email, string $name, string $emailExpected, string $nameExpected) |
| 47 | + { |
| 48 | + $this->addressFactoryMock->expects($this->once()) |
| 49 | + ->method('create') |
| 50 | + ->with(['name' => $nameExpected, 'email' => $emailExpected]) |
| 51 | + ->willReturn($this->addressMock); |
| 52 | + $address = $this->addressConverter->convert($email, $name); |
| 53 | + $this->assertInstanceOf(Address::class, $address); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @return array |
| 58 | + */ |
| 59 | + public function convertDataProvider(): array |
| 60 | + { |
| 61 | + return [ |
| 62 | + [ |
| 63 | + 'email' => 'test@example.com', |
| 64 | + 'name' => 'Test', |
| 65 | + 'emailExpected' => 'test@example.com', |
| 66 | + 'nameExpected' => 'Test' |
| 67 | + ], |
| 68 | + [ |
| 69 | + 'email' => 'tést@example.com', |
| 70 | + 'name' => 'Test', |
| 71 | + 'emailExpected' => 'xn--tst-bma@example.com', |
| 72 | + 'nameExpected' => 'Test' |
| 73 | + ] |
| 74 | + ]; |
| 75 | + } |
| 76 | +} |
0 commit comments