[MediaWiki-commits] [Gerrit] add mw_json_encode and mw_json_decode functions (v 3.3.3) - change (mediawiki...PhpTagsFunctions)
Pastakhov has uploaded a new change for review. https://gerrit.wikimedia.org/r/175962 Change subject: add mw_json_encode and mw_json_decode functions (v 3.3.3) .. add mw_json_encode and mw_json_decode functions (v 3.3.3) Change-Id: I2e73a93ddb9d31a241dc3822bee571e4e59a8562 --- M PhpTagsFunctions.init.php M PhpTagsFunctions.php M includes/PhpTagsFuncUseful.php M tests/phpunit/PhpTagsFunctions_Array_Test.php M tests/phpunit/PhpTagsFunctions_Useful_Test.php 5 files changed, 71 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PhpTagsFunctions refs/changes/62/175962/1 diff --git a/PhpTagsFunctions.init.php b/PhpTagsFunctions.init.php index 6630c49..2eb1ed0 100644 --- a/PhpTagsFunctions.init.php +++ b/PhpTagsFunctions.init.php @@ -604,6 +604,8 @@ private static function getFuncUseful() { return array( 'uuid_create', + 'mw_json_decode', + 'mw_json_encode', ); } diff --git a/PhpTagsFunctions.php b/PhpTagsFunctions.php index b87d823..6946137 100644 --- a/PhpTagsFunctions.php +++ b/PhpTagsFunctions.php @@ -33,7 +33,7 @@ ); } -const PHPTAGS_FUNCTIONS_VERSION = '3.3.2'; +const PHPTAGS_FUNCTIONS_VERSION = '3.3.3'; // Register this extension on Special:Version $wgExtensionCredits['phptags'][] = array( diff --git a/includes/PhpTagsFuncUseful.php b/includes/PhpTagsFuncUseful.php index 02e30e3..a12135d 100644 --- a/includes/PhpTagsFuncUseful.php +++ b/includes/PhpTagsFuncUseful.php @@ -32,4 +32,12 @@ mt_rand( 0, 0x ), mt_rand( 0, 0x ), mt_rand( 0, 0x ) ); } + + public static function f_mw_json_decode( $value ) { + return \FormatJson::decode( $value, true ); + } + + public static function f_mw_json_encode( $value ) { + return \FormatJson::encode( $value, false, \FormatJson::UTF8_OK ); + } } diff --git a/tests/phpunit/PhpTagsFunctions_Array_Test.php b/tests/phpunit/PhpTagsFunctions_Array_Test.php index 62867e6..529a963 100644 --- a/tests/phpunit/PhpTagsFunctions_Array_Test.php +++ b/tests/phpunit/PhpTagsFunctions_Array_Test.php @@ -717,6 +717,15 @@ array('fruit1br /', 'fruit4br /', 'fruit5br /') ); } + public function testRun_echo_while_function_1() { + $this-assertEquals( + Runtime::runSource(' +$foo = [1,2]; +while ( count($foo) 4 ) array_push($foo, 8); +echo $foo == [1,2,8,8] ? true : false;'), + array('true') + ); + } public function testRun_in_array_1() { $this-assertEquals( @@ -838,4 +847,41 @@ ); } + public function testRun_echo_if_else_simple_function_1() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( true ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2] ? true : false;'), + array('true') + ); + } + public function testRun_echo_if_else_simple_function__2() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( false ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2,3,4] ? true : false;'), + array('true') + ); + } + public function testRun_echo_if_else_simple_function__3() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( true ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2] ? true : false; echo always!;'), + array('true', ' always!') + ); + } + public function testRun_echo_if_else_simple_function__4() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( false ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2,3,4] ? true : false; echo always!;'), + array('true', ' always!') + ); + } + public function testRun_echo_if_else_simple_variable_1() { + $this-assertEquals( + Runtime::runSource('if ( true ) $foo=true; else $foo=false; echo $foo;'), + array('true') + ); + } + public function testRun_echo_if_else_simple_variable_2() { + $this-assertEquals( + Runtime::runSource('if ( false ) $foo=true; else $foo=false; echo $foo;'), +
[MediaWiki-commits] [Gerrit] add mw_json_encode and mw_json_decode functions (v 3.3.3) - change (mediawiki...PhpTagsFunctions)
jenkins-bot has submitted this change and it was merged. Change subject: add mw_json_encode and mw_json_decode functions (v 3.3.3) .. add mw_json_encode and mw_json_decode functions (v 3.3.3) Change-Id: I2e73a93ddb9d31a241dc3822bee571e4e59a8562 --- M PhpTagsFunctions.init.php M PhpTagsFunctions.php M includes/PhpTagsFuncUseful.php M tests/phpunit/PhpTagsFunctions_Array_Test.php M tests/phpunit/PhpTagsFunctions_Useful_Test.php 5 files changed, 71 insertions(+), 1 deletion(-) Approvals: Pastakhov: Looks good to me, approved jenkins-bot: Verified diff --git a/PhpTagsFunctions.init.php b/PhpTagsFunctions.init.php index 6630c49..2eb1ed0 100644 --- a/PhpTagsFunctions.init.php +++ b/PhpTagsFunctions.init.php @@ -604,6 +604,8 @@ private static function getFuncUseful() { return array( 'uuid_create', + 'mw_json_decode', + 'mw_json_encode', ); } diff --git a/PhpTagsFunctions.php b/PhpTagsFunctions.php index b87d823..6946137 100644 --- a/PhpTagsFunctions.php +++ b/PhpTagsFunctions.php @@ -33,7 +33,7 @@ ); } -const PHPTAGS_FUNCTIONS_VERSION = '3.3.2'; +const PHPTAGS_FUNCTIONS_VERSION = '3.3.3'; // Register this extension on Special:Version $wgExtensionCredits['phptags'][] = array( diff --git a/includes/PhpTagsFuncUseful.php b/includes/PhpTagsFuncUseful.php index 02e30e3..a12135d 100644 --- a/includes/PhpTagsFuncUseful.php +++ b/includes/PhpTagsFuncUseful.php @@ -32,4 +32,12 @@ mt_rand( 0, 0x ), mt_rand( 0, 0x ), mt_rand( 0, 0x ) ); } + + public static function f_mw_json_decode( $value ) { + return \FormatJson::decode( $value, true ); + } + + public static function f_mw_json_encode( $value ) { + return \FormatJson::encode( $value, false, \FormatJson::UTF8_OK ); + } } diff --git a/tests/phpunit/PhpTagsFunctions_Array_Test.php b/tests/phpunit/PhpTagsFunctions_Array_Test.php index 62867e6..529a963 100644 --- a/tests/phpunit/PhpTagsFunctions_Array_Test.php +++ b/tests/phpunit/PhpTagsFunctions_Array_Test.php @@ -717,6 +717,15 @@ array('fruit1br /', 'fruit4br /', 'fruit5br /') ); } + public function testRun_echo_while_function_1() { + $this-assertEquals( + Runtime::runSource(' +$foo = [1,2]; +while ( count($foo) 4 ) array_push($foo, 8); +echo $foo == [1,2,8,8] ? true : false;'), + array('true') + ); + } public function testRun_in_array_1() { $this-assertEquals( @@ -838,4 +847,41 @@ ); } + public function testRun_echo_if_else_simple_function_1() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( true ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2] ? true : false;'), + array('true') + ); + } + public function testRun_echo_if_else_simple_function__2() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( false ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2,3,4] ? true : false;'), + array('true') + ); + } + public function testRun_echo_if_else_simple_function__3() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( true ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2] ? true : false; echo always!;'), + array('true', ' always!') + ); + } + public function testRun_echo_if_else_simple_function__4() { + $this-assertEquals( + Runtime::runSource('$foo = [1,2,3]; if ( false ) array_pop($foo); else array_push($foo, 4); echo $foo == [1,2,3,4] ? true : false; echo always!;'), + array('true', ' always!') + ); + } + public function testRun_echo_if_else_simple_variable_1() { + $this-assertEquals( + Runtime::runSource('if ( true ) $foo=true; else $foo=false; echo $foo;'), + array('true') + ); + } + public function testRun_echo_if_else_simple_variable_2() { + $this-assertEquals( + Runtime::runSource('if ( false ) $foo=true; else $foo=false; echo $foo;'), + array('false') + ); +