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