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