summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/FallbackTest.php
blob: c60170f3e5d566dabdf54bd7d9dabf28cdf1f90c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php

/**
 * @covers Fallback
 */
class FallbackTest extends MediaWikiTestCase {
	public function testFallbackMbstringFunctions() {
		if ( !extension_loaded( 'mbstring' ) ) {
			$this->markTestSkipped(
				"The mb_string functions must be installed to test the fallback functions"
			);
		}

		$sampleUTF = "Östergötland_coat_of_arms.png";

		//mb_substr
		$substr_params = array(
			array( 0, 0 ),
			array( 5, -4 ),
			array( 33 ),
			array( 100, -5 ),
			array( -8, 10 ),
			array( 1, 1 ),
			array( 2, -1 )
		);

		foreach ( $substr_params as $param_set ) {
			$old_param_set = $param_set;
			array_unshift( $param_set, $sampleUTF );

			$this->assertEquals(
				call_user_func_array( 'mb_substr', $param_set ),
				call_user_func_array( 'Fallback::mb_substr', $param_set ),
				'Fallback mb_substr with params ' . implode( ', ', $old_param_set )
			);
		}

		//mb_strlen
		$this->assertEquals(
			mb_strlen( $sampleUTF ),
			Fallback::mb_strlen( $sampleUTF ),
			'Fallback mb_strlen'
		);

		//mb_str(r?)pos
		$strpos_params = array(
			//array( 'ter' ),
			//array( 'Ö' ),
			//array( 'Ö', 3 ),
			//array( 'oat_', 100 ),
			//array( 'c', -10 ),
			//Broken for now
		);

		foreach ( $strpos_params as $param_set ) {
			$old_param_set = $param_set;
			array_unshift( $param_set, $sampleUTF );

			$this->assertEquals(
				call_user_func_array( 'mb_strpos', $param_set ),
				call_user_func_array( 'Fallback::mb_strpos', $param_set ),
				'Fallback mb_strpos with params ' . implode( ', ', $old_param_set )
			);

			$this->assertEquals(
				call_user_func_array( 'mb_strrpos', $param_set ),
				call_user_func_array( 'Fallback::mb_strrpos', $param_set ),
				'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set )
			);
		}
	}
}