/
UtilsTest.php
84 lines (70 loc) · 2.66 KB
/
UtilsTest.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
84
<?php
/**
* Munee: Optimising Your Assets
*
* @copyright Cody Lundquist 2012
* @license http://opensource.org/licenses/mit-license.php
*/
namespace munee\cases;
use munee\Utils;
/**
* Tests for the \munee\Utils Class
*
* @author Cody Lundquist
*/
class UtilsTest extends \PHPUnit_Framework_TestCase
{
/**
* Can Create/Remove Directories?
*/
public function testCreateRemoveDirectories()
{
$testDir = WEBROOT . DS . 'test' . DS . 'sub_dir';
$this->assertFalse(is_dir($testDir));
Utils::createDir($testDir);
$this->assertTrue(is_dir($testDir));
Utils::removeDir(WEBROOT . DS . 'test');
}
/**
* Lets test all types of serialisation!
*/
public function testIsSerialized()
{
$notSerializedString = 'nope';
$this->assertFalse(Utils::isSerialized($notSerializedString));
$notString = 42;
$this->assertFalse(Utils::isSerialized($notString));
$wrongQuotesSerial = "s:1:'foo';";
$this->assertFalse(Utils::isSerialized($wrongQuotesSerial));
$malformedStringSerial = 's:1:"foo";';
$this->assertFalse(Utils::isSerialized($malformedStringSerial));
$correctStringSerial = 's:3:"foo";';
$this->assertTrue(Utils::isSerialized($correctStringSerial));
$malformedArraySerial = 'a:1:{s:1:"foo";}';
$this->assertFalse(Utils::isSerialized($malformedArraySerial));
$correctArraySerial = 'a:1:{s:3:"foo";s:3:"bar";}';
$this->assertTrue(Utils::isSerialized($correctArraySerial));
$malformedObjectSerial = 'O8:"stdClass":0:{}';
$this->assertFalse(Utils::isSerialized($malformedObjectSerial));
$malformedObjectSerial = 'O:::"stdClass":0:{}';
$this->assertFalse(Utils::isSerialized($malformedObjectSerial));
$correctObjectSerial = 'O:8:"stdClass":0:{}';
$this->assertTrue(Utils::isSerialized($correctObjectSerial));
$malformedNullSerial = 'N:';
$this->assertFalse(Utils::isSerialized($malformedNullSerial));
$correctNullSerial = 'N;';
$this->assertTrue(Utils::isSerialized($correctNullSerial));
$isTrue = false;
$serializedTrue = 'b:1;';
$this->assertTrue(Utils::isSerialized($serializedTrue, $isTrue));
$this->assertTrue($isTrue);
$isFalse = false;
$serializedFalse = 'b:0;';
$this->assertTrue(Utils::isSerialized($serializedFalse, $isFalse));
$this->assertFalse($isFalse);
$checkArray = array('foo' => 'bar');
$testArray = array();
Utils::isSerialized('a:1:{s:3:"foo";s:3:"bar";}', $testArray);
$this->assertSame($checkArray, $testArray);
}
}