2016-08-10 18:13:24 +03:00
|
|
|
<?php
|
|
|
|
|
2016-09-18 10:56:14 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013-2016 Mailgun
|
|
|
|
*
|
|
|
|
* This software may be modified and distributed under the terms
|
2016-12-06 21:12:52 +03:00
|
|
|
* of the MIT license. See the LICENSE file for details.
|
2016-09-18 10:56:14 +03:00
|
|
|
*/
|
|
|
|
|
2016-08-10 18:13:24 +03:00
|
|
|
namespace Mailgun\Tests\Functional;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
|
|
|
*/
|
|
|
|
class NoSamePostNameTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
2016-09-18 10:56:14 +03:00
|
|
|
* No post names should ever be the same.
|
2016-08-10 18:13:24 +03:00
|
|
|
*/
|
|
|
|
public function testNames()
|
|
|
|
{
|
2016-09-18 10:56:14 +03:00
|
|
|
$fileValidator = function ($files) {
|
2016-08-10 18:13:24 +03:00
|
|
|
$usedNames = [];
|
|
|
|
foreach ($files as $file) {
|
|
|
|
$this->assertFalse(in_array($file['name'], $usedNames), 'No files should have the same POST name.');
|
|
|
|
$usedNames[] = $file['name'];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Create the mocked mailgun client. We use $this->assertEquals on $method, $uri and $body parameters.
|
2017-03-25 15:48:03 +03:00
|
|
|
$mailgun = MockedMailgun::createMock($this, 'POST', 'domain/messages', [], $fileValidator);
|
2016-08-10 18:13:24 +03:00
|
|
|
|
|
|
|
$builder = $mailgun->MessageBuilder();
|
2016-09-18 10:56:14 +03:00
|
|
|
$builder->setFromAddress('bob@example.com');
|
|
|
|
$builder->addToRecipient('to1@example.com');
|
|
|
|
$builder->addToRecipient('to2@example.com');
|
|
|
|
$builder->addCcRecipient('cc1@example.com');
|
|
|
|
$builder->addCcRecipient('cc2@example.com');
|
|
|
|
$builder->addBccRecipient('bcc1@example.com');
|
|
|
|
$builder->addBccRecipient('bcc2@example.com');
|
2016-08-10 19:28:19 +03:00
|
|
|
$builder->addCustomParameter('foo', 'bar');
|
|
|
|
$builder->addCustomParameter('foo', 'baz');
|
|
|
|
$builder->addCampaignId('campaign0');
|
|
|
|
$builder->addCampaignId('campaign1');
|
2016-09-18 10:56:14 +03:00
|
|
|
$builder->setSubject('Foo');
|
|
|
|
$builder->setTextBody('Bar');
|
2016-08-10 18:13:24 +03:00
|
|
|
|
2016-09-18 10:56:14 +03:00
|
|
|
$builder->addAttachment('@./tests/TestAssets/mailgun_icon1.png', 'foo.png');
|
|
|
|
$builder->addAttachment('@./tests/TestAssets/mailgun_icon1.png', 'foo.png');
|
|
|
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon2.png', 'bar.png');
|
|
|
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon2.png', 'bar.png');
|
2016-08-10 18:13:24 +03:00
|
|
|
|
2016-09-18 10:56:14 +03:00
|
|
|
$mailgun->post('domain/messages', $builder->getMessage(), $builder->getFiles());
|
2016-08-10 18:13:24 +03:00
|
|
|
}
|
|
|
|
}
|