This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mime.php
83 lines (73 loc) · 2.37 KB
/
Mime.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Unit test cases for the T_Mime class.
*
* @package coreTests
* @author Rob Tuley
* @version SVN: $Id$
* @license http://knotwerk.com/licence MIT
*/
/**
* T_Mime unit test cases.
*
* @package coreTests
*/
class T_Test_Mime extends T_Unit_Case
{
function testMimeReturnsTypeFromConstructor()
{
$mime = new T_Mime(T_Mime::GIF);
$this->assertSame($mime->getType(),T_Mime::GIF);
}
function testFailureIfCreatedWithInvalidType()
{
try {
$mime = new T_Mime('not_a_mime');
$this->fail();
} catch (InvalidArgumentException $e) {}
}
function testEachMimeConstantIsUnique()
{
$reflect = new ReflectionClass('T_Mime');
$constants = $reflect->getConstants();
$values = array();
foreach ($constants as $key => $int) {
$this->assertTrue(is_integer($int),"$key is int");
$this->assertFalse(isset($values[$int]),"$key is repeated");
$values[$int] = true;
}
}
function testConstantsAreAllInUppercase()
{
$reflect = new ReflectionClass('T_Mime');
$constants = $reflect->getConstants();
foreach ($constants as $name => $int) {
$this->assertSame(strcmp($name,strtoupper($name)),0,"$name is uppercase");
}
}
function testEachMimeTypeRelatesToAString()
{
$reflect = new ReflectionClass('T_Mime');
$constants = $reflect->getConstants();
foreach ($constants as $key => $type) {
$mime = new T_Mime($type);
$str = $mime->__toString();
$this->assertTrue(is_string($str),"$key is string mime");
$this->assertTrue(strlen($str)>0,"$key mime str has length");
}
}
function testCanCreateMimeFromString()
{
$this->assertEquals(new T_Mime(T_Mime::JPEG),T_Mime::getByString('image/jpeg'));
$this->assertEquals(new T_Mime(T_Mime::XHTML),T_Mime::getByString('text/html'));
}
function testCanCreateSameMimeFromMoreThanOneDiffMimeString()
{
$this->assertEquals(new T_Mime(T_Mime::XML),T_Mime::getByString('text/xml'));
$this->assertEquals(new T_Mime(T_Mime::XML),T_Mime::getByString('application/xml'));
}
function testBinaryIsDefaultIfCannotMatchString()
{
$this->assertEquals(new T_Mime(T_Mime::BINARY),T_Mime::getByString('not_a_mime'));
}
}