Update version.php to 3.3.0
[isso.git] / UnitTest / FunctionsTest.php
1 <?php
2
3 require_once 'PHPUnit/Framework.php';
4
5 /**
6 * Functions Test Suite
7 *
8 * @author Blue Static
9 * @copyright Copyright (c)2005 - 2009, Blue Static
10 * @package ISSO Tests
11 *
12 */
13 class FunctionsTest extends PHPUnit_Framework_TestCase
14 {
15 public function setUp()
16 {
17 require_once(ISSO . '/App.php');
18 }
19
20 public function testSwapCssClasses()
21 {
22 $result = BSFunctions::swap_css_classes('1', '2');
23 $this->assertEquals('2', $result);
24
25 $result = BSFunctions::swap_css_classes('1', '2');
26 $this->assertEquals('1', $result);
27
28 $result = BSFunctions::swap_css_classes('1', '2');
29 $this->assertEquals('2', $result);
30 }
31
32 public function testFetchSourcePath()
33 {
34 $this->assertEquals('a' . DIRECTORY_SEPARATOR, BSFunctions::fetch_source_path('a'));
35 }
36
37 public function testDownloadFile()
38 {
39
40 }
41
42 public function testIsValidEmail()
43 {
44 $this->assertTrue(BSFunctions::is_valid_email('test@example.com'));
45 $this->assertTrue(BSFunctions::is_valid_email('test@example.co.uk'));
46 $this->assertTrue(BSFunctions::is_valid_email('test.foo_hi@example.edu.k12.paloalto.ca.us'));
47
48 $this->assertFalse(BSFunctions::is_valid_email(''));
49 $this->assertFalse(BSFunctions::is_valid_email('te#st@example.com'));
50 $this->assertFalse(BSFunctions::is_valid_email('@example.com'));
51 $this->assertFalse(BSFunctions::is_valid_email('test@.com'));
52 }
53
54 public function testRandom()
55 {
56 // test fixed length
57 $values = array();
58 for ($i = 0; $i < 100; $i++)
59 {
60 $random = BSFunctions::random(5);
61 $this->assertEquals(5, strlen($random));
62 $values[] = $random;
63 }
64 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
65
66 // test random length
67 $values = array();
68 for ($i = 0; $i < 100; $i++)
69 {
70 $random = BSFunctions::random();
71 $length = strlen($random);
72 $this->assertTrue($length >= 20 && $length <= 65);
73 $values[] = $random;
74 }
75 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
76 }
77
78 public function testArraySetCurrent()
79 {
80 $array = array('a', 'b', 'c', 'd');
81
82 $this->assertEquals('a', current($array));
83 $this->assertEquals('b', next($array));
84 $this->assertEquals('c', next($array));
85
86 BSFunctions::array_set_current($array, 0);
87 $this->assertEquals('a', current($array));
88
89 BSFunctions::array_set_current($array, 3);
90 $this->assertEquals('d', current($array));
91 }
92
93 public function testFetchMicrotimeDiff()
94 {
95
96 }
97
98 public function testFetchExtension()
99 {
100 $this->assertEquals('txt', BSFunctions::fetch_extension('test.txt'));
101 $this->assertEquals('', BSFunctions::fetch_extension('test'));
102 $this->assertEquals('xml', BSFunctions::fetch_extension('test.file.xml'));
103 }
104
105 public function testFetchMaxPhpFileSize()
106 {
107
108 }
109
110 public function testScanDirectory()
111 {
112
113 }
114
115 public function testConvertLineBreaks()
116 {
117 $string = "test\r\nstring\r\n";
118 $this->assertFalse(strpos("\r", BSFunctions::convert_line_breaks($string)));
119 }
120
121 public function testArrayStripEmpty()
122 {
123 $array = array(1, 4, 6);
124 $this->assertEquals(3, sizeof(BSFunctions::array_strip_empty($array)));
125
126 $array = array(1, 0, 5, '');
127 $this->assertEquals(2, sizeof(BSFunctions::array_strip_empty($array)));
128
129 $array = array('', 'test' => array('', 6));
130 $array = BSFunctions::array_strip_empty($array);
131 $this->assertEquals(1, sizeof($array));
132 $this->assertEquals(1, sizeof($array['test']));
133 }
134 }
135
136 ?>