3 require_once 'PHPUnit/Framework.php';
9 * @copyright Copyright (c)2002 - 2007, 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
::SwapCssClasses('1', '2');
25 $this->assertEquals('2', BSFunctions
::$cssClass);
27 BSFunctions
::SwapCssClasses('1', '2');
28 $this->assertEquals('1', BSFunctions
::$cssClass);
30 BSFunctions
::SwapCssClasses('1', '2');
31 $this->assertEquals('2', BSFunctions
::$cssClass);
34 public function testFetchSourcePath()
36 $this->assertEquals('a' . DIRECTORY_SEPARATOR
, BSFunctions
::FetchSourcePath('a'));
39 public function testDownloadFile()
44 public function testIsValidEmail()
46 $this->assertTrue(BSFunctions
::IsValidEmail('test@example.com'));
47 $this->assertTrue(BSFunctions
::IsValidEmail('test@example.co.uk'));
48 $this->assertTrue(BSFunctions
::IsValidEmail('test.foo_hi@example.edu.k12.paloalto.ca.us'));
50 $this->assertFalse(BSFunctions
::IsValidEmail(''));
51 $this->assertFalse(BSFunctions
::IsValidEmail('te#st@example.com'));
52 $this->assertFalse(BSFunctions
::IsValidEmail('@example.com'));
53 $this->assertFalse(BSFunctions
::IsValidEmail('test@.com'));
56 public function testIsBrowser()
61 public function testRandom()
64 for ($i = 0; $i < 100; $i++
)
66 $random = BSFunctions
::Random(5);
67 $this->assertEquals(5, strlen($random));
68 $this->assertFalse(in_array($random, $values));
73 public function testArraySetCurrent()
75 $array = array('a', 'b', 'c', 'd');
77 $this->assertEquals('a', current($array));
78 $this->assertEquals('b', next($array));
79 $this->assertEquals('c', next($array));
81 BSFunctions
::ArraySetCurrent($array, 0);
82 $this->assertEquals('a', current($array));
84 BSFunctions
::ArraySetCurrent($array, 3);
85 $this->assertEquals('d', current($array));
88 public function testFetchMicrotimeDiff()
93 public function testFetchExtension()
95 $this->assertEquals('txt', BSFunctions
::FetchExtension('test.txt'));
96 $this->assertEquals('', BSFunctions
::FetchExtension('test'));
97 $this->assertEquals('xml', BSFunctions
::FetchExtension('test.file.xml'));
100 public function testFetchMaxPhpFileSize()
105 public function testScanDirectory()
110 public function testConvertLineBreaks()
112 $string = "test\r\nstring\r\n";
113 $this->assertFalse(strpos("\r", BSFunctions
::ConvertLineBreaks($string)));
116 public function testArrayStripEmpty()
118 $array = array(1, 4, 6);
119 $this->assertEquals(3, sizeof(BSFunctions
::ArrayStripEmpty($array)));
121 $array = array(1, 0, 5, '');
122 $this->assertEquals(2, sizeof(BSFunctions
::ArrayStripEmpty($array)));
124 $array = array('', 'test' => array('', 6));
125 $array = BSFunctions
::ArrayStripEmpty($array);
126 $this->assertEquals(1, sizeof($array));
127 $this->assertEquals(1, sizeof($array['test']));