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, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) ); } + + 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('fruit1<br />', 'fruit4<br />', 'fruit5<br />') ); } + 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') + ); + } + } diff --git a/tests/phpunit/PhpTagsFunctions_Useful_Test.php b/tests/phpunit/PhpTagsFunctions_Useful_Test.php index 5c2fba3..3d690b6 100644 --- a/tests/phpunit/PhpTagsFunctions_Useful_Test.php +++ b/tests/phpunit/PhpTagsFunctions_Useful_Test.php @@ -17,4 +17,18 @@ ); } + public function testRun_uuid_mw_json_encode_1() { + $this->assertEquals( + Runtime::runSource('echo mw_json_encode( ["foo"=>"bar"] );'), + array('{"foo":"bar"}') + ); + } + + public function testRun_uuid_mw_json_decode_1() { + $this->assertEquals( + Runtime::runSource('echo ["foo"=>"bar"] == mw_json_decode( "{\"foo\":\"bar\"}" ) ? "true" : "false";'), + array('true') + ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/175962 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2e73a93ddb9d31a241dc3822bee571e4e59a8562 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PhpTagsFunctions Gerrit-Branch: master Gerrit-Owner: Pastakhov <pastak...@yandex.ru> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits