XOMW: Finish XomwHooks [#632]

staging
gnosygnu 4 years ago
parent 3d74406a3e
commit d1345bf724

@ -15,7 +15,9 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.mediawiki.includes;
import gplx.Gfo_log_;
import gplx.xowa.mediawiki.XomwEnv;
import gplx.xowa.mediawiki.XophpString_;
// MW.SRC:1.33.1
// XO.NOTE:MW lists functions individually; XO aggregates under XomwGlobalFunctions class
@ -1052,23 +1054,27 @@ public class XomwGlobalFunctions {
// $logger = LoggerFactory::getInstance('wfLogDBError');
// $logger.error(trim($text), $context);
// }
//
// /**
// * Throws a warning that $function is deprecated
// *
// * @param string $function Function that is deprecated.
// * @param string|bool $version Version of MediaWiki that the function
// * was deprecated in (Added in 1.19).
// * @param string|bool $component Component to which the function belongs.
// * If false, it is assumed the function is in MediaWiki core (Added in 1.19).
// * @param int $callerOffset How far up the call stack is the original
// * caller. 2 = function that called the function that called
// * wfDeprecated (Added in 1.20).
// */
// function wfDeprecated($function, $version = false, $component = false, $callerOffset = 2) {
// MWDebug::deprecated($function, $version, $component, $callerOffset + 1);
// }
//
/**
* Throws a warning that $function is deprecated
*
* @param string $function Function that is deprecated.
* @param string|bool $version Version of MediaWiki that the function
* was deprecated in (Added in 1.19).
* @param string|bool $component Component to which the function belongs.
* If false, it is assumed the function is in MediaWiki core (Added in 1.19).
* @param int $callerOffset How far up the call stack is the original
* caller. 2 = function that called the function that called
* wfDeprecated (Added in 1.20).
*/
public static void wfDeprecated(String function) {wfDeprecated(function, XophpString_.False, XophpString_.False, 2);}
public static void wfDeprecated(String function, String version) {wfDeprecated(function, version, XophpString_.False, 2);}
public static void wfDeprecated(String function, String version, String component, int callerOffset) {
// MWDebug::deprecated($function, $version, $component, $callerOffset + 1);
String deprecatedIn = version == null ? "" : " deprecated in " + version;
Gfo_log_.Instance.Warn(function + deprecatedIn);
}
// /**
// * Send a warning either to the debug log or in a PHP error depending on
// * $wgDevelopmentWarnings. To log warnings in production, use wfLogWarning() instead.

@ -0,0 +1,81 @@
package gplx.xowa.mediawiki.includes;
import gplx.core.tests.Gftest;
import gplx.xowa.mediawiki.XophpArray;
import gplx.xowa.mediawiki.XophpArray__tst;
import gplx.xowa.mediawiki.XophpCallback;
import gplx.xowa.mediawiki.XophpCallbackOwner;
import org.junit.Before;
import org.junit.Test;
public class XomwHooksTest {
private XomwHooksTestCallbackOwner callbackOwner;
@Before
public void setUp() throws Exception {
callbackOwner = new XomwHooksTestCallbackOwner();
XomwHooks.clearAll();
}
@Test
public void isRegistered() {
Gftest.Eq__bool_n(XomwHooks.isRegistered("test1"));
}
@Test
public void register() {
Gftest.Eq__bool_n(XomwHooks.isRegistered("test1"));
XomwHooks.register("test1", callbackOwner.NewCallback("test1"));
Gftest.Eq__bool_y(XomwHooks.isRegistered("test1"));
}
@Test
public void clear() {
Gftest.Eq__bool_n(XomwHooks.isRegistered("test1"));
XomwHooks.register("test1", callbackOwner.NewCallback("test1"));
Gftest.Eq__bool_y(XomwHooks.isRegistered("test1"));
XomwHooks.clear("test1");
Gftest.Eq__bool_y(XomwHooks.isRegistered("test1"));
}
@Test
public void getHandlers() {
XomwHooks.register("test1", callbackOwner.NewCallback("test1a"));
XomwHooks.register("test1", callbackOwner.NewCallback("test1b"));
XomwHooks.register("test2", callbackOwner.NewCallback("test2"));
XophpArray handlers = XomwHooks.getHandlers("test1");
Gftest.Eq__ary
( new String[] {"test1a", "test1b"}
, extractKeysFromCallbackAry(handlers)
);
}
@Test
public void run() {
XomwHooks.register("test1", callbackOwner.NewCallback("test1a"));
XomwHooks.register("test1", callbackOwner.NewCallback("test1b"));
XomwHooks.register("test2", callbackOwner.NewCallback("test2"));
Gftest.Eq__bool_y(XomwHooks.run("test1", XophpArray.New(1, 2, 3)));
Gftest.Eq__str("test1a:3;test1b:3", callbackOwner.Result());
}
private static String[] extractKeysFromCallbackAry(XophpArray callbacks) {
int len = callbacks.Len();
String[] rv = new String[len];
for (int i = 0; i < len; i++) {
XophpCallback callback = (XophpCallback)callbacks.Get_at(i);
rv[i] = callback.MethodName();
}
return rv;
}
}
class XomwHooksTestCallbackOwner implements XophpCallbackOwner {
public String Result() {return result;} private String result = "";
@Override
public Object Call(String method, Object... args) {
result += method + ":" + (args == null ? -1 : ((XophpArray)args[0]).count()) + ";";
return null; // NOTE: XomwHooks throws error if non-null
}
}
Loading…
Cancel
Save