Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a test, updating CI #4

Merged
merged 24 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:

strategy:
matrix:
php-versions: ['8.0'] # The supported PHP versions
php-versions: ['8.1'] # The supported PHP versions
db-types: ['mysql'] # can be: ['mysql', 'mariadb'] but not necessary for this plugin that does not add any DB schema
mautic-versions: ['5.x'] # The supported Mautic versions
mautic-versions: [6.x] # The supported Mautic versions

name: Tests on PHP ${{ matrix.php-versions }}, ${{ matrix.db-types }}, Mautic ${{ matrix.mautic-versions }}

Expand All @@ -40,7 +40,7 @@ jobs:
--health-retries=3

steps:
- name: Checkout Mautic 5
- name: Checkout Mautic
uses: actions/checkout@v3
with:
repository: mautic/mautic
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
verbose: true

- name: Upload logs as artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mautic-logs
path: var/logs/
57 changes: 57 additions & 0 deletions Tests/Functional/EventSubscriber/CallbackSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

namespace MauticPlugin\SparkpostBundle\Tests\Functional\EventSubscriber;

use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\CoreBundle\Helper\DateTimeHelper;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\EmailBundle\EmailEvents;
use Mautic\EmailBundle\Entity\Stat;
use Mautic\EmailBundle\Event\TransportWebhookEvent;
use Mautic\EmailBundle\Model\TransportCallback;
use Mautic\LeadBundle\Entity\DoNotContact;
use Mautic\LeadBundle\Entity\Lead;
use MauticPlugin\SparkpostBundle\EventSubscriber\CallbackSubscriber;
use PHPUnit\Framework\Assert;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;

class CallbackSubscriberTest extends MauticMysqlTestCase
Expand Down Expand Up @@ -198,4 +204,55 @@ private function getCommentAndReason(string $type): array
],
};
}

/**
* For the message with 'type': 'out of band' and 'bounce class': 60 should never be called transportCallback.
*/
public function testProcessCallbackRequestWhenSoftBounce(): void
{
$payload = <<<JSON
[
{
"msys": {
"message_event": {
"reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
"msg_from":"msprvs1=18290qww0ygol=bounces-44585-172@bounces.mauticsparkt3.com",
"event_id":"13251575597141532",
"raw_reason":"550 [internal] [oob] The message is an auto-reply/vacation mail.",
"error_code":"550",
"subaccount_id":172,
"delv_method":"esmtp",
"customer_id":44585,
"type":"out_of_band",
"bounce_class":"60",
"timestamp":"2020-01-22T21:59:32.000Z"
}
}
}
]
JSON;
$request = new Request([], json_decode($payload, true));
$event = new TransportWebhookEvent($request);

$dispatcher = new EventDispatcher();

$transportCallback = $this->getMockBuilder(TransportCallback::class)->disableOriginalConstructor()->getMock();
$coreParametersHelper = $this->getMockBuilder(CoreParametersHelper::class)->disableOriginalConstructor()->getMock();

$coreParametersHelper->method('get')
->with('mailer_dsn')
->willReturn('mautic+sparkpost+api://:some_api@some_host:25?region=us');

$subscriber = new CallbackSubscriber(
$transportCallback,
$coreParametersHelper
);

$dispatcher->addSubscriber($subscriber);

$dispatcher->dispatch($event, EmailEvents::ON_TRANSPORT_WEBHOOK);

$transportCallback->expects($this->never())
->method($this->anything());
}
}
15 changes: 10 additions & 5 deletions Tests/Functional/Mailer/Transport/SparkpostTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ function ($method, $url, $options): MockResponse {
$mockHttpClient = self::getContainer()->get(HttpClientInterface::class);
$mockHttpClient->setResponseFactory($expectedResponses);

$userHelper = static::getContainer()->get(UserHelper::class);
$user = $userHelper->getUser();

$contact = $this->createContact('[email protected]');
$this->em->flush();

$this->client->request(Request::METHOD_GET, "/s/contacts/email/{$contact->getId()}");
Assert::assertTrue($this->client->getResponse()->isOk());
$this->assertResponseIsSuccessful();

// User's email address should be pre-filled in the form.
Assert::assertStringContainsString($user->getEmail(), $this->client->getResponse()->getContent());

$newContent = json_decode($this->client->getResponse()->getContent(), true)['newContent'];
$crawler = new Crawler($newContent, $this->client->getInternalRequest()->getUri());
$form = $crawler->selectButton('Send')->form();
Expand All @@ -68,12 +75,10 @@ function ($method, $url, $options): MockResponse {
]
);
$this->client->submit($form);
Assert::assertTrue($this->client->getResponse()->isOk());
$this->assertResponseIsSuccessful();
self::assertQueuedEmailCount(1);

$email = self::getMailerMessage();
$userHelper = static::getContainer()->get(UserHelper::class);
$user = $userHelper->getUser();
$email = self::getMailerMessage();

Assert::assertSame('Hello there!', $email->getSubject());
Assert::assertStringContainsString('This is test body for {contactfield=email}!', $email->getHtmlBody());
Expand Down
Loading