Pascal Kriete | 69c97a7 | 2011-04-20 21:44:54 -0400 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | // OLD TEST FORMAT: DO NOT COPY |
| 4 | |
| 5 | require_once(BASEPATH.'helpers/array_helper.php'); |
| 6 | |
| 7 | class Array_helper_test extends PHPUnit_Framework_TestCase |
| 8 | { |
| 9 | public function setUp() |
| 10 | { |
| 11 | $this->my_array = array( |
| 12 | 'foo' => 'bar', |
| 13 | 'sally' => 'jim', |
| 14 | 'maggie' => 'bessie', |
| 15 | 'herb' => 'cook' |
| 16 | ); |
| 17 | } |
| 18 | |
| 19 | // ------------------------------------------------------------------------ |
| 20 | |
| 21 | public function testElementWithExistingItem() |
| 22 | { |
| 23 | $this->assertEquals(FALSE, element('testing', $this->my_array)); |
| 24 | |
| 25 | $this->assertEquals('not set', element('testing', $this->my_array, 'not set')); |
| 26 | |
| 27 | $this->assertEquals('bar', element('foo', $this->my_array)); |
| 28 | } |
| 29 | |
| 30 | // ------------------------------------------------------------------------ |
| 31 | |
| 32 | public function testRandomElement() |
| 33 | { |
| 34 | // Send a string, not an array to random_element |
| 35 | $this->assertEquals('my string', random_element('my string')); |
| 36 | |
| 37 | // Test sending an array |
| 38 | $this->assertEquals(TRUE, in_array(random_element($this->my_array), $this->my_array)); |
| 39 | } |
| 40 | |
| 41 | // ------------------------------------------------------------------------ |
| 42 | |
| 43 | public function testElements() |
| 44 | { |
| 45 | $this->assertEquals(TRUE, is_array(elements('test', $this->my_array))); |
| 46 | $this->assertEquals(TRUE, is_array(elements('foo', $this->my_array))); |
| 47 | } |
| 48 | |
| 49 | } |