Adding fixes in the unit tests for all the refactoring we did
[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 - 2008, 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 $this->assertEquals('', BSFunctions::$cssClass);
23
24 BSFunctions::swap_css_classes('1', '2');
25 $this->assertEquals('2', BSFunctions::$cssClass);
26
27 BSFunctions::swap_css_classes('1', '2');
28 $this->assertEquals('1', BSFunctions::$cssClass);
29
30 BSFunctions::swap_css_classes('1', '2');
31 $this->assertEquals('2', BSFunctions::$cssClass);
32 }
33
34 public function testFetchSourcePath()
35 {
36 $this->assertEquals('a' . DIRECTORY_SEPARATOR, BSFunctions::fetch_source_path('a'));
37 }
38
39 public function testDownloadFile()
40 {
41
42 }
43
44 public function testIsValidEmail()
45 {
46 $this->assertTrue(BSFunctions::is_valid_email('test@example.com'));
47 $this->assertTrue(BSFunctions::is_valid_email('test@example.co.uk'));
48 $this->assertTrue(BSFunctions::is_valid_email('test.foo_hi@example.edu.k12.paloalto.ca.us'));
49
50 $this->assertFalse(BSFunctions::is_valid_email(''));
51 $this->assertFalse(BSFunctions::is_valid_email('te#st@example.com'));
52 $this->assertFalse(BSFunctions::is_valid_email('@example.com'));
53 $this->assertFalse(BSFunctions::is_valid_email('test@.com'));
54 }
55
56 public function testIsBrowser()
57 {
58
59 }
60
61 public function testRandom()
62 {
63 $values = array();
64 for ($i = 0; $i < 100; $i++)
65 {
66 $random = BSFunctions::random(5);
67 $this->assertEquals(5, strlen($random));
68 $this->assertFalse(in_array($random, $values));
69 $values[] = $random;
70 }
71 }
72
73 public function testArraySetCurrent()
74 {
75 $array = array('a', 'b', 'c', 'd');
76
77 $this->assertEquals('a', current($array));
78 $this->assertEquals('b', next($array));
79 $this->assertEquals('c', next($array));
80
81 BSFunctions::array_set_current($array, 0);
82 $this->assertEquals('a', current($array));
83
84 BSFunctions::array_set_current($array, 3);
85 $this->assertEquals('d', current($array));
86 }
87
88 public function testFetchMicrotimeDiff()
89 {
90
91 }
92
93 public function testFetchExtension()
94 {
95 $this->assertEquals('txt', BSFunctions::fetch_extension('test.txt'));
96 $this->assertEquals('', BSFunctions::fetch_extension('test'));
97 $this->assertEquals('xml', BSFunctions::fetch_extension('test.file.xml'));
98 }
99
100 public function testFetchMaxPhpFileSize()
101 {
102
103 }
104
105 public function testScanDirectory()
106 {
107
108 }
109
110 public function testConvertLineBreaks()
111 {
112 $string = "test\r\nstring\r\n";
113 $this->assertFalse(strpos("\r", BSFunctions::convert_line_breaks($string)));
114 }
115
116 public function testArrayStripEmpty()
117 {
118 $array = array(1, 4, 6);
119 $this->assertEquals(3, sizeof(BSFunctions::array_strip_empty($array)));
120
121 $array = array(1, 0, 5, '');
122 $this->assertEquals(2, sizeof(BSFunctions::array_strip_empty($array)));
123
124 $array = array('', 'test' => array('', 6));
125 $array = BSFunctions::array_strip_empty($array);
126 $this->assertEquals(1, sizeof($array));
127 $this->assertEquals(1, sizeof($array['test']));
128 }
129 }
130
131 ?>