2016-08-10 18:06:27 +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:06:27 +03:00
|
|
|
namespace Mailgun\Tests\Functional;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
|
|
|
|
*/
|
|
|
|
class InlineFileTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testSimpleExample()
|
|
|
|
{
|
2016-09-18 10:56:14 +03:00
|
|
|
$fileValidator = function ($files) {
|
2016-08-10 18:06:27 +03:00
|
|
|
$fileNames = [
|
2017-04-08 02:24:37 +03:00
|
|
|
['name' => 'inline', 'filename' => 'foo.png'],
|
|
|
|
['name' => 'inline', 'filename' => 'bar.png'],
|
2016-08-10 18:06:27 +03:00
|
|
|
];
|
2016-08-10 18:32:10 +03:00
|
|
|
|
|
|
|
// Make sure that both files exists
|
2016-08-10 18:06:27 +03:00
|
|
|
foreach ($fileNames as $idx => $fileName) {
|
|
|
|
foreach ($files as $file) {
|
|
|
|
if ($file['name'] === $fileName['name'] && $file['filename'] === $fileName['filename']) {
|
2016-09-18 10:56:14 +03:00
|
|
|
unset($fileNames[$idx]);
|
2016-08-10 18:06:27 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEmpty($fileNames, 'Filenames could not be found');
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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:06:27 +03:00
|
|
|
|
|
|
|
$builder = $mailgun->MessageBuilder();
|
2016-09-18 10:56:14 +03:00
|
|
|
$builder->setFromAddress('bob@example.com');
|
|
|
|
$builder->addToRecipient('alice@example.com');
|
|
|
|
$builder->setSubject('Foo');
|
|
|
|
$builder->setTextBody('Bar');
|
2016-08-10 18:06:27 +03:00
|
|
|
|
2016-09-18 10:56:14 +03:00
|
|
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon1.png', 'foo.png');
|
|
|
|
$builder->addInlineImage('@./tests/TestAssets/mailgun_icon2.png', 'bar.png');
|
2016-08-10 18:06:27 +03:00
|
|
|
|
2016-09-18 10:56:14 +03:00
|
|
|
$mailgun->post('domain/messages', $builder->getMessage(), $builder->getFiles());
|
2016-08-10 18:06:27 +03:00
|
|
|
}
|
|
|
|
}
|