3 require_once 'PHPUnit/Framework.php';
9 * @copyright Copyright (c)2005 - 2009, Blue Static
13 class FunctionsTest
extends PHPUnit_Framework_TestCase
15 public function setUp()
17 require_once(ISSO
. '/App.php');
20 public function testSwapCssClasses()
22 $result = BSFunctions
::swap_css_classes('1', '2');
23 $this->assertEquals('2', $result);
25 $result = BSFunctions
::swap_css_classes('1', '2');
26 $this->assertEquals('1', $result);
28 $result = BSFunctions
::swap_css_classes('1', '2');
29 $this->assertEquals('2', $result);
32 public function testFetchSourcePath()
34 $this->assertEquals('a' . DIRECTORY_SEPARATOR
, BSFunctions
::fetch_source_path('a'));
37 public function testDownloadFile()
42 public function testIsValidEmail()
44 $this->assertTrue(BSFunctions
::is_valid_email('test@example.com'));
45 $this->assertTrue(BSFunctions
::is_valid_email('test@example.co.uk'));
46 $this->assertTrue(BSFunctions
::is_valid_email('test.foo_hi@example.edu.k12.paloalto.ca.us'));
48 $this->assertFalse(BSFunctions
::is_valid_email(''));
49 $this->assertFalse(BSFunctions
::is_valid_email('te#st@example.com'));
50 $this->assertFalse(BSFunctions
::is_valid_email('@example.com'));
51 $this->assertFalse(BSFunctions
::is_valid_email('test@.com'));
54 public function testRandom()
58 for ($i = 0; $i < 100; $i++
)
60 $random = BSFunctions
::random(5);
61 $this->assertEquals(5, strlen($random));
64 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
68 for ($i = 0; $i < 100; $i++
)
70 $random = BSFunctions
::random();
71 $length = strlen($random);
72 $this->assertTrue($length >= 20 && $length <= 65);
75 $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
78 public function testArraySetCurrent()
80 $array = array('a', 'b', 'c', 'd');
82 $this->assertEquals('a', current($array));
83 $this->assertEquals('b', next($array));
84 $this->assertEquals('c', next($array));
86 BSFunctions
::array_set_current($array, 0);
87 $this->assertEquals('a', current($array));
89 BSFunctions
::array_set_current($array, 3);
90 $this->assertEquals('d', current($array));
93 public function testFetchMicrotimeDiff()
98 public function testFetchExtension()
100 $this->assertEquals('txt', BSFunctions
::fetch_extension('test.txt'));
101 $this->assertEquals('', BSFunctions
::fetch_extension('test'));
102 $this->assertEquals('xml', BSFunctions
::fetch_extension('test.file.xml'));
105 public function testFetchMaxPhpFileSize()
110 public function testScanDirectory()
115 public function testConvertLineBreaks()
117 $string = "test\r\nstring\r\n";
118 $this->assertFalse(strpos("\r", BSFunctions
::convert_line_breaks($string)));
121 public function testArrayStripEmpty()
123 $array = array(1, 4, 6);
124 $this->assertEquals(3, sizeof(BSFunctions
::array_strip_empty($array)));
126 $array = array(1, 0, 5, '');
127 $this->assertEquals(2, sizeof(BSFunctions
::array_strip_empty($array)));
129 $array = array('', 'test' => array('', 6));
130 $array = BSFunctions
::array_strip_empty($array);
131 $this->assertEquals(1, sizeof($array));
132 $this->assertEquals(1, sizeof($array['test']));