blob: ba46e86f92ee95eadd68a385082057f9a55d5822 [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 {
Andrey Andreev99b782d2012-06-09 22:24:46 +03004
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 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030016
Pascal Kriete69c97a72011-04-20 21:44:54 -040017 // ------------------------------------------------------------------------
Andrey Andreev99b782d2012-06-09 22:24:46 +030018
Eric Barnes68286a42011-04-21 22:00:33 -040019 public function test_element_with_existing_item()
Andrey Andreev99b782d2012-06-09 22:24:46 +030020 {
Pascal Kriete69c97a72011-04-20 21:44:54 -040021 $this->assertEquals(FALSE, element('testing', $this->my_array));
Andrey Andreev99b782d2012-06-09 22:24:46 +030022
Pascal Kriete69c97a72011-04-20 21:44:54 -040023 $this->assertEquals('not set', element('testing', $this->my_array, 'not set'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030024
Pascal Kriete69c97a72011-04-20 21:44:54 -040025 $this->assertEquals('bar', element('foo', $this->my_array));
26 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030027
28 // ------------------------------------------------------------------------
Pascal Kriete69c97a72011-04-20 21:44:54 -040029
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'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030034
Pascal Kriete69c97a72011-04-20 21:44:54 -040035 // Test sending an array
36 $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array));
37 }
38
Andrey Andreev99b782d2012-06-09 22:24:46 +030039 // ------------------------------------------------------------------------
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}