Пример #1
0
 /**
  * Tests service links for content fields
  * @group restContentServices
  * @dataProvider requestObjectProvider
  * @param ezpRestRequest $request
  * @param int $nodeId
  */
 public function testFieldsLinksByContent(ezpRestRequest $request, $nodeId)
 {
     $mvcConfig = new ezpMvcConfiguration();
     $mvcConfig->runPreRoutingFilters($request);
     $baseUri = $request->getBaseURI();
     $contentQueryString = $request->getContentQueryString(true);
     $content = ezpContent::fromNodeId($nodeId);
     $links = ezpRestContentModel::getFieldsLinksByContent($content, $request);
     self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $links);
     self::assertArrayHasKey('*', $links, 'Links for fields services must contain a wildcard (*) pointing to a service listing all fields content');
     // * stands for all fields
     self::assertEquals($baseUri . '/fields' . $contentQueryString, $links['*']);
     // We must have one entry per field
     foreach ($content->fields as $fieldName => $field) {
         self::assertArrayHasKey($fieldName, $links, "Service link missing for {$fieldName}");
         self::assertEquals($baseUri . '/field/' . $fieldName . $contentQueryString, $links[$fieldName], "Wrong service link for {$fieldName}");
     }
 }
Пример #2
0
 /**
  * Counts children of a given node
  * Request :
  *   - GET /api/ezp/content/node/childrenCount
  */
 public function doCountChildren()
 {
     $this->setDefaultResponseGroups(array(self::VIEWLIST_RESPONSEGROUP_METADATA));
     $result = new ezpRestMvcResult();
     if ($this->hasResponseGroup(self::VIEWLIST_RESPONSEGROUP_METADATA)) {
         $crit = new ezpContentCriteria();
         $crit->accept[] = ezpContentCriteria::location()->subtree(ezpContentLocation::fetchByNodeId($this->nodeId));
         $crit->accept[] = ezpContentCriteria::depth(1);
         // Fetch children only
         $childrenCount = ezpRestContentModel::getChildrenCount($crit);
         $result->variables['metadata'] = array('childrenCount' => $childrenCount, 'parentNodeId' => $this->nodeId);
     }
     return $result;
 }