/**
  * @see ApiBase::execute
  */
 public function execute()
 {
     $params = $this->extractRequestParams();
     $applicationFactory = ApplicationFactory::getInstance();
     $propertyListByApiRequest = new PropertyListByApiRequest($applicationFactory->getStore(), $applicationFactory->getPropertySpecificationLookup());
     $propertyListByApiRequest->setLimit($params['limit']);
     $propertyListByApiRequest->setListOnly($params['listonly']);
     $propertyListByApiRequest->setLanguageCode($params['lang']);
     $propertyListByApiRequest->findPropertyListBy($params['property']);
     foreach ($propertyListByApiRequest->getNamespaces() as $ns) {
         $uri = NamespaceUriFinder::getUri($ns);
         if (!$uri) {
             continue;
         }
         $this->getResult()->addValue(null, 'xmlns:' . $ns, $uri);
     }
     $data = $propertyListByApiRequest->getPropertyList();
     // I'm without words for this utter nonsense introduced here
     // because property keys can have a underscore _MDAT or for that matter
     // any other data field can
     // https://www.mediawiki.org/wiki/API:JSON_version_2
     // " ... can indicate that a property beginning with an underscore is not metadata using"
     if (method_exists($this->getResult(), 'setPreserveKeysList')) {
         $this->getResult()->setPreserveKeysList($data, array_keys($data));
     }
     $this->getResult()->addValue(null, 'query', $data);
     $this->getResult()->addValue(null, 'version', 2);
     $this->getResult()->addValue(null, 'query-continue-offset', $propertyListByApiRequest->getContinueOffset());
     $this->getResult()->addValue(null, 'meta', $propertyListByApiRequest->getMeta());
 }
 public function testGetSerializedListForProperty()
 {
     $list[] = array(new DIProperty('Foo'), 42);
     $list[] = array(new DIProperty('Foaf:Foo'), 1001);
     $list[] = array(new \SMWDIError('error'), -1);
     $list[] = array();
     $isCached = true;
     $expectedSerializedPropertyList = array('Foo' => array('label' => 'Foo', 'isUserDefined' => true, 'usageCount' => 42), 'Foaf:Foo' => array('label' => 'Foaf:Foo', 'isUserDefined' => true, 'usageCount' => 1001));
     $expectedNamespaces = array('Foaf');
     $expectedMeta = array('limit' => 3, 'count' => 2, 'isCached' => $isCached);
     $cachedListLookup = $this->getMockBuilder('\\SMW\\SQLStore\\Lookup\\CachedListLookup')->disableOriginalConstructor()->getMock();
     $cachedListLookup->expects($this->once())->method('fetchList')->will($this->returnValue($list));
     $cachedListLookup->expects($this->once())->method('isCached')->will($this->returnValue($isCached));
     $this->store->expects($this->once())->method('getPropertiesSpecial')->will($this->returnValue($cachedListLookup));
     $instance = new PropertyListByApiRequest($this->store);
     $instance->setLimit(3);
     $this->assertTrue($instance->findPropertyListFor('Foo'));
     $this->assertEquals($expectedSerializedPropertyList, $instance->getPropertyList());
     $this->assertEquals($expectedNamespaces, $instance->getNamespaces());
     $this->assertEquals($expectedMeta, $instance->getMeta());
     $this->assertEquals(3, $instance->getContinueOffset());
 }