Removing the is_browser() function
[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 testRandom()
57 {
58 $values = array();
59 for ($i = 0; $i < 100; $i++)
60 {
61 $random = BSFunctions::random(5);
62 $this->assertEquals(5, strlen($random));
63 $this->assertFalse(in_array($random, $values));
64 $values[] = $random;
65 }
66 }
67
68 public function testArraySetCurrent()
69 {
70 $array = array('a', 'b', 'c', 'd');
71
72 $this->assertEquals('a', current($array));
73 $this->assertEquals('b', next($array));
74 $this->assertEquals('c', next($array));
75
76 BSFunctions::array_set_current($array, 0);
77 $this->assertEquals('a', current($array));
78
79 BSFunctions::array_set_current($array, 3);
80 $this->assertEquals('d', current($array));
81 }
82
83 public function testFetchMicrotimeDiff()
84 {
85
86 }
87
88 public function testFetchExtension()
89 {
90 $this->assertEquals('txt', BSFunctions::fetch_extension('test.txt'));
91 $this->assertEquals('', BSFunctions::fetch_extension('test'));
92 $this->assertEquals('xml', BSFunctions::fetch_extension('test.file.xml'));
93 }
94
95 public function testFetchMaxPhpFileSize()
96 {
97
98 }
99
100 public function testScanDirectory()
101 {
102
103 }
104
105 public function testConvertLineBreaks()
106 {
107 $string = "test\r\nstring\r\n";
108 $this->assertFalse(strpos("\r", BSFunctions::convert_line_breaks($string)));
109 }
110
111 public function testArrayStripEmpty()
112 {
113 $array = array(1, 4, 6);
114 $this->assertEquals(3, sizeof(BSFunctions::array_strip_empty($array)));
115
116 $array = array(1, 0, 5, '');
117 $this->assertEquals(2, sizeof(BSFunctions::array_strip_empty($array)));
118
119 $array = array('', 'test' => array('', 6));
120 $array = BSFunctions::array_strip_empty($array);
121 $this->assertEquals(1, sizeof($array));
122 $this->assertEquals(1, sizeof($array['test']));
123 }
124 }
125
126 ?>