blob: b2409c3302f11632e9a686ecd81eeded18515468 [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
Andrey Andreev3ddd5642014-02-17 17:31:23 +02005 public $my_array = array(
6 'foo' => 'bar',
7 'sally' => 'jim',
8 'maggie' => 'bessie',
9 'herb' => 'cook'
10 );
11
Eric Barnes68286a42011-04-21 22:00:33 -040012 public function set_up()
Pascal Kriete69c97a72011-04-20 21:44:54 -040013 {
Taufan Adityae1dc9ea2012-03-28 16:49:49 +070014 $this->helper('array');
Pascal Kriete69c97a72011-04-20 21:44:54 -040015 }
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));
Pascal Kriete69c97a72011-04-20 21:44:54 -040022 $this->assertEquals('not set', element('testing', $this->my_array, 'not set'));
Pascal Kriete69c97a72011-04-20 21:44:54 -040023 $this->assertEquals('bar', element('foo', $this->my_array));
24 }
Andrey Andreev99b782d2012-06-09 22:24:46 +030025
26 // ------------------------------------------------------------------------
Pascal Kriete69c97a72011-04-20 21:44:54 -040027
Eric Barnes68286a42011-04-21 22:00:33 -040028 public function test_random_element()
Pascal Kriete69c97a72011-04-20 21:44:54 -040029 {
30 // Send a string, not an array to random_element
31 $this->assertEquals('my string', random_element('my string'));
Andrey Andreev99b782d2012-06-09 22:24:46 +030032
Pascal Kriete69c97a72011-04-20 21:44:54 -040033 // Test sending an array
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020034 $this->assertContains(random_element($this->my_array), $this->my_array);
Pascal Kriete69c97a72011-04-20 21:44:54 -040035 }
36
Andrey Andreev99b782d2012-06-09 22:24:46 +030037 // ------------------------------------------------------------------------
38
Eric Barnes68286a42011-04-21 22:00:33 -040039 public function test_elements()
Pascal Kriete69c97a72011-04-20 21:44:54 -040040 {
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020041 $this->assertInternalType('array', elements('test', $this->my_array));
42 $this->assertInternalType('array', elements('foo', $this->my_array));
Pascal Kriete69c97a72011-04-20 21:44:54 -040043 }
44
Andrey Andreev20d9b0a2017-12-20 19:57:39 +020045}