mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-25 14:26:04 +03:00
e177e13a0c
* Update boundary regex to match RFC1341
46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (C) 2013-2016 Mailgun
|
|
*
|
|
* This software may be modified and distributed under the terms
|
|
* of the MIT license. See the LICENSE file for details.
|
|
*/
|
|
|
|
namespace Mailgun\Tests;
|
|
|
|
use Mailgun\RequestBuilder;
|
|
|
|
class RequestBuilderTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testCreateSimpleStream()
|
|
{
|
|
$builder = new RequestBuilder();
|
|
$request = $builder->create('GET', 'http://foo.bar', ['Content-Type' => 'application/json'], 'content');
|
|
|
|
$body = $request->getBody()->__toString();
|
|
$contentType = $request->getHeaderLine('Content-Type');
|
|
|
|
$this->assertContains('content', $body);
|
|
$this->assertEquals('application/json', $contentType);
|
|
}
|
|
|
|
public function testCreateMultipartStream()
|
|
{
|
|
$item0 = ['content' => 'foobar', 'name' => 'username'];
|
|
$item1 = ['content' => 'Stockholm', 'name' => 'city'];
|
|
|
|
$builder = new RequestBuilder();
|
|
$request = $builder->create('GET', 'http://foo.bar', ['Content-Type' => 'application/json'], [$item0, $item1]);
|
|
|
|
$body = $request->getBody()->__toString();
|
|
$contentType = $request->getHeaderLine('Content-Type');
|
|
|
|
$this->assertContains('foobar', $body);
|
|
$this->assertContains('username', $body);
|
|
$this->assertContains('Stockholm', $body);
|
|
$this->assertContains('city', $body);
|
|
$this->assertRegExp('|^multipart/form-data; boundary=(?P<quote>"?)[\w\Q\'()+,-./:=?\E]{1,69}(?P=quote)$|si', $contentType);
|
|
}
|
|
}
|