|
| 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\App\ObjectManager; |
| 13 | +use Magento\Framework\ObjectManager\Config\Config; |
| 14 | +use Magento\Framework\ObjectManager\Factory\Dynamic\Developer; |
| 15 | +use Magento\Framework\ObjectManager\Relations\Runtime; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +class AddressConverterTest extends TestCase |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var ObjectManager |
| 22 | + */ |
| 23 | + private $objectManager; |
| 24 | + |
| 25 | + protected function setUp(): void |
| 26 | + { |
| 27 | + $config = new Config( |
| 28 | + new Runtime() |
| 29 | + ); |
| 30 | + $factory = new Developer( |
| 31 | + $config |
| 32 | + ); |
| 33 | + $this->objectManager = new ObjectManager($factory, $config); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @param string $email |
| 38 | + * @param string $name |
| 39 | + * @param string $emailExpected |
| 40 | + * @param string $nameExpected |
| 41 | + * @dataProvider convertDataProvider |
| 42 | + */ |
| 43 | + public function testConvert(string $email, string $name, string $emailExpected, string $nameExpected) |
| 44 | + { |
| 45 | + $addressFactory = new AddressFactory($this->objectManager); |
| 46 | + $addressConverter = new AddressConverter($addressFactory); |
| 47 | + $address = $addressConverter->convert($email, $name); |
| 48 | + $this->assertSame($emailExpected, $address->getEmail()); |
| 49 | + $this->assertSame($nameExpected, $address->getName()); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @return array |
| 54 | + */ |
| 55 | + public function convertDataProvider(): array |
| 56 | + { |
| 57 | + return [ |
| 58 | + [ |
| 59 | + |
| 60 | + 'name' => 'Test', |
| 61 | + 'emailExpected' => '[email protected]', |
| 62 | + 'nameExpected' => 'Test' |
| 63 | + ], |
| 64 | + [ |
| 65 | + |
| 66 | + 'name' => 'Test', |
| 67 | + 'emailExpected' => '[email protected]', |
| 68 | + 'nameExpected' => 'Test' |
| 69 | + ] |
| 70 | + ]; |
| 71 | + } |
| 72 | +} |
0 commit comments