This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom DSN validation for Sparkpost region
- Loading branch information
1 parent
a446c7a
commit f53045c
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,20 @@ | |
use Symfony\Component\HttpClient\Response\MockResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
|
||
class SparkpostTransportTest extends MauticMysqlTestCase | ||
{ | ||
private TranslatorInterface $translator; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->configParams['mailer_dsn'] = 'mautic+sparkpost+api://:some_api@some_host:25?region=us'; | ||
$this->configParams['messenger_dsn_email'] = 'sync://'; | ||
$this->configParams['mailer_custom_headers'] = ['x-global-custom-header' => 'value123']; | ||
$this->configParams['mailer_from_email'] = '[email protected]'; | ||
parent::setUp(); | ||
$this->translator = self::getContainer()->get('translator'); | ||
} | ||
|
||
public function testEmailSendToContactSync(): void | ||
|
@@ -114,4 +118,45 @@ private function createContact(string $email): Lead | |
|
||
return $lead; | ||
} | ||
|
||
/** | ||
* @dataProvider dataInvalidDsn | ||
* | ||
* @param array<string, string> $data | ||
*/ | ||
public function testInvalidDsn(array $data, string $expectedMessage): void | ||
{ | ||
// Request config edit page | ||
$crawler = $this->client->request(Request::METHOD_GET, '/s/config/edit'); | ||
Assert::assertTrue($this->client->getResponse()->isOk()); | ||
|
||
// Set form data | ||
$form = $crawler->selectButton('config[buttons][save]')->form(); | ||
$form->setValues($data + ['config[leadconfig][contact_columns]' => ['name', 'email', 'id']]); | ||
|
||
// Check if there is the given validation error | ||
$crawler = $this->client->submit($form); | ||
Assert::assertTrue($this->client->getResponse()->isOk()); | ||
Assert::assertStringContainsString($this->translator->trans($expectedMessage, [], 'validators'), $crawler->text()); | ||
} | ||
|
||
/** | ||
* @return array<string, mixed[]> | ||
*/ | ||
public function dataInvalidDsn(): iterable | ||
{ | ||
yield 'Empty region' => [ | ||
[ | ||
'config[emailconfig][mailer_dsn][options][list][0][value]' => '', | ||
], | ||
'mautic.sparkpost.plugin.region.empty' | ||
]; | ||
|
||
yield 'Invalid region' => [ | ||
[ | ||
'config[emailconfig][mailer_dsn][options][list][0][value]' => 'invalid_region', | ||
], | ||
'mautic.sparkpost.plugin.region.invalid' | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mautic.sparkpost.plugin.region.empty="Sparkpost region is empty. Add 'region' as a option." | ||
mautic.sparkpost.plugin.region.invalid="Sparkpost region is invalid. Add 'us' or 'eu' as a suitable region." |