PostFileTest.php
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace GuzzleHttp\Tests\Post;
use GuzzleHttp\Post\MultipartBody;
use GuzzleHttp\Post\PostFile;
use GuzzleHttp\Stream\Stream;
/**
* @covers GuzzleHttp\Post\PostFile
*/
class PostFileTest extends \PHPUnit_Framework_TestCase
{
public function testCreatesFromString()
{
$p = new PostFile('foo', 'hi', '/path/to/test.php');
$this->assertInstanceOf('GuzzleHttp\Post\PostFileInterface', $p);
$this->assertEquals('hi', $p->getContent());
$this->assertEquals('foo', $p->getName());
$this->assertEquals('/path/to/test.php', $p->getFilename());
$this->assertEquals(
'form-data; name="foo"; filename="test.php"',
$p->getHeaders()['Content-Disposition']
);
}
public function testGetsFilenameFromMetadata()
{
$p = new PostFile('foo', fopen(__FILE__, 'r'));
$this->assertEquals(__FILE__, $p->getFilename());
}
public function testDefaultsToNameWhenNoFilenameExists()
{
$p = new PostFile('foo', 'bar');
$this->assertEquals('foo', $p->getFilename());
}
public function testCreatesFromMultipartFormData()
{
$mp = new MultipartBody([], [], 'baz');
$p = new PostFile('foo', $mp);
$this->assertEquals(
'form-data; name="foo"',
$p->getHeaders()['Content-Disposition']
);
$this->assertEquals(
'multipart/form-data; boundary=baz',
$p->getHeaders()['Content-Type']
);
}
public function testCanAddHeaders()
{
$p = new PostFile('foo', Stream::factory('hi'), 'test.php', [
'X-Foo' => '123',
'Content-Disposition' => 'bar'
]);
$this->assertEquals('bar', $p->getHeaders()['Content-Disposition']);
$this->assertEquals('123', $p->getHeaders()['X-Foo']);
}
}