public function testCanConstruct()
 {
     $parser = $this->getMockBuilder('\\Parser')->disableOriginalConstructor()->getMock();
     $this->assertInstanceOf('\\SMW\\ParserFunctionFactory', new ParserFunctionFactory($parser));
     $this->assertInstanceOf('\\SMW\\ParserFunctionFactory', ParserFunctionFactory::newFromParser($parser));
 }
 /**
  * Based on Semantic Internal Objects'
  * SIOSubobjectHandler::doSetInternal().
  */
 public static function callSubobject($parser, $params)
 {
     // This is a hack, since SMW's SMWSubobject::render() call is
     // not meant to be called outside of SMW. However, this seemed
     // like the better solution than copying over all of that
     // method's code. Ideally, a true public function can be
     // added to SMW, that handles a subobject creation, that this
     // code can then call.
     $subobjectArgs = array(&$parser);
     // Blank first argument, so that subobject ID will be
     // an automatically-generated random number.
     $subobjectArgs[1] = '';
     // "main" property, pointing back to the page.
     $mainPageName = $parser->getTitle()->getText();
     $mainPageNamespace = $parser->getTitle()->getNsText();
     if ($mainPageNamespace != '') {
         $mainPageName = $mainPageNamespace . ':' . $mainPageName;
     }
     $subobjectArgs[2] = $params[0] . '=' . $mainPageName;
     foreach ($params as $i => $value) {
         if ($i == 0) {
             continue;
         }
         $subobjectArgs[] = $value;
     }
     if (class_exists('SMW\\SubobjectParserFunction')) {
         // SMW 1.9+
         $instance = \SMW\ParserFunctionFactory::newFromParser($parser)->getSubobjectParser();
         return $instance->parse(new SMW\ParserParameterFormatter($subobjectArgs));
     } elseif (class_exists('SMW\\SubobjectHandler')) {
         // Old version of SMW 1.9 - can be removed at some point
         call_user_func_array(array('SMW\\SubobjectHandler', 'render'), $subobjectArgs);
     } elseif (class_exists('SMW\\SubobjectParser')) {
         // Old version of SMW 1.9 - can be removed at some point
         call_user_func_array(array('SMW\\SubobjectParser', 'render'), $subobjectArgs);
     } elseif (class_exists('SMW\\Subobject')) {
         // Old version of SMW 1.9 - can be removed at some point
         call_user_func_array(array('SMW\\Subobject', 'render'), $subobjectArgs);
     } else {
         // SMW 1.8
         call_user_func_array(array('SMWSubobject', 'render'), $subobjectArgs);
     }
     return;
 }