blob: 9cd15960f159da26fd71c0a609c76a5affb43133 [file] [log] [blame]
Pascal Kriete69c97a72011-04-20 21:44:54 -04001<?php
2
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07003class Array_helper_test extends CI_TestCase {
4
Eric Barnes68286a42011-04-21 22:00:33 -04005 public function set_up()
Pascal Kriete69c97a72011-04-20 21:44:54 -04006 {
Taufan Adityae1dc9ea2012-03-28 16:49:49 +07007 $this->helper('array');
8
Pascal Kriete69c97a72011-04-20 21:44:54 -04009 $this->my_array = array(
10 'foo' => 'bar',
11 'sally' => 'jim',
12 'maggie' => 'bessie',
13 'herb' => 'cook'
14 );
15 }
16
17 // ------------------------------------------------------------------------
18
Eric Barnes68286a42011-04-21 22:00:33 -040019 public function test_element_with_existing_item()
Pascal Kriete69c97a72011-04-20 21:44:54 -040020 {
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 Barnes68286a42011-04-21 22:00:33 -040030 public function test_random_element()
Pascal Kriete69c97a72011-04-20 21:44:54 -040031 {
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 Barnes68286a42011-04-21 22:00:33 -040041 public function test_elements()
Pascal Kriete69c97a72011-04-20 21:44:54 -040042 {
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}