3 require_once 'PHPUnit/Framework.php';
9 * @copyright Copyright (c)2005 - 2008, Blue Static
13 class FunctionsTest
extends PHPUnit_Framework_TestCase
15 public function setUp()
17 require_once(ISSO
. '/App.php');
20 public function testSwapCssClasses()
22 $this->assertEquals('', BSFunctions
::$cssClass);
24 BSFunctions
::swap_css_classes('1', '2');
25 $this->assertEquals('2', BSFunctions
::$cssClass);
27 BSFunctions
::swap_css_classes('1', '2');
28 $this->assertEquals('1', BSFunctions
::$cssClass);
30 BSFunctions
::swap_css_classes('1', '2');
31 $this->assertEquals('2', BSFunctions
::$cssClass);
34 public function testFetchSourcePath()
36 $this->assertEquals('a' . DIRECTORY_SEPARATOR
, BSFunctions
::fetch_source_path('a'));
39 public function testDownloadFile()
44 public function testIsValidEmail()
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'));
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'));
56 public function testRandom()
60 for ($i = 0; $i < 100; $i++
)
62 $random = BSFunctions
::random(5);
63 $this->assertEquals(5, strlen($random));
66 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
70 for ($i = 0; $i < 100; $i++
)
72 $random = BSFunctions
::random();
73 $length = strlen($random);
74 $this->assertTrue($length >= 20 && $length <= 65);
77 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
80 public function testArraySetCurrent()
82 $array = array('a', 'b', 'c', 'd');
84 $this->assertEquals('a', current($array));
85 $this->assertEquals('b', next($array));
86 $this->assertEquals('c', next($array));
88 BSFunctions
::array_set_current($array, 0);
89 $this->assertEquals('a', current($array));
91 BSFunctions
::array_set_current($array, 3);
92 $this->assertEquals('d', current($array));
95 public function testFetchMicrotimeDiff()
100 public function testFetchExtension()
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'));
107 public function testFetchMaxPhpFileSize()
112 public function testScanDirectory()
117 public function testConvertLineBreaks()
119 $string = "test\r\nstring\r\n";
120 $this->assertFalse(strpos("\r", BSFunctions
::convert_line_breaks($string)));
123 public function testArrayStripEmpty()
125 $array = array(1, 4, 6);
126 $this->assertEquals(3, sizeof(BSFunctions
::array_strip_empty($array)));
128 $array = array(1, 0, 5, '');
129 $this->assertEquals(2, sizeof(BSFunctions
::array_strip_empty($array)));
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']));