8adb55fc140df52b7d68433b71f3b7489f8306d8
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / wfArrayFilterTest.php
1 <?php
2
3 /**
4 * @group GlobalFunctions
5 * @covers ::wfArrayFilter
6 * @covers ::wfArrayFilterByKey
7 */
8 class WfArrayFilterTest extends \PHPUnit_Framework_TestCase {
9 public function testWfArrayFilter() {
10 $arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
11 $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
12 return $key !== 'b';
13 } );
14 $this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
15
16 $arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
17 $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
18 return $val !== 2;
19 } );
20 $this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
21
22 $arr = [ 'a', 'b', 'c' ];
23 $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
24 return $key !== 0;
25 } );
26 $this->assertSame( [ 1 => 'b', 2 => 'c' ], $filtered );
27 }
28
29 public function testWfArrayFilterByKey() {
30 $arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
31 $filtered = wfArrayFilterByKey( $arr, function ( $key ) {
32 return $key !== 'b';
33 } );
34 $this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
35
36 $arr = [ 'a', 'b', 'c' ];
37 $filtered = wfArrayFilterByKey( $arr, function ( $key ) {
38 return $key !== 0;
39 } );
40 $this->assertSame( [ 1 => 'b', 2 => 'c' ], $filtered );
41 }
42 }