|
13 | 13 | use Symfony\Component\HttpClient\Response\MockResponse;
|
14 | 14 | use Symfony\Component\HttpFoundation\Request;
|
15 | 15 | use Symfony\Contracts\HttpClient\HttpClientInterface;
|
| 16 | +use Symfony\Contracts\Translation\TranslatorInterface; |
16 | 17 |
|
17 | 18 | class SparkpostTransportTest extends MauticMysqlTestCase
|
18 | 19 | {
|
| 20 | + private TranslatorInterface $translator; |
| 21 | + |
19 | 22 | protected function setUp(): void
|
20 | 23 | {
|
21 | 24 | $this->configParams['mailer_dsn'] = 'mautic+sparkpost+api://:some_api@some_host:25?region=us';
|
22 | 25 | $this->configParams['messenger_dsn_email'] = 'sync://';
|
23 | 26 | $this->configParams['mailer_custom_headers'] = ['x-global-custom-header' => 'value123'];
|
24 | 27 | $this-> configParams[ 'mailer_from_email'] = '[email protected]';
|
25 | 28 | parent::setUp();
|
| 29 | + $this->translator = self::getContainer()->get('translator'); |
26 | 30 | }
|
27 | 31 |
|
28 | 32 | public function testEmailSendToContactSync(): void
|
@@ -114,4 +118,45 @@ private function createContact(string $email): Lead
|
114 | 118 |
|
115 | 119 | return $lead;
|
116 | 120 | }
|
| 121 | + |
| 122 | + /** |
| 123 | + * @dataProvider dataInvalidDsn |
| 124 | + * |
| 125 | + * @param array<string, string> $data |
| 126 | + */ |
| 127 | + public function testInvalidDsn(array $data, string $expectedMessage): void |
| 128 | + { |
| 129 | + // Request config edit page |
| 130 | + $crawler = $this->client->request(Request::METHOD_GET, '/s/config/edit'); |
| 131 | + Assert::assertTrue($this->client->getResponse()->isOk()); |
| 132 | + |
| 133 | + // Set form data |
| 134 | + $form = $crawler->selectButton('config[buttons][save]')->form(); |
| 135 | + $form->setValues($data + ['config[leadconfig][contact_columns]' => ['name', 'email', 'id']]); |
| 136 | + |
| 137 | + // Check if there is the given validation error |
| 138 | + $crawler = $this->client->submit($form); |
| 139 | + Assert::assertTrue($this->client->getResponse()->isOk()); |
| 140 | + Assert::assertStringContainsString($this->translator->trans($expectedMessage, [], 'validators'), $crawler->text()); |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * @return array<string, mixed[]> |
| 145 | + */ |
| 146 | + public function dataInvalidDsn(): iterable |
| 147 | + { |
| 148 | + yield 'Empty region' => [ |
| 149 | + [ |
| 150 | + 'config[emailconfig][mailer_dsn][options][list][0][value]' => '', |
| 151 | + ], |
| 152 | + 'mautic.sparkpost.plugin.region.empty' |
| 153 | + ]; |
| 154 | + |
| 155 | + yield 'Invalid region' => [ |
| 156 | + [ |
| 157 | + 'config[emailconfig][mailer_dsn][options][list][0][value]' => 'invalid_region', |
| 158 | + ], |
| 159 | + 'mautic.sparkpost.plugin.region.invalid' |
| 160 | + ]; |
| 161 | + } |
117 | 162 | }
|
0 commit comments