Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | // OLD TEST FORMAT: DO NOT COPY |
| 4 | |
| 5 | require_once(BASEPATH.'helpers/array_helper.php'); |
| 6 | |
Greg Aker | b4d93db | 2011-04-21 14:42:33 -0500 | [diff] [blame] | 7 | class Array_helper_test extends CI_TestCase |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 8 | { |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 9 | public function set_up() |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 10 | { |
| 11 | $this->my_array = array( |
| 12 | 'foo' => 'bar', |
| 13 | 'sally' => 'jim', |
| 14 | 'maggie' => 'bessie', |
| 15 | 'herb' => 'cook' |
| 16 | ); |
| 17 | } |
| 18 | |
| 19 | // ------------------------------------------------------------------------ |
| 20 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 21 | public function test_element_with_existing_item() |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 22 | { |
| 23 | $this->assertEquals(FALSE, element('testing', $this->my_array)); |
| 24 | |
| 25 | $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); |
| 26 | |
| 27 | $this->assertEquals('bar', element('foo', $this->my_array)); |
| 28 | } |
| 29 | |
| 30 | // ------------------------------------------------------------------------ |
| 31 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 32 | public function test_random_element() |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 33 | { |
| 34 | // Send a string, not an array to random_element |
| 35 | $this->assertEquals('my string', random_element('my string')); |
| 36 | |
| 37 | // Test sending an array |
| 38 | $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); |
| 39 | } |
| 40 | |
| 41 | // ------------------------------------------------------------------------ |
| 42 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 43 | public function test_elements() |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 44 | { |
| 45 | $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); |
| 46 | $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); |
| 47 | } |
| 48 | |
| 49 | } |