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 { |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 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 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 16 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 17 | // ------------------------------------------------------------------------ |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 18 | |
Eric Barnes | 68286a4 | 2011-04-21 22:00:33 -0400 | [diff] [blame] | 19 | public function test_element_with_existing_item() |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 20 | { |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 21 | $this->assertEquals(FALSE, element('testing', $this->my_array)); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 22 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 23 | $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 24 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 25 | $this->assertEquals('bar', element('foo', $this->my_array)); |
| 26 | } |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 27 | |
| 28 | // ------------------------------------------------------------------------ |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 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')); |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 34 | |
Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 35 | // Test sending an array |
| 36 | $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); |
| 37 | } |
| 38 | |
Andrey Andreev | 99b782d | 2012-06-09 22:24:46 +0300 | [diff] [blame] | 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 | } |