]> src.bluestatic.org Git - isso.git/blob - UnitTest/FunctionsTest.php
Renaming all the classes for the Printer to match the name of the file
[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 // test fixed length
59 $values = array();
60 for ($i = 0; $i < 100; $i++)
61 {
62 $random = BSFunctions::random(5);
63 $this->assertEquals(5, strlen($random));
64 $values[] = $random;
65 }
66 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
67
68 // test random length
69 $values = array();
70 for ($i = 0; $i < 100; $i++)
71 {
72 $random = BSFunctions::random();
73 $length = strlen($random);
74 $this->assertTrue($length >= 20 && $length <= 65);
75 $values[] = $random;
76 }
77 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
78 }
79
80 public function testArraySetCurrent()
81 {
82 $array = array('a', 'b', 'c', 'd');
83
84 $this->assertEquals('a', current($array));
85 $this->assertEquals('b', next($array));
86 $this->assertEquals('c', next($array));
87
88 BSFunctions::array_set_current($array, 0);
89 $this->assertEquals('a', current($array));
90
91 BSFunctions::array_set_current($array, 3);
92 $this->assertEquals('d', current($array));
93 }
94
95 public function testFetchMicrotimeDiff()
96 {
97
98 }
99
100 public function testFetchExtension()
101 {
102 $this->assertEquals('txt', BSFunctions::fetch_extension('test.txt'));
103 $this->assertEquals('', BSFunctions::fetch_extension('test'));
104 $this->assertEquals('xml', BSFunctions::fetch_extension('test.file.xml'));
105 }
106
107 public function testFetchMaxPhpFileSize()
108 {
109
110 }
111
112 public function testScanDirectory()
113 {
114
115 }
116
117 public function testConvertLineBreaks()
118 {
119 $string = "test\r\nstring\r\n";
120 $this->assertFalse(strpos("\r", BSFunctions::convert_line_breaks($string)));
121 }
122
123 public function testArrayStripEmpty()
124 {
125 $array = array(1, 4, 6);
126 $this->assertEquals(3, sizeof(BSFunctions::array_strip_empty($array)));
127
128 $array = array(1, 0, 5, '');
129 $this->assertEquals(2, sizeof(BSFunctions::array_strip_empty($array)));
130
131 $array = array('', 'test' => array('', 6));
132 $array = BSFunctions::array_strip_empty($array);
133 $this->assertEquals(1, sizeof($array));
134 $this->assertEquals(1, sizeof($array['test']));
135 }
136 }
137
138 ?>