mailgun-php/tests/Functional/InlineFileTest.php

54 lines
1.7 KiB
PHP
Raw Normal View History

2016-08-10 18:06:27 +03:00
<?php
/*
* Copyright (C) 2013 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-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()
{
$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']) {
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.
$mailgun = MockedMailgun::createMock($this, 'POST', 'domain/messages', [], $fileValidator);
2016-08-10 18:06:27 +03:00
$builder = $mailgun->MessageBuilder();
$builder->setFromAddress('bob@example.com');
$builder->addToRecipient('alice@example.com');
$builder->setSubject('Foo');
$builder->setTextBody('Bar');
2016-08-10 18:06:27 +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
$mailgun->post('domain/messages', $builder->getMessage(), $builder->getFiles());
2016-08-10 18:06:27 +03:00
}
}