3 // Copyright (c) 2011 Blue Static
5 // This program is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License as published by the Free
7 // Software Foundation, either version 3 of the License, or any later version.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program. If not, see <http://www.gnu.org/licenses/>.
17 namespace hoplite\test
;
18 use hoplite\base
as base
;
20 require_once HOPLITE_ROOT
. '/base/functions.php';
22 class FunctionsTest
extends \PHPUnit_Framework_TestCase
24 public function testArrayStripEmpty()
26 $array = array(1, 4, 6);
27 base\
ArrayStripEmpty($array);
28 $this->assertEquals(3, count($array));
30 $array = array(1, 0, 5, '');
31 base\
ArrayStripEmpty($array);
32 $this->assertEquals(2, count($array));
34 $array = array('', 'test' => array('', 6));
35 base\
ArrayStripEmpty($array);
36 $this->assertEquals(1, count($array));
37 $this->assertEquals(1, count($array['test']));
39 $array = array('foo', NULL, 'bar');
40 base\
ArrayStripEmpty($array);
41 $this->assertEquals(2, count($array));
44 public function testUnderscoreToCamelCase()
47 $this->assertEquals('UnderScore', base\
UnderscoreToCamelCase($str));
48 $this->assertEquals('underScore', base\
UnderscoreToCamelCase($str, FALSE));
50 $str = 'many_many_under_scores';
51 $this->assertEquals('ManyManyUnderScores', base\
UnderscoreToCamelCase($str));
54 public function testCamelCaseToUnderscore()
57 $this->assertEquals('camel_case', base\
CamelCaseToUnderscore($str));
60 $this->assertEquals('camel_case', base\
CamelCaseToUnderscore($str));
62 $str = 'AVeryLongTitleCase';
63 $this->assertEquals('a_very_long_title_case', base\
CamelCaseToUnderscore($str));
66 protected function _RandomHelper($arg, $lower, $upper)
69 for ($i = 0; $i < 200; $i++
)
71 $rand = base\
Random($arg);
72 $this->assertNotContains($rand, $list, 'Duplicate random string!');
74 $this->assertGreaterThanOrEqual($lower, strlen($rand), 'Random string not in lower bound');
75 $this->assertLessThanOrEqual($upper, strlen($rand), 'Random string not in upper bound');
79 public function testRandomDefault()
81 $this->_RandomHelper(NULL, 20, 100);
84 public function testRandomArgument()
86 $this->_RandomHelper(20, 20, 20);